コード例 #1
0
def do_file(file_name, lang_codes):
    if verbose:
        sys.stderr.write('%s...\n' % file_name)
    split_file_name = file_name.split('/')
    d1, d2 = split_file_name[0:2]
    if d1 in lang_codes:
        check_lang = d1
        lang_dir_index = 0
    elif d2 in lang_codes:
        check_lang = d2
        lang_dir_index = 1
    else:
        check_lang = lang
    if check_lang == C:
        raise Exception('cannot determine language for ' + file_name)
    else:
        if os.path.splitext(file_name)[1] == '.texidoc':
            original = file_name.replace(os.path.join(check_lang, 'texidocs'),
                                         'snippets', 1)
            original = original.replace('.texidoc', '.ly', 1)
        else:
            original = dir_lang(file_name, 'en', lang_dir_index)
        translated_contents = open(file_name, encoding='utf8').read()

        # experimental feature
        if not touch_committishes in (current_revision, 'HEAD'):
            (changes_in_original, error) = \
                buildlib.check_translated_doc(original,
                                              file_name,
                                              translated_contents,
                                              upper_revision=touch_committishes)
            if not error and not changes_in_original in ('', '\n'):
                translated_contents = \
                    buildlib.revision_re.sub('GIT committish: ' + current_revision,
                                             translated_contents, 1)
                f = open(file_name, 'w',
                         encoding='utf8').write(translated_contents)
                return

    (diff_string, error) \
        = buildlib.check_translated_doc(original,
                                        file_name,
                                        translated_contents,
                                        color=use_colors and not update_mode)

    if error:
        sys.stderr.write('warning: %s: %s' % (file_name, error))

    if update_mode:
        if error or len(diff_string) >= os.path.getsize(original):
            buildlib.read_pipe(text_editor + ' ' + file_name + ' ' + original)
        elif diff_string:
            diff_file = original + '.diff'
            f = open(diff_file, 'w', encoding='utf8')
            f.write(diff_string)
            f.close()
            buildlib.read_pipe(text_editor + ' ' + file_name + ' ' + diff_file)
            os.remove(diff_file)
    else:
        sys.stdout.write(diff_string)
コード例 #2
0
def do_file (file_name, lang_codes):
    if verbose:
        sys.stderr.write ('%s...\n' % file_name)
    split_file_name = file_name.split ('/')
    d1, d2 = split_file_name[0:2]
    if d1 in lang_codes:
        check_lang = d1
        lang_dir_index = 0
    elif d2 in lang_codes:
        check_lang = d2
        lang_dir_index = 1
    else:
        check_lang = lang
    if check_lang == C:
        raise Exception ('cannot determine language for ' + file_name)
    else:
        if os.path.splitext (file_name)[1] == '.texidoc':
            original = file_name.replace (os.path.join (check_lang, 'texidocs'), 'snippets', 1)
            original = original.replace ('.texidoc', '.ly', 1)
        else:
            original = dir_lang (file_name, '', lang_dir_index)
        translated_contents = open (file_name).read ()

        ## experimental feature
        if not touch_committishes in (current_revision, 'HEAD'):
            (changes_in_original, error) = \
                buildlib.check_translated_doc (original,
                                               file_name,
                                               translated_contents,
                                               upper_revision=touch_committishes)
            if not error and not changes_in_original in ('', '\n'):
                translated_contents = \
                    buildlib.revision_re.sub ('GIT committish: ' + current_revision,
                                              translated_contents, 1)
                f = open (file_name, 'w').write (translated_contents)
                return
    (diff_string, error) \
        = buildlib.check_translated_doc (original,
                                         file_name,
                                         translated_contents,
                                         color=use_colors and not update_mode)

    if error:
        sys.stderr.write ('warning: %s: %s' % (file_name, error))

    if update_mode:
        if error or len (diff_string) >= os.path.getsize (original):
            buildlib.read_pipe (text_editor + ' ' + file_name + ' ' + original)
        elif diff_string:
            diff_file = original + '.diff'
            f = open (diff_file, 'w')
            f.write (diff_string)
            f.close ()
            buildlib.read_pipe (text_editor + ' ' + file_name + ' ' + diff_file)
            os.remove (diff_file)
    else:
        sys.stdout.write (diff_string)
コード例 #3
0
def main ():
    global update_mode, text_editor, touch_committishes, current_revision

    files = do_options ()
    if 'EDITOR' in os.environ:
        text_editor = os.environ['EDITOR']
    else:
        update_mode = False
    buildlib.verbose = verbose
    (parsed_revision, error) = buildlib.read_pipe (vc_revision_parse % touch_committishes)
    if error:
        sys.stderr.write ('warning: %s' % error)
    else:
        touch_committishes = parsed_revision.strip ()
    current_revision = buildlib.read_pipe (vc_revision_parse % 'HEAD')[0]

    for i in files:
        do_file (i, list(langdefs.LANGDICT.keys ()))
