Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 3 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 4 # for details. All rights reserved. Use of this source code is governed by a | 4 # for details. All rights reserved. Use of this source code is governed by a |
| 5 # BSD-style license that can be found in the LICENSE file. | 5 # BSD-style license that can be found in the LICENSE file. |
| 6 # | 6 # |
| 7 # Script to push a package to pub. | 7 # Script to push a package to pub. |
| 8 # | 8 # |
| 9 # Usage: publish_pkg.py pkg_dir | 9 # Usage: publish_pkg.py pkg_dir |
| 10 # | |
| 11 # "pub" must be in PATH. | |
| 10 | 12 |
| 11 | 13 |
| 12 import os | 14 import os |
| 13 import os.path | 15 import os.path |
| 14 import re | 16 import re |
| 15 import shutil | 17 import shutil |
| 16 import sys | 18 import sys |
| 17 import subprocess | 19 import subprocess |
| 18 import tempfile | 20 import tempfile |
| 19 | 21 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 38 | 40 |
| 39 def Main(argv): | 41 def Main(argv): |
| 40 HOME = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) | 42 HOME = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) |
| 41 | 43 |
| 42 versionFile = os.path.join(HOME, 'tools', 'VERSION') | 44 versionFile = os.path.join(HOME, 'tools', 'VERSION') |
| 43 major = ReadVersion(versionFile, 'MAJOR') | 45 major = ReadVersion(versionFile, 'MAJOR') |
| 44 minor = ReadVersion(versionFile, 'MINOR') | 46 minor = ReadVersion(versionFile, 'MINOR') |
| 45 build = ReadVersion(versionFile, 'BUILD') | 47 build = ReadVersion(versionFile, 'BUILD') |
| 46 patch = ReadVersion(versionFile, 'PATCH') | 48 patch = ReadVersion(versionFile, 'PATCH') |
| 47 | 49 |
| 50 # bleeding_edge has a fixed version number of 0.1.x.y . Don't allow users | |
| 51 # to publish packages from bleeding_edge. | |
| 48 if major == 0 and minor <= 1: | 52 if major == 0 and minor <= 1: |
| 49 print 'Error: Do not run this script from a bleeding_edge checkout.' | 53 print 'Error: Do not run this script from a bleeding_edge checkout.' |
| 50 return -1 | 54 return -1 |
| 51 | 55 |
| 52 version = '%d.%d.%d+%d' % (major, minor, build, patch) | 56 version = '%d.%d.%d+%d' % (major, minor, build, patch) |
| 53 | 57 |
| 54 tmpDir = tempfile.mkdtemp() | 58 tmpDir = tempfile.mkdtemp() |
| 55 pkgName = argv[1].split('/').pop() | 59 pkgName = argv[1].split('/').pop() |
| 56 shutil.copytree(os.path.join(HOME, argv[1]), | |
| 57 os.path.join(tmpDir, pkgName)) | |
| 58 | 60 |
| 59 # Add version to pubspec file. | |
| 60 pubspec = os.path.join(tmpDir, pkgName, 'pubspec.yaml') | 61 pubspec = os.path.join(tmpDir, pkgName, 'pubspec.yaml') |
| 61 pubspecFile = open(pubspec) | 62 |
| 62 lines = pubspecFile.readlines() | 63 if os.path.exists(os.path.join(HOME, argv[1], 'pubspec.yaml')): |
| 63 pubspecFile.close() | 64 # |
| 64 pubspecFile = open(pubspec, 'w') | 65 # If pubspec.yaml exists, add the SDK's version number if |
| 65 foundVersion = False | 66 # no version number is present. |
| 66 for line in lines: | 67 # |
| 67 if line.startswith('version:'): | 68 shutil.copytree(os.path.join(HOME, argv[1]), |
| 68 foundVersion = True | 69 os.path.join(tmpDir, pkgName)) |
| 69 if line.startswith('description:') and not foundVersion: | 70 pubspecFile = open(pubspec) |
|
Bob Nystrom
2012/11/29 17:28:14
How about:
with open(pubspec) as pubspecFile:
.
dgrove
2012/11/29 18:45:31
Done.
| |
| 70 pubspecFile.write('version: ' + version + '\n') | 71 lines = pubspecFile.readlines() |
| 71 if not line.startswith(' sdk:'): | 72 pubspecFile.close() |
| 72 pubspecFile.write(line) | 73 pubspecFile = open(pubspec, 'w') |
| 73 pubspecFile.close() | 74 foundVersion = False |
| 74 | 75 for line in lines: |
| 76 if line.startswith('version:'): | |
| 77 foundVersion = True | |
| 78 if line.startswith('description:') and not foundVersion: | |
| 79 pubspecFile.write('version: ' + version + '\n') | |
|
Bob Nystrom
2012/11/29 17:28:14
This will fail if the pubspec happens to have its
dgrove
2012/11/29 18:45:31
Done.
| |
| 80 if not line.startswith(' sdk:'): | |
|
Bob Nystrom
2012/11/29 17:28:14
I'm not sure I understand this. Is the point to st
dgrove
2012/11/29 18:45:31
I fixed this so that it strips out both
sdk: p
| |
| 81 pubspecFile.write(line) | |
| 82 pubspecFile.close() | |
| 83 else: | |
| 84 # | |
| 85 # If there's a lib/ directory in the package, copy the package. | |
| 86 # Otherwise, move the package's contents to lib/. | |
| 87 # | |
| 88 if os.path.exists(os.path.join(HOME, argv[1], 'lib')): | |
| 89 shutil.copytree(os.path.join(HOME, argv[1]), | |
| 90 os.path.join(tmpDir, pkgName)) | |
| 91 else: | |
| 92 os.makedirs(os.path.join(tmpDir, pkgName)) | |
| 93 shutil.copytree(os.path.join(HOME, argv[1]), | |
| 94 os.path.join(tmpDir, pkgName, 'lib')) | |
| 95 | |
| 96 # Create pubspec.yaml . | |
| 97 pubspecFile = open(pubspec, 'w') | |
| 98 pubspecFile.write('name: ' + pkgName + '_unsupported\n') | |
| 99 pubspecFile.write('version: ' + version + '\n') | |
| 100 pubspecFile.write("description: >\n") | |
| 101 pubspecFile.write(' A completely unsupported clone of Dart SDK library\n') | |
| 102 pubspecFile.write(' ' + argv[1] + ' . This package will change in\n') | |
| 103 pubspecFile.write(' unpredictable/incompatible ways without warning.\n') | |
| 104 pubspecFile.write('dependencies:\n') | |
| 105 pubspecFile.close() | |
| 106 | |
| 75 # Replace '../*/pkg' imports and parts. | 107 # Replace '../*/pkg' imports and parts. |
| 76 for root, dirs, files in os.walk(os.path.join(tmpDir, pkgName)): | 108 for root, dirs, files in os.walk(os.path.join(tmpDir, pkgName)): |
| 77 for name in files: | 109 for name in files: |
| 78 if name.endswith('.dart'): | 110 if name.endswith('.dart'): |
| 79 ReplaceInFiles([os.path.join(root, name)], | 111 ReplaceInFiles([os.path.join(root, name)], |
| 80 [(r'(import|part)(\s+)(\'|")(\.\./)+pkg/', r'\1\2\3package:')]) | 112 [(r'(import|part)(\s+)(\'|")(\.\./)+pkg/', r'\1\2\3package:')]) |
| 81 | 113 |
| 82 print 'publishing version ' + version + ' of ' + argv[1] + ' to pub\n' | 114 print 'publishing version ' + version + ' of ' + argv[1] + ' to pub.\n' |
| 83 print tmpDir | |
| 84 subprocess.call(['pub', 'publish'], cwd=os.path.join(tmpDir, pkgName)) | 115 subprocess.call(['pub', 'publish'], cwd=os.path.join(tmpDir, pkgName)) |
| 85 shutil.rmtree(tmpDir) | 116 shutil.rmtree(tmpDir) |
| 86 | 117 |
| 87 if __name__ == '__main__': | 118 if __name__ == '__main__': |
| 88 sys.exit(Main(sys.argv)) | 119 sys.exit(Main(sys.argv)) |
| OLD | NEW |