Index: tools/publish_pkg.py |
=================================================================== |
--- tools/publish_pkg.py (revision 15525) |
+++ tools/publish_pkg.py (working copy) |
@@ -7,6 +7,8 @@ |
# Script to push a package to pub. |
# |
# Usage: publish_pkg.py pkg_dir |
+# |
+# "pub" must be in PATH. |
import os |
@@ -45,6 +47,8 @@ |
build = ReadVersion(versionFile, 'BUILD') |
patch = ReadVersion(versionFile, 'PATCH') |
+ # bleeding_edge has a fixed version number of 0.1.x.y . Don't allow users |
+ # to publish packages from bleeding_edge. |
if major == 0 and minor <= 1: |
print 'Error: Do not run this script from a bleeding_edge checkout.' |
return -1 |
@@ -53,25 +57,53 @@ |
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. |
pubspec = os.path.join(tmpDir, pkgName, 'pubspec.yaml') |
- pubspecFile = open(pubspec) |
- lines = pubspecFile.readlines() |
- pubspecFile.close() |
- pubspecFile = open(pubspec, 'w') |
- foundVersion = False |
- for line in lines: |
- if line.startswith('version:'): |
- foundVersion = True |
- if line.startswith('description:') and not foundVersion: |
- pubspecFile.write('version: ' + version + '\n') |
- if not line.startswith(' sdk:'): |
- pubspecFile.write(line) |
- pubspecFile.close() |
- |
+ |
+ if os.path.exists(os.path.join(HOME, argv[1], 'pubspec.yaml')): |
+ # |
+ # If pubspec.yaml exists, add the SDK's version number if |
+ # no version number is present. |
+ # |
+ shutil.copytree(os.path.join(HOME, argv[1]), |
+ os.path.join(tmpDir, pkgName)) |
+ 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.
|
+ lines = pubspecFile.readlines() |
+ pubspecFile.close() |
+ pubspecFile = open(pubspec, 'w') |
+ foundVersion = False |
+ for line in lines: |
+ if line.startswith('version:'): |
+ foundVersion = True |
+ if line.startswith('description:') and not foundVersion: |
+ 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.
|
+ 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
|
+ pubspecFile.write(line) |
+ pubspecFile.close() |
+ else: |
+ # |
+ # If there's a lib/ directory in the package, copy the package. |
+ # Otherwise, move the package's contents to lib/. |
+ # |
+ if os.path.exists(os.path.join(HOME, argv[1], 'lib')): |
+ shutil.copytree(os.path.join(HOME, argv[1]), |
+ os.path.join(tmpDir, pkgName)) |
+ else: |
+ os.makedirs(os.path.join(tmpDir, pkgName)) |
+ shutil.copytree(os.path.join(HOME, argv[1]), |
+ os.path.join(tmpDir, pkgName, 'lib')) |
+ |
+ # Create pubspec.yaml . |
+ pubspecFile = open(pubspec, 'w') |
+ pubspecFile.write('name: ' + pkgName + '_unsupported\n') |
+ pubspecFile.write('version: ' + version + '\n') |
+ pubspecFile.write("description: >\n") |
+ pubspecFile.write(' A completely unsupported clone of Dart SDK library\n') |
+ pubspecFile.write(' ' + argv[1] + ' . This package will change in\n') |
+ pubspecFile.write(' unpredictable/incompatible ways without warning.\n') |
+ pubspecFile.write('dependencies:\n') |
+ pubspecFile.close() |
+ |
# Replace '../*/pkg' imports and parts. |
for root, dirs, files in os.walk(os.path.join(tmpDir, pkgName)): |
for name in files: |
@@ -79,8 +111,7 @@ |
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' |
- print tmpDir |
+ print 'publishing version ' + version + ' of ' + argv[1] + ' to pub.\n' |
subprocess.call(['pub', 'publish'], cwd=os.path.join(tmpDir, pkgName)) |
shutil.rmtree(tmpDir) |