Home | History | Annotate | Download | only in releasetools
      1 #!/usr/bin/env python
      2 #
      3 # Copyright (C) 2014 The Android Open Source Project
      4 #
      5 # Licensed under the Apache License, Version 2.0 (the "License");
      6 # you may not use this file except in compliance with the License.
      7 # You may obtain a copy of the License at
      8 #
      9 #      http://www.apache.org/licenses/LICENSE-2.0
     10 #
     11 # Unless required by applicable law or agreed to in writing, software
     12 # distributed under the License is distributed on an "AS IS" BASIS,
     13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14 # See the License for the specific language governing permissions and
     15 # limitations under the License.
     16 
     17 from __future__ import print_function
     18 
     19 import sys
     20 
     21 if sys.hexversion < 0x02070000:
     22   print("Python 2.7 or newer is required.", file=sys.stderr)
     23   sys.exit(1)
     24 
     25 import os
     26 import common
     27 
     28 OPTIONS = common.OPTIONS
     29 
     30 def main(argv):
     31   # def option_handler(o, a):
     32   #   return False
     33 
     34   args = common.ParseOptions(argv, __doc__)
     35   input_dir, output_dir = args
     36 
     37   OPTIONS.info_dict = common.LoadInfoDict(input_dir)
     38 
     39   recovery_img = common.GetBootableImage("recovery.img", "recovery.img",
     40                                          input_dir, "RECOVERY")
     41   boot_img = common.GetBootableImage("boot.img", "boot.img",
     42                                      input_dir, "BOOT")
     43 
     44   if not recovery_img or not boot_img:
     45     sys.exit(0)
     46 
     47   def output_sink(fn, data):
     48     with open(os.path.join(output_dir, "SYSTEM", *fn.split("/")), "wb") as f:
     49       f.write(data)
     50 
     51   common.MakeRecoveryPatch(input_dir, output_sink, recovery_img, boot_img)
     52 
     53 
     54 if __name__ == '__main__':
     55   main(sys.argv[1:])
     56