Ejemplo n.º 1
0
# Cleanup of temporary paths.
_tmppaths = set()

def record_tmppath (path):

    _tmppaths.add(path)


def cleanup_tmppaths (norem=set()):

    for path in _tmppaths:
        if path in norem:
            continue
        if os.path.isfile(path):
            os.unlink(path)
        elif os.path.isdir(path):
            shutil.rmtree(path)


def error_wcl (msg, norem=set()):

    if not isinstance(norem, set):
        norem = set(norem)
    cleanup_tmppaths(norem)
    error(msg)


if __name__ == '__main__':
    exit_on_exception(main, cleanup_tmppaths)
Ejemplo n.º 2
0
    shutil.copyfile(catpath, potpath)

    # Open catalog for pre-processing.
    cat = Catalog(potpath, monitored=False)

    # Decide wrapping policy.
    wrapping = select_field_wrapping(cfgsec, cat, cmlopt)

    # From the dummy template, clean all active messages and
    # remove all obsolete messages.
    for msg in cat:
        if msg.obsolete:
            cat.remove_on_sync(msg)
        else:
            msg.clear()
    cat.sync()

    # Merge with dummy template.
    merge_pofile(catpath_mod, potpath, update=True, wrapping=wrapping,
                 cmppaths=compendiums, fuzzex=fuzzex,
                 minwnex=minwnex, minasfz=minasfz, refuzzy=refuzzy,
                 abort=True)

    # Overwrite original with temporary catalog.
    shutil.move(catpath_mod, catpath)
    os.unlink(potpath)


if __name__ == '__main__':
    exit_on_exception(main)