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)'
' the source code (MAKE A BACKUP FIRST)') # Worse parser.add_option('-w', '--worse', action='store', type='int', metavar='INT', dest='worse', default=-1, help='number of worse files showed, 0 for all') # Show lines parser.add_option('-s', '--show-lines', action='store_true', dest='show_lines', default=False, help='give the line of each problem found') options, args = parser.parse_args() # Filenames worktree = open_worktree('.', soft=True) if args: filenames = set([]) for arg in args: filenames = filenames.union(glob(arg)) filenames = list(filenames) elif worktree: filenames = worktree.get_filenames() filenames = [ x for x in filenames if x.endswith('.py') ] else: filenames = [] for path in lfs.traverse(): if lfs.is_file(path) and basename(path).endswith('.py'): filenames.append(relpath(path)) # Check options
dest='worse', default=-1, help='number of worse files showed, 0 for all') # Show lines parser.add_option('-s', '--show-lines', action='store_true', dest='show_lines', default=False, help='give the line of each problem found') options, args = parser.parse_args() # Filenames worktree = open_worktree('.', soft=True) if args: filenames = set([]) for arg in args: filenames = filenames.union(glob(arg)) filenames = list(filenames) elif worktree: filenames = worktree.get_filenames() filenames = [x for x in filenames if x.endswith('.py')] else: filenames = [] for path in lfs.traverse(): if lfs.is_file(path) and basename(path).endswith('.py'): filenames.append(relpath(path)) # Check options
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)