def run(baseDir, downloadsRepo, buildtoolsRepo): baseExtDir = packagerKMeleon.getBaseExtensionDir(baseDir) # Read extension name, version and branch name locales = packager.readLocaleMetadata(baseExtDir, [packager.defaultLocale]) extensionName = locales[packager.defaultLocale]['name'] + ' for K-Meleon' metadata = packager.readMetadata(baseExtDir) metadata.read(packager.getMetadataPath(baseDir)) branchName = metadata.get('general', 'branchname') version = metadata.get('general', 'version') # Tag our source repository subprocess.Popen(['hg', 'tag', '-R', baseDir, '-f', version]).communicate() # Create a release build buildPath = os.path.join(downloadsRepo, packager.getDefaultFileName(baseDir, metadata, version, 'zip')) packagerKMeleon.createBuild(baseDir, outFile=buildPath, releaseBuild=True) # Create source archive archivePath = os.path.splitext(buildPath)[0] + '-source.tgz' archiveHandle = open(archivePath, 'wb') archive = tarfile.open(fileobj=archiveHandle, name=os.path.basename(archivePath), mode='w:gz') (data, dummy) = subprocess.Popen(['hg', 'archive', '-R', baseDir, '-t', 'tar', '-X', os.path.join(baseDir, '.hgtags'), '-'], stdout=subprocess.PIPE).communicate() repoArchive = tarfile.open(fileobj=StringIO(data), mode='r:') for fileInfo in repoArchive: fileData = repoArchive.extractfile(fileInfo) fileInfo.name = re.sub(r'^[^/]+/', '', fileInfo.name) archive.addfile(fileInfo, fileData) repoArchive.close() (data, dummy) = subprocess.Popen(['hg', 'archive', '-R', buildtoolsRepo, '-t', 'tar', '-X', os.path.join(buildtoolsRepo, '.hgtags'), '-'], stdout=subprocess.PIPE).communicate() repoArchive = tarfile.open(fileobj=StringIO(data), mode='r:') for fileInfo in repoArchive: fileData = repoArchive.extractfile(fileInfo) fileInfo.name = re.sub(r'^[^/]+/', 'buildtools/', fileInfo.name) archive.addfile(fileInfo, fileData) (data, dummy) = subprocess.Popen(['hg', 'archive', '-R', baseExtDir, '-t', 'tar', '-X', os.path.join(baseExtDir, '.hgtags'), '-'], stdout=subprocess.PIPE).communicate() repoArchive = tarfile.open(fileobj=StringIO(data), mode='r:') for fileInfo in repoArchive: fileData = repoArchive.extractfile(fileInfo) fileInfo.name = re.sub(r'^[^/]+/', '%s/' % os.path.basename(baseExtDir), fileInfo.name) archive.addfile(fileInfo, fileData) repoArchive.close() archive.close() archiveHandle.close() # Now add the downloads, commit and tag the downloads repo tagName = '%s_%s_RELEASE' % (branchName, version.replace('.', '_')) subprocess.Popen(['hg', 'add', '-R', downloadsRepo, buildPath, archivePath]).communicate() subprocess.Popen(['hg', 'commit', '-R', downloadsRepo, '-m', 'Releasing %s %s' % (extensionName, version)]).communicate() subprocess.Popen(['hg', 'tag', '-R', downloadsRepo, '-f', tagName]).communicate() # Tag buildtools repository as well subprocess.Popen(['hg', 'tag', '-R', buildtoolsRepo, '-f', tagName]).communicate() # Push all changes subprocess.Popen(['hg', 'push', '-R', baseDir]).communicate() subprocess.Popen(['hg', 'push', '-R', downloadsRepo]).communicate() subprocess.Popen(['hg', 'push', '-R', buildtoolsRepo]).communicate()
def run(baseDir, version, keyFile, downloadsRepo, buildtoolsRepo): # Replace version number in metadata file "manually", ConfigParser will mess # up the order of lines. handle = open(packager.getMetadataPath(baseDir), 'rb') rawMetadata = handle.read() handle.close() versionRegExp = re.compile(r'^(\s*version\s*=\s*).*', re.I | re.M) rawMetadata = re.sub(versionRegExp, r'\g<1>%s' % version, rawMetadata) handle = open(packager.getMetadataPath(baseDir), 'wb') handle.write(rawMetadata) handle.close() # Read extension name and branch name locales = packager.readLocaleMetadata(baseDir, [packager.defaultLocale]) extensionName = locales[packager.defaultLocale]['name'] metadata = packager.readMetadata(baseDir) branchName = metadata.get('general', 'branchname') # Now commit the change and tag it subprocess.Popen(['hg', 'commit', '-R', baseDir, '-m', 'Releasing %s %s' % (extensionName, version)]).communicate() subprocess.Popen(['hg', 'tag', '-R', baseDir, '-f', version]).communicate() # Create a release build buildPath = os.path.join(downloadsRepo, packager.getDefaultFileName(baseDir, metadata, version)) packager.createBuild(baseDir, outFile=buildPath, releaseBuild=True, keyFile=keyFile) # Create source archive archivePath = os.path.splitext(buildPath)[0] + '-source.tgz' archiveHandle = open(archivePath, 'wb') archive = tarfile.open(fileobj=archiveHandle, name=os.path.basename(archivePath), mode='w:gz') (data, dummy) = subprocess.Popen(['hg', 'archive', '-R', baseDir, '-t', 'tar', '-X', os.path.join(baseDir, '.hgtags'), '-'], stdout=subprocess.PIPE).communicate() repoArchive = tarfile.open(fileobj=StringIO(data), mode='r:') for fileInfo in repoArchive: fileData = repoArchive.extractfile(fileInfo) fileInfo.name = re.sub(r'^[^/]+/', '', fileInfo.name) archive.addfile(fileInfo, fileData) repoArchive.close() (data, dummy) = subprocess.Popen(['hg', 'archive', '-R', buildtoolsRepo, '-t', 'tar', '-X', os.path.join(buildtoolsRepo, '.hgtags'), '-'], stdout=subprocess.PIPE).communicate() repoArchive = tarfile.open(fileobj=StringIO(data), mode='r:') for fileInfo in repoArchive: fileData = repoArchive.extractfile(fileInfo) fileInfo.name = re.sub(r'^[^/]+/', 'buildtools/', fileInfo.name) archive.addfile(fileInfo, fileData) repoArchive.close() archive.close() archiveHandle.close() # Now add the downloads, commit and tag the downloads repo tagName = '%s_%s_RELEASE' % (branchName, version.replace('.', '_')) subprocess.Popen(['hg', 'add', '-R', downloadsRepo, buildPath, archivePath]).communicate() subprocess.Popen(['hg', 'commit', '-R', downloadsRepo, '-m', 'Releasing %s %s' % (extensionName, version)]).communicate() subprocess.Popen(['hg', 'tag', '-R', downloadsRepo, '-f', tagName]).communicate() # Tag buildtools repository as well subprocess.Popen(['hg', 'tag', '-R', buildtoolsRepo, '-f', tagName]).communicate() # Push all changes subprocess.Popen(['hg', 'push', '-R', baseDir]).communicate() subprocess.Popen(['hg', 'push', '-R', downloadsRepo]).communicate() subprocess.Popen(['hg', 'push', '-R', buildtoolsRepo]).communicate()
def createBuild(baseDir, outFile=None, locales=None, buildNum=None, releaseBuild=False): if buildNum == None: buildNum = packager.getBuildNum(baseDir) baseExtDir = getBaseExtensionDir(baseDir) if locales == None: locales = packager.getLocales(baseExtDir) elif locales == 'all': locales = packager.getLocales(baseExtDir, True) metadata = packager.readMetadata(baseExtDir) version = metadata.get('general', 'version') if not releaseBuild: version += '.' + buildNum params = { 'locales': locales, 'releaseBuild': releaseBuild, 'buildNum': buildNum, 'version': version.encode('utf-8'), 'metadata': metadata, 'limitMetadata': False, } baseName = metadata.get('general', 'baseName') chromeFiles = {} for xulFile in getXULFiles(baseDir): packager.readFile(chromeFiles, params, xulFile, 'content/ui/%s' % os.path.basename(xulFile)) files = {} files['modules/%s/Manifest.jsm' % baseName] = createManifest(baseExtDir, params) files['kplugins/%s.dll' % baseName] = buildDLL(baseDir, '%s.dll' % baseName, version) files['chrome/%s.jar' % baseName] = packager.createChromeJar(baseExtDir, params, files=chromeFiles) packager.readFile(files, params, os.path.join(baseExtDir, 'chrome.manifest'), 'chrome/%s.manifest' % baseName) files['chrome/%s.manifest' % baseName] = processChromeManifest(files['chrome/%s.manifest' % baseName], baseName) for macroFile in getMacroFiles(baseDir): packager.readFile(files, params, macroFile, 'macros/%s' % os.path.basename(macroFile)) for interfaceFile in getInterfaceFiles(baseDir): packager.readFile(files, params, interfaceFile, 'components/%s' % os.path.basename(interfaceFile)) for moduleFile in getModuleFiles(baseDir): packager.readFile(files, params, moduleFile, 'modules/%s/%s' % (baseName, os.path.basename(moduleFile))) for prefsFile in getPrefsFiles(baseDir): packager.readFile(files, params, prefsFile, 'defaults/pref/%s' % os.path.basename(prefsFile)) packager.readFile(files, params, os.path.join(baseExtDir, 'defaults'), 'defaults') packager.readFile(files, params, os.path.join(baseExtDir, 'modules'), 'modules/%s' %baseName) # Correct files names (defaults/preferences/ => defaults/pref/) newFiles = {} for key, value in files.iteritems(): if key.startswith('defaults/preferences/'): key = 'defaults/pref/' + key[len('defaults/preferences/'):] newFiles[key] = value files = newFiles # Allow local metadata to overrite settings from base extension metadata.read(packager.getMetadataPath(baseDir)) if outFile == None: outFile = packager.getDefaultFileName(baseDir, metadata, version, 'zip') packager.writeXPI(files, outFile)