コード例 #4
0
def main ():
    global update_mode, text_editor, touch_committishes, current_revision

    files = do_options ()
    if 'EDITOR' in os.environ:
        text_editor = os.environ['EDITOR']
    else:
        update_mode = False
    buildlib.verbose = verbose
    (parsed_revision, error) = buildlib.read_pipe (vc_revision_parse % touch_committishes)
    if error:
        sys.stderr.write ('warning: %s' % error)
    else:
        touch_committishes = parsed_revision.strip ()
    current_revision = buildlib.read_pipe (vc_revision_parse % 'HEAD')[0]

    for i in files:
        do_file (i, langdefs.LANGDICT.keys ())
コード例 #5
0

def update_category_word_counts_sub(m):
    return ('-' + m.group(1) + '-' + m.group(2) +
            str(sum([int(c)
                     for c in counts_re.findall(m.group(2))])).ljust(6) +
            'total')


# urg
# main () starts here-abouts

progress("Reading documents...")

master_files = []
for l in buildlib.read_pipe("git ls-files en")[0].split('\n'):
    if re.match(r"^en/[^./]*\.(texi|tely)$", l):
        master_files.append(l)
master_files.sort()

master_docs = [
    MasterTelyDocument(os.path.normpath(filename)) for filename in master_files
]
master_docs = [doc for doc in master_docs if doc.translations]

enabled_languages = [
    l for l in langdefs.LANGDICT if langdefs.LANGDICT[l].enabled and l != 'en'
]

progress("Generating status pages...")
コード例 #6
0
counts_re = re.compile (r'(?m)^(\d+) ')

def update_category_word_counts_sub (m):
    return ('-' + m.group (1) + '-' + m.group (2)
            + str (sum ([int (c)
                         for c in counts_re.findall (m.group (2))])).ljust (6)
            + 'total')

# urg 
# main () starts here-abouts

progress ("Reading documents...")

master_files = \
    buildlib.read_pipe ("git ls-files | grep -E '[^/]*/?[^/]*[.](tely|texi)$'")[0].splitlines ()
master_files.sort ()
master_docs = [MasterTelyDocument (os.path.normpath (filename))
               for filename in master_files]
master_docs = [doc for doc in master_docs if doc.translations]

enabled_languages = [l for l in langdefs.LANGDICT
                     if langdefs.LANGDICT[l].enabled
                     and l != 'en']

progress ("Generating status pages...")

date_time = buildlib.read_pipe ('LANG= date -u')[0]

# TEXI output sort of works
# TODO: table border, td-titles :-)
コード例 #7
0
counts_re = re.compile (r'(?m)^(\d+) ')

def update_category_word_counts_sub (m):
    return ('-' + m.group (1) + '-' + m.group (2)
            + str (sum ([int (c)
                         for c in counts_re.findall (m.group (2))])).ljust (6)
            + 'total')

# urg 
# main () starts here-abouts

progress ("Reading documents...")

master_files = \
    buildlib.read_pipe ("git ls-files | grep -E '[^/]*/?[^/]*[.](tely|texi)$'")[0].splitlines ()
master_files.sort ()
master_docs = [MasterTelyDocument (os.path.normpath (filename))
               for filename in master_files]
master_docs = [doc for doc in master_docs if doc.translations]

enabled_languages = [l for l in langdefs.LANGDICT
                     if langdefs.LANGDICT[l].enabled
                     and l != 'en']

progress ("Generating status pages...")

date_time = buildlib.read_pipe ('LANG= date -u')[0]

# TEXI output sort of works
# TODO: table border, td-titles :-)
コード例 #8
0
update_category_word_counts_re = re.compile (r'(?ms)^-(\d+)-(.*?\n)\d+ *total')

counts_re = re.compile (r'(?m)^(\d+) ')

def update_category_word_counts_sub (m):
    return '-' + m.group (1) + '-' + m.group (2) + \
        str (sum ([int (c)
                   for c in counts_re.findall (m.group (2))])).ljust (6) + \
        'total'


progress ("Reading documents...")

master_files = \
    buildlib.read_pipe ("find -maxdepth 2 -and -name '*.tely' -or -name '*.texi'")[0].splitlines ()
master_files.sort ()
master_docs = [MasterTelyDocument (os.path.normpath (filename))
               for filename in master_files]
master_docs = [doc for doc in master_docs if doc.translations]

main_status_page = open ('translations.template.html.in').read ()

enabled_languages = [l for l in langdefs.LANGDICT
                     if langdefs.LANGDICT[l].enabled
                     and l != 'en']
lang_status_pages = \
    dict ([(l, open (os.path.join (l, 'translations.template.html.in')). read ())
           for l in enabled_languages])

progress ("Generating status pages...")