Chromium Code Reviews
|
| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
|
Jennifer Messerly
2012/11/29 01:07:05
copyright after this line?
dgrove
2012/11/29 01:14:23
Done.
| |
| 2 # | |
| 3 # Script to push a package to pub. | |
| 4 # | |
| 5 # Usage: publish_pkg.py pkg_dir | |
| 6 | |
| 7 | |
| 8 import os | |
| 9 import os.path | |
| 10 import re | |
| 11 import shutil | |
| 12 import sys | |
| 13 import subprocess | |
| 14 import tempfile | |
| 15 | |
| 16 def ReplaceInFiles(paths, subs): | |
| 17 '''Reads a series of files, applies a series of substitutions to each, and | |
| 18 saves them back out. subs should by a list of (pattern, replace) tuples.''' | |
|
Bob Nystrom
2012/11/29 00:59:13
"by" -> "be"
dgrove
2012/11/29 01:14:23
Done.
| |
| 19 for path in paths: | |
| 20 contents = open(path).read() | |
|
Jennifer Messerly
2012/11/29 01:07:05
It's usually considered good practice to call .clo
dgrove
2012/11/29 01:14:23
Done.
| |
| 21 for pattern, replace in subs: | |
| 22 contents = re.sub(pattern, replace, contents) | |
| 23 | |
| 24 dest = open(path, 'w') | |
| 25 dest.write(contents) | |
| 26 dest.close() | |
| 27 | |
| 28 | |
| 29 def readVersion(file, field): | |
|
Bob Nystrom
2012/11/29 00:59:13
"ReadVersion" to be consistent with other function
Jennifer Messerly
2012/11/29 01:07:05
would be good to be consistent about UpperCamelCas
dgrove
2012/11/29 01:14:23
Done.
| |
| 30 for line in open(file).read().split('\n'): | |
| 31 [k, v] = re.split('\s+', line) | |
| 32 if field == k: | |
| 33 return int(v) | |
| 34 | |
| 35 def Main(argv): | |
| 36 HOME = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) | |
| 37 | |
| 38 versionFile = os.path.join(HOME, 'tools', 'VERSION') | |
| 39 major = readVersion(versionFile, 'MAJOR') | |
| 40 minor = readVersion(versionFile, 'MINOR') | |
| 41 build = readVersion(versionFile, 'BUILD') | |
| 42 patch = readVersion(versionFile, 'PATCH') | |
| 43 | |
| 44 if major == 0 and minor <= 1: | |
| 45 print 'Error: Do not run this script from a bleeding_edge checkout.' | |
| 46 return -1 | |
| 47 | |
| 48 version = '%d.%d.%d+%d' % (major, minor, build, patch) | |
| 49 | |
| 50 tmpDir = tempfile.mkdtemp() | |
| 51 pkgName = argv[1].split('/').pop() | |
| 52 shutil.copytree(os.path.join(HOME, argv[1]), | |
| 53 os.path.join(tmpDir, pkgName)) | |
| 54 | |
| 55 # Add version to pubspec file. | |
| 56 pubspecFile = os.path.join(tmpDir, pkgName, 'pubspec.yaml') | |
| 57 lines = open(pubspecFile).readlines() | |
| 58 pubspec = open(pubspecFile, 'w') | |
| 59 for line in lines: | |
| 60 if line.startswith('description:'): | |
| 61 pubspec.write('version: ' + version + '\n') | |
|
Bob Nystrom
2012/11/29 00:59:13
How about only doing this only if the pubspec does
dgrove
2012/11/29 01:14:23
Done.
| |
| 62 if not line.startswith(' sdk:'): | |
| 63 pubspec.write(line) | |
| 64 pubspec.close() | |
| 65 | |
| 66 # Delete .svn directories, replace '../*/pkg' imports and parts. | |
|
Jennifer Messerly
2012/11/29 01:07:05
Ideally we could delete any file that is not in so
dgrove
2012/11/29 01:14:23
Not that I know of. For now, pub will ignore .svn,
| |
| 67 for root, dirs, files in os.walk(os.path.join(tmpDir, pkgName)): | |
| 68 if '.svn' in dirs: | |
|
Bob Nystrom
2012/11/29 00:59:13
Pub should do this itself. Filed a bug: http://cod
Bob Nystrom
2012/11/29 01:04:58
Actually, I didn't give Nathan enough credit. It s
Jennifer Messerly
2012/11/29 01:07:05
according to Nathan, pub will already ignore "." f
dgrove
2012/11/29 01:14:23
Done.
dgrove
2012/11/29 01:14:23
Done.
| |
| 69 shutil.rmtree(os.path.join(root, '.svn')) | |
| 70 for name in files: | |
| 71 if name.endswith('.dart'): | |
| 72 ReplaceInFiles([os.path.join(root, name)], | |
| 73 [(r'(import|part)(\s+)(\'|")(\.\./)+pkg/', r'\1\2\3package:')]) | |
| 74 | |
| 75 print 'publishing version ' + version + ' of ' + argv[1] + ' to pub\n' | |
| 76 subprocess.call(['pub', 'publish', os.path.join(tmpDir, pkgName)]) | |
|
Bob Nystrom
2012/11/29 00:59:13
Pub doesn't take a path to the package. Instead, i
dgrove
2012/11/29 01:14:23
Done.
| |
| 77 shutil.rmtree(tmpDir) | |
| 78 | |
| 79 if __name__ == '__main__': | |
| 80 sys.exit(Main(sys.argv)) | |
| OLD | NEW |