def uploadTranslations(baseDir, scriptName, opts, args, type): if len(args) < 1: print 'Project key is required to upload existing translations.' usage(scriptName, type, 'uploadtrans') return key = args[0] from buildtools.packager import readMetadata metadata = readMetadata(baseDir, type) basename = metadata.get('general', 'basename') if type == 'chrome' or type == 'opera': import buildtools.packagerChrome as packager localesDir = os.path.join(baseDir, '_locales') locales = os.listdir(localesDir) locales = map(lambda locale: (locale.replace('_', '-'), os.path.join(localesDir, locale)), locales) else: import buildtools.packagerGecko as packager localesDir = packager.getLocalesDir(baseDir) locales = packager.getLocales(baseDir, True) locales = map(lambda locale: (locale, os.path.join(localesDir, locale)), locales) import buildtools.localeTools as localeTools for locale, localeDir in locales: if locale != packager.defaultLocale: localeTools.uploadTranslations(type, metadata, localeDir, locale, basename, key)
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 createBuild(baseDir, type, outFile=None, buildNum=None, releaseBuild=False, keyFile=None, devenv=False): metadata = readMetadata(baseDir, type) version = getBuildVersion(baseDir, metadata, releaseBuild, buildNum) if not outFile: outFile = getDefaultFileName(metadata, version, 'safariextz' if keyFile else 'zip') params = { 'type': type, 'baseDir': baseDir, 'releaseBuild': releaseBuild, 'version': version, 'devenv': devenv, 'metadata': metadata, } mapped = metadata.items('mapping') if metadata.has_section('mapping') else [] files = Files(getPackageFiles(params), getIgnoredFiles(params), process=lambda path, data: processFile(path, data, params)) files.readMappedFiles(mapped) files.read(baseDir, skip=[opt for opt, _ in mapped]) if metadata.has_section('convert_js'): convertJS(params, files) if metadata.has_section('preprocess'): files.preprocess( [f for f, _ in metadata.items('preprocess')], {'needsExt': True}, ) if metadata.has_section('import_locales'): import_locales(params, files) if metadata.has_option('general', 'testScripts'): files['qunit/index.html'] = createScriptPage(params, 'testIndex.html.tmpl', ('general', 'testScripts')) if keyFile: from buildtools import xarfile certs, key = xarfile.read_certificates_and_key(keyFile) params['developerIdentifier'] = get_developer_identifier(certs) files['lib/info.js'] = createInfoModule(params) files['background.html'] = createScriptPage(params, 'background.html.tmpl', ('general', 'backgroundScripts')) files['Info.plist'] = createManifest(params, files) dirname = metadata.get('general', 'basename') + '.safariextension' for filename in files.keys(): files[os.path.join(dirname, filename)] = files.pop(filename) if not devenv and keyFile: from buildtools import xarfile xarfile.create(outFile, files, keyFile) else: files.zip(outFile)
def getTranslations(baseDir, scriptName, opts, args, type): if len(args) < 1: print 'Project key is required to update translation master files.' usage(scriptName, type, 'translate') return key = args[0] import buildtools.packager as packager localesDir = packager.getLocalesDir(baseDir) basename = packager.readMetadata(baseDir).get('general', 'baseName') import buildtools.localeTools as localeTools localeTools.getTranslations(localesDir, packager.defaultLocale, basename, key)
def gettranslations(base_dir, project_key, platform, **kwargs): """ Download translation updates. Download updated translations from crowdin.com. """ from buildtools.packager import readMetadata metadata = readMetadata(base_dir, platform) basename = metadata.get('general', 'basename') locale_config = read_locale_config(base_dir, platform, metadata) import buildtools.localeTools as localeTools localeTools.getTranslations(locale_config, basename, project_key)
def setuptrans(base_dir, project_key, platform, **kwargs): """ Set up translation languages. Set up translation languages for the project on crowdin.com. """ from buildtools.packager import readMetadata metadata = readMetadata(base_dir, platform) basename = metadata.get('general', 'basename') locale_config = read_locale_config(base_dir, platform, metadata) import buildtools.localeTools as localeTools localeTools.setupTranslations(locale_config, basename, project_key)
def getTranslations(baseDir, scriptName, opts, args, type): if len(args) < 1: print 'Project key is required to update translation master files.' usage(scriptName, type, 'translate') return key = args[0] from buildtools.packager import readMetadata metadata = readMetadata(baseDir, type) basename = metadata.get('general', 'basename') localeConfig = readLocaleConfig(baseDir, type, metadata) import buildtools.localeTools as localeTools localeTools.getTranslations(localeConfig, basename, key)
def uploadtrans(base_dir, project_key, platform, **kwargs): """ Upload existing translations. Upload already existing translations to the project on crowdin.com. """ from buildtools.packager import readMetadata metadata = readMetadata(base_dir, platform) basename = metadata.get('general', 'basename') locale_config = read_locale_config(base_dir, platform, metadata) import buildtools.localeTools as localeTools for locale, locale_dir in locale_config['locales'].iteritems(): if locale != locale_config['default_locale'].replace('_', '-'): localeTools.uploadTranslations(locale_config, metadata, locale_dir, locale, basename, project_key)
def uploadTranslations(baseDir, scriptName, opts, args, type): if len(args) < 1: print 'Project key is required to upload existing translations.' usage(scriptName, type, 'uploadtrans') return key = args[0] from buildtools.packager import readMetadata metadata = readMetadata(baseDir, type) basename = metadata.get('general', 'basename') localeConfig = readLocaleConfig(baseDir, type, metadata) import buildtools.localeTools as localeTools for locale, localeDir in localeConfig['locales'].iteritems(): if locale != localeConfig['default_locale']: localeTools.uploadTranslations(localeConfig, metadata, localeDir, locale, basename, key)
def translate(base_dir, project_key, platform, **kwargs): """ Update translation master files. Update the translation master files in the project on crowdin.com. """ from buildtools.packager import readMetadata metadata = readMetadata(base_dir, platform) basename = metadata.get('general', 'basename') locale_config = read_locale_config(base_dir, platform, metadata) default_locale_dir = os.path.join(locale_config['base_path'], locale_config['default_locale']) import buildtools.localeTools as localeTools localeTools.updateTranslationMaster(locale_config, metadata, default_locale_dir, basename, project_key)
def getTranslations(baseDir, scriptName, opts, args, type): if len(args) < 1: print 'Project key is required to update translation master files.' usage(scriptName, type, 'translate') return from buildtools.packager import readMetadata metadata = readMetadata(baseDir, type) basename = metadata.get('general', 'basename') key = args[0] if type == 'chrome' or type == 'opera': import buildtools.packagerChrome as packager localesDir = os.path.join(baseDir, '_locales') else: import buildtools.packagerGecko as packager localesDir = packager.getLocalesDir(baseDir) import buildtools.localeTools as localeTools localeTools.getTranslations(type, localesDir, packager.defaultLocale.replace('_', '-'), basename, key)
def updateTranslationMaster(baseDir, scriptName, opts, args, type): if len(args) < 1: print 'Project key is required to update translation master files.' usage(scriptName, type, 'translate') return key = args[0] from buildtools.packager import readMetadata metadata = readMetadata(baseDir, type) basename = metadata.get('general', 'basename') localeConfig = readLocaleConfig(baseDir, type, metadata) defaultLocaleDir = os.path.join(localeConfig['base_path'], localeConfig['default_locale']) import buildtools.localeTools as localeTools localeTools.updateTranslationMaster(localeConfig, metadata, defaultLocaleDir, basename, key)
def updateTranslationMaster(baseDir, scriptName, opts, args, type): if len(args) < 1: print 'Project key is required to update translation master files.' usage(scriptName, type, 'translate') return key = args[0] from buildtools.packager import readMetadata metadata = readMetadata(baseDir, type) basename = metadata.get('general', 'basename') if type == 'chrome' or type == 'opera': import buildtools.packagerChrome as packager defaultLocaleDir = os.path.join(baseDir, '_locales', packager.defaultLocale) else: import buildtools.packagerGecko as packager defaultLocaleDir = os.path.join(packager.getLocalesDir(baseDir), packager.defaultLocale) import buildtools.localeTools as localeTools localeTools.updateTranslationMaster(type, metadata, defaultLocaleDir, basename, key)
def setupTranslations(baseDir, scriptName, opts, args, type): if len(args) < 1: print 'Project key is required to update translation master files.' usage(scriptName, type, 'setuptrans') return key = args[0] from buildtools.packager import readMetadata metadata = readMetadata(baseDir, type) basename = metadata.get('general', 'basename') if type == 'chrome' or type == 'opera': import buildtools.packagerChrome as packager locales = os.listdir(os.path.join(baseDir, '_locales')) locales = map(lambda locale: locale.replace('_', '-'), locales) else: import buildtools.packagerGecko as packager locales = packager.getLocales(baseDir, True) import buildtools.localeTools as localeTools localeTools.setupTranslations(type, locales, basename, key)
def edge_metadata(tmpdir): filename = 'metadata.edge' copy_metadata(filename, tmpdir) return packager.readMetadata(str(tmpdir), 'edge')
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)
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()