| 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) 2014, 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 # | 10 # |
| 11 # "pub" must be in PATH. | 11 # "pub" must be in PATH. |
| 12 | 12 |
| 13 | 13 |
| 14 import os | 14 import os |
| 15 import os.path | 15 import os.path |
| 16 import re | |
| 17 import shutil | 16 import shutil |
| 18 import sys | 17 import sys |
| 19 import subprocess | 18 import subprocess |
| 20 import tempfile | 19 import tempfile |
| 21 | 20 |
| 22 def Main(argv): | 21 def Main(argv): |
| 23 HOME = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) | 22 HOME = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) |
| 24 | 23 |
| 25 pkgName = os.path.basename(os.path.normpath(argv[1])) | 24 pkgName = os.path.basename(os.path.normpath(argv[1])) |
| 26 | 25 |
| 27 pubspec = os.path.join(HOME, argv[1], 'pubspec.yaml') | 26 pubspec = os.path.join(HOME, argv[1], 'pubspec.yaml') |
| 28 if not os.path.exists(pubspec): | 27 if not os.path.exists(pubspec): |
| 29 print 'Error: did not find pubspec.yaml at ' + pubspec | 28 print 'Error: did not find pubspec.yaml at ' + pubspec |
| 30 return -1 | 29 return -1 |
| 31 | 30 |
| 32 with open(pubspec) as pubspecFile: | 31 with open(pubspec) as pubspecFile: |
| 33 lines = pubspecFile.readlines() | 32 lines = pubspecFile.readlines() |
| 34 | 33 |
| 35 version = None | 34 version = None |
| 36 foundSdkContraint = False | 35 foundSdkConstraint = False |
| 37 inDependencies = False | 36 inDependencies = False |
| 38 for line in lines: | 37 for line in lines: |
| 39 if line.startswith('dependencies:'): | 38 if line.startswith('dependencies:'): |
| 40 inDependencies = True | 39 inDependencies = True |
| 41 elif line.startswith('environment:'): | 40 elif line.startswith('environment:'): |
| 42 foundSdkContraint = True | 41 foundSdkConstraint = True |
| 43 elif line[0].isalpha(): | 42 elif line[0].isalpha(): |
| 44 inDependencies = False | 43 inDependencies = False |
| 45 if line.startswith('version:'): | 44 if line.startswith('version:'): |
| 46 version = line[len('version:'):].strip() | 45 version = line[len('version:'):].strip() |
| 47 if inDependencies: | 46 if inDependencies: |
| 48 if line.endswith(': any'): | 47 if line.endswith(': any'): |
| 49 print 'Error in %s: should not use "any" version constraint: %s' % ( | 48 print 'Error in %s: should not use "any" version constraint: %s' % ( |
| 50 pubspec, line) | 49 pubspec, line) |
| 51 return -1 | 50 return -1 |
| 52 | 51 |
| 53 if not version: | 52 if not version: |
| 54 print 'Error in %s: did not find package version.' % pubspec | 53 print 'Error in %s: did not find package version.' % pubspec |
| 55 return -1 | 54 return -1 |
| 56 | 55 |
| 57 if not foundSdkContraint: | 56 if not foundSdkConstraint: |
| 58 print 'Error in %s: did not find SDK version constraint.' % pubspec | 57 print 'Error in %s: did not find SDK version constraint.' % pubspec |
| 59 return -1 | 58 return -1 |
| 60 | 59 |
| 61 tmpDir = tempfile.mkdtemp() | 60 tmpDir = tempfile.mkdtemp() |
| 62 | 61 |
| 63 # | 62 # |
| 64 # If pubspec.yaml exists, check that the SDK's version constraint is valid | 63 # If pubspec.yaml exists, check that the SDK's version constraint is valid |
| 65 # | 64 # |
| 66 shutil.copytree(os.path.join(HOME, argv[1]), | 65 shutil.copytree(os.path.join(HOME, argv[1]), |
| 67 os.path.join(tmpDir, pkgName)) | 66 os.path.join(tmpDir, pkgName)) |
| 68 | 67 |
| 69 if not os.path.exists(os.path.join(tmpDir, pkgName, 'LICENSE')): | 68 if not os.path.exists(os.path.join(tmpDir, pkgName, 'LICENSE')): |
| 70 with open(os.path.join(tmpDir, pkgName, 'LICENSE'), 'w') as licenseFile: | 69 with open(os.path.join(tmpDir, pkgName, 'LICENSE'), 'w') as licenseFile: |
| 71 licenseFile.write( | 70 licenseFile.write( |
| 72 '''Copyright 2013, the Dart project authors. All rights reserved. | 71 '''Copyright 2014, the Dart project authors. All rights reserved. |
| 73 Redistribution and use in source and binary forms, with or without | 72 Redistribution and use in source and binary forms, with or without |
| 74 modification, are permitted provided that the following conditions are | 73 modification, are permitted provided that the following conditions are |
| 75 met: | 74 met: |
| 76 | 75 |
| 77 * Redistributions of source code must retain the above copyright | 76 * Redistributions of source code must retain the above copyright |
| 78 notice, this list of conditions and the following disclaimer. | 77 notice, this list of conditions and the following disclaimer. |
| 79 * Redistributions in binary form must reproduce the above | 78 * Redistributions in binary form must reproduce the above |
| 80 copyright notice, this list of conditions and the following | 79 copyright notice, this list of conditions and the following |
| 81 disclaimer in the documentation and/or other materials provided | 80 disclaimer in the documentation and/or other materials provided |
| 82 with the distribution. | 81 with the distribution. |
| 83 * Neither the name of Google Inc. nor the names of its | 82 * Neither the name of Google Inc. nor the names of its |
| 84 contributors may be used to endorse or promote products derived | 83 contributors may be used to endorse or promote products derived |
| 85 from this software without specific prior written permission. | 84 from this software without specific prior written permission. |
| 86 | 85 |
| 87 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 86 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 88 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 87 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 89 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 88 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 90 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 89 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 91 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 90 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 92 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 91 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 93 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 92 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 94 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 93 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 95 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 94 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 96 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 95 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 97 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 96 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 98 '''); | 97 ''') |
| 99 | 98 |
| 100 print 'publishing version ' + version + ' of ' + argv[1] + ' to pub.\n' | 99 print 'publishing version ' + version + ' of ' + argv[1] + ' to pub.\n' |
| 101 | 100 |
| 102 # TODO(jmesserly): this code puts things in the pub cache. Useful for testing | 101 # TODO(jmesserly): this code puts things in the pub cache. Useful for testing |
| 103 # without actually uploading. | 102 # without actually uploading. |
| 104 #cacheDir = os.path.join( | 103 #cacheDir = os.path.join( |
| 105 # os.path.expanduser('~/.pub-cache/hosted/pub.dartlang.org'), | 104 # os.path.expanduser('~/.pub-cache/hosted/pub.dartlang.org'), |
| 106 # pkgName + '-' + version) | 105 # pkgName + '-' + version) |
| 107 #print 'Moving to ' + cacheDir | 106 #print 'Moving to ' + cacheDir |
| 108 #shutil.move(os.path.join(tmpDir, pkgName), cacheDir) | 107 #shutil.move(os.path.join(tmpDir, pkgName), cacheDir) |
| 109 | 108 |
| 110 subprocess.call(['pub', 'publish'], cwd=os.path.join(tmpDir, pkgName)) | 109 subprocess.call(['pub', 'publish'], cwd=os.path.join(tmpDir, pkgName)) |
| 111 shutil.rmtree(tmpDir) | 110 shutil.rmtree(tmpDir) |
| 112 | 111 |
| 113 if __name__ == '__main__': | 112 if __name__ == '__main__': |
| 114 sys.exit(Main(sys.argv)) | 113 sys.exit(Main(sys.argv)) |
| OLD | NEW |