blob: 01f9128af49d277ed03730861001be5a9e499068 [file] [log] [blame]
Joe Onorato9197a482011-06-08 16:04:14 -07001#!/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
17import 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.
21def 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.
27def 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
39class 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
62def 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
Mike Lockwood5b65ee42011-06-08 19:06:43 -070077 f = open(filename, 'w+')
78 properties.write(f)
Joe Onorato9197a482011-06-08 16:04:14 -070079 f.close()
80
81if __name__ == "__main__":
82 main(sys.argv)