Home | History | Annotate | Download | only in tools
      1 #!/usr/bin/env python
      2 #
      3 # Copyright (C) 2009 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 import sys
     18 
     19 # Put the modifications that you need to make into the /system/build.prop into this
     20 # function. The prop object has get(name) and put(name,value) methods.
     21 def mangle_build_prop(prop):
     22   pass
     23 
     24 
     25 # Put the modifications that you need to make into the /system/build.prop into this
     26 # function. The prop object has get(name) and put(name,value) methods.
     27 def mangle_default_prop(prop):
     28   # If ro.debuggable is 1, then enable adb on USB by default
     29   # (this is for userdebug builds)
     30   if prop.get("ro.debuggable") == "1":
     31     val = prop.get("persist.sys.usb.config")
     32     if val == "":
     33       val = "adb"
     34     else:
     35       val = val + ",adb"
     36     prop.put("persist.sys.usb.config", val)
     37 
     38 
     39 class PropFile:
     40   def __init__(self, lines):
     41     self.lines = [s[:-1] for s in lines]
     42 
     43   def get(self, name):
     44     key = name + "="
     45     for line in self.lines:
     46       if line.startswith(key):
     47         return line[len(key):]
     48     return ""
     49 
     50   def put(self, name, value):
     51     key = name + "="
     52     for i in range(0,len(self.lines)):
     53       if self.lines[i].startswith(key):
     54         self.lines[i] = key + value
     55         return
     56     self.lines.append(key + value)
     57 
     58   def write(self, f):
     59     f.write("\n".join(self.lines))
     60     f.write("\n")
     61 
     62 def main(argv):
     63   filename = argv[1]
     64   f = open(filename)
     65   lines = f.readlines()
     66   f.close()
     67 
     68   properties = PropFile(lines)
     69   if filename.endswith("/build.prop"):
     70     mangle_build_prop(properties)
     71   elif filename.endswith("/default.prop"):
     72     mangle_default_prop(properties)
     73   else:
     74     sys.stderr.write("bad command line: " + str(argv) + "\n")
     75     sys.exit(1)
     76 
     77   f = open(filename, 'w+')
     78   properties.write(f)
     79   f.close()
     80 
     81 if __name__ == "__main__":
     82   main(sys.argv)
     83