def build(): # (1) Initialize the manifest file manifest = set([x for x in get_manifest() if not islink(x)]) manifest.add('MANIFEST') # (2) Find out the version string worktree = open_worktree('.') version = make_version(worktree) open('version.txt', 'w').write(version) print '* Version:', version manifest.add('version.txt') # (3) Rules rules = [('.po', '.mo', po2mo), ('.scss', '.css', scss2css)] # Templates config = get_config() src_lang = config.get_value('source_language', default='en') for dst_lang in config.get_value('target_languages'): rules.append( ('.xml.%s' % src_lang, '.xml.%s' % dst_lang, make_template)) rules.append( ('.xhtml.%s' % src_lang, '.xhtml.%s' % dst_lang, make_template)) # (4) Make make(worktree, rules, manifest) # (5) Write the manifest lines = [x + '\n' for x in sorted(manifest)] open('MANIFEST', 'w').write(''.join(lines)) print '* Build MANIFEST file (list of files to install)'
def build(): config = get_config() package_root = config.get_value('package_root') # (1) Initialize the manifest file manifest = set([ x for x in get_manifest() if not islink(x) ]) manifest.add('MANIFEST') # (2) Find out the version string worktree = open_worktree('.') version = make_version(worktree) version_txt = 'version.txt' if package_root == '.' \ else package_root + '/version.txt' open(version_txt, 'w').write(version) print '* Version:', version manifest.add(version_txt) # (3) Rules rules = [ ('.po', '.mo', po2mo), ('.scss', '.css', scss2css)] # Templates src_lang = config.get_value('source_language', default='en') for dst_lang in config.get_value('target_languages'): rules.append( ('.xml.%s' % src_lang, '.xml.%s' % dst_lang, make_template)) rules.append( ('.xhtml.%s' % src_lang, '.xhtml.%s' % dst_lang, make_template)) # (4) Make make(worktree, rules, manifest) # (5) Write the manifest lines = [ x + '\n' for x in sorted(manifest) ] open('MANIFEST', 'w').write(''.join(lines)) print '* Build MANIFEST file (list of files to install)'
def build(): worktree = open_worktree('.', soft=True) # Try using git facilities if not worktree: print "Warning: not using git." # Read configuration for languages config = get_config() source_language = config.get_value('source_language', default='en') target_languages = config.get_value('target_languages') # (1) Initialize the manifest file manifest = [ x for x in get_manifest() if not islink(x) ] manifest.append('MANIFEST') # Find out the version string if worktree: version = make_version() open('version.txt', 'w').write(version) print '* Version:', version manifest.append('version.txt') # (2) Internationalization bad_templates = [] if lfs.exists('locale'): # Build MO files print '* Compile message catalogs:', stdout.flush() for lang in (source_language,) + target_languages: print lang, stdout.flush() call([ 'msgfmt', 'locale/%s.po' % lang, '-o', 'locale/%s.mo' % lang]) # Add to the manifest manifest.append('locale/%s.mo' % lang) print # Load message catalogs message_catalogs = {} for lang in target_languages: path = 'locale/%s.po' % lang handler = ro_database.get_handler(path) message_catalogs[lang] = (handler, lfs.get_mtime(path)) # Build the templates in the target languages good_files = compile('.*\\.x.*ml.%s$' % source_language) exclude = frozenset(['.git', 'build', 'docs', 'dist']) lines = get_files(exclude, filter=lambda x: good_files.match(x)) lines = list(lines) if lines: print '* Build XHTML files', stdout.flush() for path in lines: # Load the handler src_mtime = lfs.get_mtime(path) src = ro_database.get_handler(path, XHTMLFile) done = False # Build the translation n = path.rfind('.') error = False for language in target_languages: po, po_mtime = message_catalogs[language] dst = '%s.%s' % (path[:n], language) # Add to the manifest manifest.append(dst) # Skip the file if it is already up-to-date if lfs.exists(dst): dst_mtime = lfs.get_mtime(dst) if dst_mtime > src_mtime and dst_mtime > po_mtime: continue try: data = src.translate(po) except StandardError: error = True bad_templates.append((path, exc_info())) else: open(dst, 'w').write(data) done = True # Done if error is True: stdout.write('E') elif done is True: stdout.write('*') else: stdout.write('.') stdout.flush() print # (3) Build the manifest file manifest.sort() lines = [ x + '\n' for x in manifest ] open('MANIFEST', 'w').write(''.join(lines)) print '* Build MANIFEST file (list of files to install)' # (4) Show errors if bad_templates: print print '***********************************************************' print 'The following templates could not be translated' print '***********************************************************' for (path, (type, value, traceback)) in bad_templates: print print path print_exception(type, value, traceback)
# The command line parser version = 'itools %s' % itools.__version__ description = ('Updates the message catalogs (POT and PO files) in the' ' "locale" directory, with the messages found in the' ' source.') parser = OptionParser('%prog', version=version, description=description) parser.add_option('-s', '--srx', help='Use an other SRX file than the default one.') options, args = parser.parse_args() if len(args) != 0: parser.error('incorrect number of arguments') # Read configuration for languages config = get_config() src_language = config.get_value('source_language', default='en') # Get local folder package_root = config.get_value('package_root') if lfs.exists(package_root): locale_folder_path = Path('{0}/locale'.format(package_root)) else: locale_folder_path = Path('locale/') locale_folder = lfs.open(locale_folder_path) # The SRX file if options.srx is not None: srx_handler = ro_database.get_handler(options.srx) else: srx_handler = None
# The command line parser version = 'itools %s' % itools.__version__ description = ('Builds the package.') parser = OptionParser('%prog', version=version, description=description) options, args = parser.parse_args() if len(args) != 0: parser.error('incorrect number of arguments') # Try using git facilities git_available = git.is_available() if not git_available: print "Warning: not using git." # Read configuration for languages config = get_config() source_language = config.get_value('source_language', default='en') target_languages = config.get_value('target_languages') # (1) Initialize the manifest file manifest = [ x for x in get_manifest() if not islink(x) ] manifest.append('MANIFEST') # Find out the version string if git_available: version = make_version() open('version.txt', 'w').write(version) print '* Version:', version manifest.append('version.txt') # (2) Internationalization bad_templates = []