Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(443)

Unified Diff: sky/tools/roll_versions.py

Issue 1179633003: Add a roll_versions.py script and roll versions once. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Include a version roll Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sky/sdk/pubspec.yaml ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/tools/roll_versions.py
diff --git a/sky/tools/roll_versions.py b/sky/tools/roll_versions.py
new file mode 100644
index 0000000000000000000000000000000000000000..1334cc7b003e317a9cdf068eae731170a7b06d2e
--- /dev/null
+++ b/sky/tools/roll_versions.py
@@ -0,0 +1,88 @@
+
abarth-chromium 2015/06/10 23:10:56 Copyright block?
+import yaml
+import xml.etree.ElementTree as ET
+
+
+PUBSPECS = [
+ 'sky/sdk/pubspec.yaml',
+ 'mojo/public/dart/pubspec.yaml',
+ 'mojo/dart/mojo_services/pubspec.yaml',
+ 'mojo/dart/mojom/pubspec.yaml',
+]
+
+
+MANIFESTS = [
+ 'sky/apk/demo/AndroidManifest.xml',
+]
+
+MANIFEST_PREFACE = '''<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright 2015 The Chromium Authors. All rights reserved.
+ Use of this source code is governed by a BSD-style license that can be
+ found in the LICENSE file.
+ -->
+'''
+
+def increment_version(version):
+ pieces = version.split('.')
+ pieces[-1] = str(int(pieces[-1]) + 1)
+ return '.'.join(pieces)
+
+def sort_dict(unsorted):
+ sorted_dict = collections.OrderedDict()
+ for key in sorted(unsorted.keys()):
+ sorted_dict[key] = unsorted[key]
+ return sorted_dict
+
+def update_pubspec(pubspec):
+ # TODO(eseidel): This does not prserve any manual sort-order of the yaml.
+ with open(pubspec, 'r') as stream:
+ spec = yaml.load(stream)
+ old_version = spec['version']
+ spec['version'] = increment_version(old_version)
+ print "%20s %6s => %6s" % (spec['name'], old_version, spec['version'])
+
+ with open(pubspec, 'w') as stream:
+ yaml.dump(spec, stream=stream, default_flow_style=False)
+
+
+def prepend_to_file(to_prepend, filepath):
+ with open(filepath, 'r+') as f:
+ content = f.read()
+ f.seek(0, 0)
+ f.write(to_prepend + content)
+
+
+def update_manifest(manifest):
+ VERSION_CODE = '{http://schemas.android.com/apk/res/android}versionCode'
+ VERSION_NAME = '{http://schemas.android.com/apk/res/android}versionName'
+ tree = ET.parse(manifest)
+ root = tree.getroot()
+ package_name = root.get('package')
+ old_code = root.get(VERSION_CODE)
+ old_name = root.get(VERSION_NAME)
+ root.set(VERSION_CODE, increment_version(old_code))
+ root.set(VERSION_NAME, increment_version(old_name))
+ print "%20s %6s (%s) => %6s (%s)" % (package_name, old_name, old_code,
+ root.get(VERSION_NAME), root.get(VERSION_CODE))
+ # TODO(eseidel): This isn't smart enough to wrap/intent multi-attribute
+ # elements like <manifest> as is the typical AndroidManifiest.xml style
+ # we could write our own custom prettyprinter to do that?
+ tree.write(manifest)
+ prepend_to_file(MANIFEST_PREFACE, manifest)
+
+
+def main():
+ print 'Pub packages:'
+ for pubspec in PUBSPECS:
+ update_pubspec(pubspec)
+
+ # TODO(eseidel): Without this ET uses 'ns0' for 'android' which is wrong.
+ ET.register_namespace('android', 'http://schemas.android.com/apk/res/android')
+
+ print 'APKs:'
+ for manifest in MANIFESTS:
+ update_manifest(manifest)
+
+
+if __name__ == '__main__':
+ main()
« no previous file with comments | « sky/sdk/pubspec.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698