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

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