Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 | |
|
abarth-chromium
2015/06/10 23:10:56
Copyright block?
| |
| 2 import yaml | |
| 3 import xml.etree.ElementTree as ET | |
| 4 | |
| 5 | |
| 6 PUBSPECS = [ | |
| 7 'sky/sdk/pubspec.yaml', | |
| 8 'mojo/public/dart/pubspec.yaml', | |
| 9 'mojo/dart/mojo_services/pubspec.yaml', | |
| 10 'mojo/dart/mojom/pubspec.yaml', | |
| 11 ] | |
| 12 | |
| 13 | |
| 14 MANIFESTS = [ | |
| 15 'sky/apk/demo/AndroidManifest.xml', | |
| 16 ] | |
| 17 | |
| 18 MANIFEST_PREFACE = '''<?xml version="1.0" encoding="utf-8"?> | |
| 19 <!-- Copyright 2015 The Chromium Authors. All rights reserved. | |
| 20 Use of this source code is governed by a BSD-style license that can be | |
| 21 found in the LICENSE file. | |
| 22 --> | |
| 23 ''' | |
| 24 | |
| 25 def increment_version(version): | |
| 26 pieces = version.split('.') | |
| 27 pieces[-1] = str(int(pieces[-1]) + 1) | |
| 28 return '.'.join(pieces) | |
| 29 | |
| 30 def sort_dict(unsorted): | |
| 31 sorted_dict = collections.OrderedDict() | |
| 32 for key in sorted(unsorted.keys()): | |
| 33 sorted_dict[key] = unsorted[key] | |
| 34 return sorted_dict | |
| 35 | |
| 36 def update_pubspec(pubspec): | |
| 37 # TODO(eseidel): This does not prserve any manual sort-order of the yaml. | |
| 38 with open(pubspec, 'r') as stream: | |
| 39 spec = yaml.load(stream) | |
| 40 old_version = spec['version'] | |
| 41 spec['version'] = increment_version(old_version) | |
| 42 print "%20s %6s => %6s" % (spec['name'], old_version, spec['version']) | |
| 43 | |
| 44 with open(pubspec, 'w') as stream: | |
| 45 yaml.dump(spec, stream=stream, default_flow_style=False) | |
| 46 | |
| 47 | |
| 48 def prepend_to_file(to_prepend, filepath): | |
| 49 with open(filepath, 'r+') as f: | |
| 50 content = f.read() | |
| 51 f.seek(0, 0) | |
| 52 f.write(to_prepend + content) | |
| 53 | |
| 54 | |
| 55 def update_manifest(manifest): | |
| 56 VERSION_CODE = '{http://schemas.android.com/apk/res/android}versionCode' | |
| 57 VERSION_NAME = '{http://schemas.android.com/apk/res/android}versionName' | |
| 58 tree = ET.parse(manifest) | |
| 59 root = tree.getroot() | |
| 60 package_name = root.get('package') | |
| 61 old_code = root.get(VERSION_CODE) | |
| 62 old_name = root.get(VERSION_NAME) | |
| 63 root.set(VERSION_CODE, increment_version(old_code)) | |
| 64 root.set(VERSION_NAME, increment_version(old_name)) | |
| 65 print "%20s %6s (%s) => %6s (%s)" % (package_name, old_name, old_code, | |
| 66 root.get(VERSION_NAME), root.get(VERSION_CODE)) | |
| 67 # TODO(eseidel): This isn't smart enough to wrap/intent multi-attribute | |
| 68 # elements like <manifest> as is the typical AndroidManifiest.xml style | |
| 69 # we could write our own custom prettyprinter to do that? | |
| 70 tree.write(manifest) | |
| 71 prepend_to_file(MANIFEST_PREFACE, manifest) | |
| 72 | |
| 73 | |
| 74 def main(): | |
| 75 print 'Pub packages:' | |
| 76 for pubspec in PUBSPECS: | |
| 77 update_pubspec(pubspec) | |
| 78 | |
| 79 # TODO(eseidel): Without this ET uses 'ns0' for 'android' which is wrong. | |
| 80 ET.register_namespace('android', 'http://schemas.android.com/apk/res/android ') | |
| 81 | |
| 82 print 'APKs:' | |
| 83 for manifest in MANIFESTS: | |
| 84 update_manifest(manifest) | |
| 85 | |
| 86 | |
| 87 if __name__ == '__main__': | |
| 88 main() | |
| OLD | NEW |