Anthony King | 2890d6b | 2014-11-07 21:26:48 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # |
| 3 | # Copyright (C) 2009 The Android Open Source Project |
| 4 | # Copyright (C) 2014 SlimRoms Project |
| 5 | # |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | # you may not use this file except in compliance with the License. |
| 8 | # You may obtain a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | # See the License for the specific language governing permissions and |
| 16 | # limitations under the License. |
| 17 | |
| 18 | import os |
| 19 | import sys |
| 20 | |
| 21 | # give us access to import the original post_process_props |
| 22 | sys.path.append(os.path.join(os.getenv('ANDROID_BUILD_TOP'), 'build/tools')) |
| 23 | from post_process_props import PropFile, validate |
| 24 | |
| 25 | |
| 26 | lcd_changer = {"213": "182", "240": "182", |
| 27 | "320": "245", "480": "370"} |
| 28 | |
| 29 | |
| 30 | def mangle_build_prop(prop): |
| 31 | lcd = prop.get('ro.sf.lcd_density') |
| 32 | new_lcd = lcd_changer.get(lcd, lcd) |
| 33 | prop.put('ro.sf.lcd_density', new_lcd) |
| 34 | |
| 35 | |
| 36 | def mangle_default_prop(prop): |
| 37 | pass |
| 38 | |
| 39 | |
| 40 | def main(argv): |
| 41 | fn = argv[1] |
| 42 | with open(fn) as f: |
| 43 | lines = f.readlines() |
| 44 | properties = PropFile(lines) |
| 45 | |
| 46 | if fn.endswith('/build.prop'): |
| 47 | mangle_build_prop(properties) |
| 48 | elif fn.endswith('/default.prop'): |
| 49 | mangle_default_prop(properties) |
| 50 | else: |
| 51 | sys.stderr.write("%s: Unsupported file: %s\n" % (os.path.realpath(__file__), fn)) |
| 52 | sys.exit(1) |
| 53 | |
| 54 | if not validate(properties): |
| 55 | # the validate routine prints on error |
| 56 | sys.exit(1) |
| 57 | |
| 58 | with open(fn, 'w+') as f: |
| 59 | properties.write(f) |
| 60 | |
| 61 | if __name__ == '__main__': |
| 62 | main(sys.argv) |