OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # |
| 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 |
| 5 # BSD-style license that can be found in the LICENSE file. |
| 6 # |
| 7 # Script to push a package to pub. |
| 8 # |
| 9 # Usage: publish_pkg.py pkg_dir |
| 10 |
| 11 |
| 12 import os |
| 13 import os.path |
| 14 import re |
| 15 import shutil |
| 16 import sys |
| 17 import subprocess |
| 18 import tempfile |
| 19 |
| 20 def ReplaceInFiles(paths, subs): |
| 21 '''Reads a series of files, applies a series of substitutions to each, and |
| 22 saves them back out. subs should be a list of (pattern, replace) tuples.''' |
| 23 for path in paths: |
| 24 contents = open(path).read() |
| 25 for pattern, replace in subs: |
| 26 contents = re.sub(pattern, replace, contents) |
| 27 |
| 28 dest = open(path, 'w') |
| 29 dest.write(contents) |
| 30 dest.close() |
| 31 |
| 32 |
| 33 def ReadVersion(file, field): |
| 34 for line in open(file).read().split('\n'): |
| 35 [k, v] = re.split('\s+', line) |
| 36 if field == k: |
| 37 return int(v) |
| 38 |
| 39 def Main(argv): |
| 40 HOME = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) |
| 41 |
| 42 versionFile = os.path.join(HOME, 'tools', 'VERSION') |
| 43 major = ReadVersion(versionFile, 'MAJOR') |
| 44 minor = ReadVersion(versionFile, 'MINOR') |
| 45 build = ReadVersion(versionFile, 'BUILD') |
| 46 patch = ReadVersion(versionFile, 'PATCH') |
| 47 |
| 48 if major == 0 and minor <= 1: |
| 49 print 'Error: Do not run this script from a bleeding_edge checkout.' |
| 50 return -1 |
| 51 |
| 52 version = '%d.%d.%d+%d' % (major, minor, build, patch) |
| 53 |
| 54 tmpDir = tempfile.mkdtemp() |
| 55 pkgName = argv[1].split('/').pop() |
| 56 shutil.copytree(os.path.join(HOME, argv[1]), |
| 57 os.path.join(tmpDir, pkgName)) |
| 58 |
| 59 # Add version to pubspec file. |
| 60 pubspec = os.path.join(tmpDir, pkgName, 'pubspec.yaml') |
| 61 pubspecFile = open(pubspec) |
| 62 lines = pubspecFile.readlines() |
| 63 pubspecFile.close() |
| 64 pubspecFile = open(pubspec, 'w') |
| 65 foundVersion = False |
| 66 for line in lines: |
| 67 if line.startswith('version:'): |
| 68 foundVersion = True |
| 69 if line.startswith('description:') and not foundVersion: |
| 70 pubspecFile.write('version: ' + version + '\n') |
| 71 if not line.startswith(' sdk:'): |
| 72 pubspecFile.write(line) |
| 73 pubspecFile.close() |
| 74 |
| 75 # Replace '../*/pkg' imports and parts. |
| 76 for root, dirs, files in os.walk(os.path.join(tmpDir, pkgName)): |
| 77 for name in files: |
| 78 if name.endswith('.dart'): |
| 79 ReplaceInFiles([os.path.join(root, name)], |
| 80 [(r'(import|part)(\s+)(\'|")(\.\./)+pkg/', r'\1\2\3package:')]) |
| 81 |
| 82 print 'publishing version ' + version + ' of ' + argv[1] + ' to pub\n' |
| 83 print tmpDir |
| 84 subprocess.call(['pub', 'publish'], cwd=os.path.join(tmpDir, pkgName)) |
| 85 shutil.rmtree(tmpDir) |
| 86 |
| 87 if __name__ == '__main__': |
| 88 sys.exit(Main(sys.argv)) |
OLD | NEW |