# Upload the files if uploadType == 'local': #no upload, just copy to destination dest = os.path.join(config.get(base.BUILD_SECTION, 'buildout-server'), projectName) if not os.path.exists(dest): os.makedirs(dest) for filename in filesToUpload: shutil.copyfile(filename, os.path.join(dest, filename)) elif uploadType == 'webdav': if not options.offline and not options.noUpload: for filename in filesToUpload: base.uploadFile( filename, config.get( base.BUILD_SECTION, 'buildout-server')+'/'+projectName, config.get(base.BUILD_SECTION, 'buildout-server-username'), config.get(base.BUILD_SECTION, 'buildout-server-password'), options.offline) elif uploadType == 'mypypi': if not options.offline and not options.noUpload: server = config.get(base.BUILD_SECTION, 'buildout-server') if not server.endswith('/'): server += '/' url = (server + projectName + '/upload') boundary = "--------------GHSKFJDLGDS7543FJKLFHRE75642756743254" headers={"Content-Type": "multipart/form-data; boundary=%s; charset=utf-8" % boundary} for filename in filesToUpload: justfname = os.path.split(filename)[-1] #being lazy here with the construction of the multipart form data
def createRelease(self, version, branch): logger.info('Creating release %r for %r from branch %r' %( version, self.pkg, branch)) # 0. Skip creating releases in offline mode. if self.options.offline: logger.info('Offline: Skip creating a release.') return # 1. Create Release Tag branchUrl = self.getBranchURL(branch) tagUrl = self.getTagURL(version) logger.info('Creating release tag') #TODO: destination folder might not exist... create it self.svn.cp(branchUrl, tagUrl, "Create release tag %s." % version) #base.do('svn cp -m "Create release tag %s." %s %s' %( # version, branchUrl, tagUrl)) # 2. Download tag buildDir = tempfile.mkdtemp() tagDir = os.path.join(buildDir, '%s-%s' %(self.pkg, version)) self.svn.co(tagUrl, tagDir) #base.do('svn co %s %s' %(tagUrl, tagDir)) # 3. Create release # 3.1. Remove setup.cfg logger.info("Updating tag version metadata") setupCfgPath = os.path.join(tagDir, 'setup.cfg') if os.path.exists(setupCfgPath): os.remove(setupCfgPath) # 3.2. Update the version setuppy = file(os.path.join(tagDir, 'setup.py'), 'r').read() setuppy = re.sub( "version ?= ?'(.*)',", "version = '%s'," %version, setuppy) file(os.path.join(tagDir, 'setup.py'), 'w').write(setuppy) # 3.3. Check it all in self.svn.ci(tagDir, "Prepare for release %s." % version) #base.do('svn ci -m "Prepare for release %s." %s' %(version, tagDir)) # 4. Upload the distribution if self.uploadType == 'internal': # 3.4. Create distribution logger.info("Creating release tarball") base.do('python setup.py sdist', cwd = tagDir) if is_win32: ext = 'zip' else: ext = 'tar.gz' distributionFileName = os.path.join( tagDir, 'dist', '%s-%s.%s' %(self.pkg, version, ext)) if not self.options.noUpload: logger.info("Uploading release.") base.uploadFile( distributionFileName, self.packageIndexUrl, self.packageIndexUsername, self.packageIndexPassword, self.options.offline) elif self.uploadType == 'setup.py': # 3.4. Create distribution and upload in one step logger.info("Uploading release to PyPI.") # definitely DO NOT register!!! base.do('python setup.py sdist upload', cwd = tagDir) else: logger.warn('Unknown uploadType: ' + self.uploadType) # 5. Update the start branch to the next development (dev) version if not self.options.noBranchUpdate: logger.info("Updating branch version metadata") # 5.1. Check out the branch. branchDir = os.path.join(buildDir, 'branch') self.svn.co(branchUrl, branchDir) #base.do('svn co --non-recursive %s %s' %(branchUrl, branchDir)) # 5.2. Get the current version. setuppy = file(os.path.join(branchDir, 'setup.py'), 'r').read() currVersion = re.search("version ?= ?'(.*)',", setuppy) if not currVersion: logger.error("No version = found in setup.py, cannot update!") else: currVersion = currVersion.groups()[0] # 5.3. Update setup/py to the next version of the currently # released one newVersion = base.guessNextVersion(version) + 'dev' setuppy = re.sub( "version ?= ?'(.*)',", "version = '%s'," %newVersion, setuppy) file(os.path.join(branchDir, 'setup.py'), 'w').write(setuppy) # 5.4. Check in the changes. self.svn.ci(branchDir, "Update version number to %s." % newVersion) #base.do('svn ci -m "Update version number to %s." %s' %( # newVersion, branchDir)) # 6. Cleanup rmtree(buildDir)