Index: tools/publish_pkg.py |
=================================================================== |
--- tools/publish_pkg.py (revision 0) |
+++ tools/publish_pkg.py (revision 0) |
@@ -0,0 +1,80 @@ |
+#!/usr/bin/env python |
Jennifer Messerly
2012/11/29 01:07:05
copyright after this line?
dgrove
2012/11/29 01:14:23
Done.
|
+# |
+# Script to push a package to pub. |
+# |
+# Usage: publish_pkg.py pkg_dir |
+ |
+ |
+import os |
+import os.path |
+import re |
+import shutil |
+import sys |
+import subprocess |
+import tempfile |
+ |
+def ReplaceInFiles(paths, subs): |
+ '''Reads a series of files, applies a series of substitutions to each, and |
+ 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.
|
+ for path in paths: |
+ 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.
|
+ for pattern, replace in subs: |
+ contents = re.sub(pattern, replace, contents) |
+ |
+ dest = open(path, 'w') |
+ dest.write(contents) |
+ dest.close() |
+ |
+ |
+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.
|
+ for line in open(file).read().split('\n'): |
+ [k, v] = re.split('\s+', line) |
+ if field == k: |
+ return int(v) |
+ |
+def Main(argv): |
+ HOME = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) |
+ |
+ versionFile = os.path.join(HOME, 'tools', 'VERSION') |
+ major = readVersion(versionFile, 'MAJOR') |
+ minor = readVersion(versionFile, 'MINOR') |
+ build = readVersion(versionFile, 'BUILD') |
+ patch = readVersion(versionFile, 'PATCH') |
+ |
+ if major == 0 and minor <= 1: |
+ print 'Error: Do not run this script from a bleeding_edge checkout.' |
+ return -1 |
+ |
+ version = '%d.%d.%d+%d' % (major, minor, build, patch) |
+ |
+ tmpDir = tempfile.mkdtemp() |
+ pkgName = argv[1].split('/').pop() |
+ shutil.copytree(os.path.join(HOME, argv[1]), |
+ os.path.join(tmpDir, pkgName)) |
+ |
+ # Add version to pubspec file. |
+ pubspecFile = os.path.join(tmpDir, pkgName, 'pubspec.yaml') |
+ lines = open(pubspecFile).readlines() |
+ pubspec = open(pubspecFile, 'w') |
+ for line in lines: |
+ if line.startswith('description:'): |
+ 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.
|
+ if not line.startswith(' sdk:'): |
+ pubspec.write(line) |
+ pubspec.close() |
+ |
+ # 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,
|
+ for root, dirs, files in os.walk(os.path.join(tmpDir, pkgName)): |
+ 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.
|
+ shutil.rmtree(os.path.join(root, '.svn')) |
+ for name in files: |
+ if name.endswith('.dart'): |
+ ReplaceInFiles([os.path.join(root, name)], |
+ [(r'(import|part)(\s+)(\'|")(\.\./)+pkg/', r'\1\2\3package:')]) |
+ |
+ print 'publishing version ' + version + ' of ' + argv[1] + ' to pub\n' |
+ 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.
|
+ shutil.rmtree(tmpDir) |
+ |
+if __name__ == '__main__': |
+ sys.exit(Main(sys.argv)) |
Property changes on: tools/publish_pkg.py |
___________________________________________________________________ |
Added: svn:executable |
+ * |