#!/usr/bin/env python # -*- mode: python; coding: utf-8 -*- # Copyright © 2001, 2002 Translation Project. # Martin v. Löwis , 2001. """\ Create a clone of an existing package, adding an entry to the registry, assigning the translators of the existing package also to the new one, and then printing the new registry.sgml file on standard out plus the shell commands that would complete the cloning action. Usage: clone-domain MAGIC_KEY """ import os, sys, re, glob sys.path.insert(0, sys.path[0]+'/../lib') import config, registry, sgml os.environ['PATH'] = '/usr/lib:' + os.environ['PATH'] try: del os.environ['LANGUAGE'] except KeyError:pass try: del os.environ['LANG'] except KeyError:pass magic_key = "from old to new" old_domain = 'gnutls' # gettext new_domain = 'libgnutls' # gettext-runtime old_pattern = "gnutls-2.5.7" # gettext-0.11.5 new_pattern = "libgnutls-2.5.7" # gettext-runtime-0.11.5 def main(*arguments): if not arguments: sys.stdout.write(__doc__) sys.exit(0) if arguments[0] != magic_key: sys.stdout.write("Key is wrong, edit the script.\n") sys.exit(0) gen_registry() def gen_registry(): old = registry.registry.domain_info(old_domain) new = registry.registry.domains[new_domain] = {} new.update(old) new['name'] = new_domain registry.registry.domain_names.append(new_domain) for team in registry.registry.team_list(): for trans in team.translator.values(): trans = registry.registry.translator_info(team, trans.name[0]) try: _do = trans['do'] pos = _do.index(old_domain) try: _do.index(new_domain) except ValueError: _do[pos+1:pos+1] = [new_domain] except ValueError: pass sgml.decode_database() cp_po(config.pos_path) cp_po(config.pots_path) mklinks() renamed = {} def cp_po(dir): for f in os.listdir(dir): dir1 = os.path.join(dir, f) if not os.path.isdir(dir1): continue for f1 in os.listdir(dir1): f2 = re.sub(old_pattern, new_pattern, f1) if f1 == f2: continue print "cp %s %s" % (os.path.join(dir1, f1), os.path.join(dir1, f2)) def byversion(a, b): a = registry.hints(a[0]) b = registry.hints(b[0]) return cmp(a.version, b.version) def mklinks(): newdir = "%s/%s" % (config.last_path, new_domain) print "mkdir", newdir dir = (config.last_path+"/"+old_domain) for link in os.listdir(dir): oldfile = os.path.join(dir, link) if not os.path.islink(oldfile): continue if link[-3:] != ".po": continue team = link[:-3] oldlink = os.readlink(oldfile) newlink = re.sub(old_pattern, new_pattern, oldlink) if newlink == oldlink: # Link is good, need to make new link in newdir. podir = os.path.join(config.pos_path, team) pofiles = [] for f in glob.glob1(podir, old_pattern+"*"): f1 = re.sub(old_pattern, new_pattern, f) if f == f1: continue pofiles.append((f, f1)) pofiles.sort(byversion) if pofiles: print ("ln -s ../../%s/%s/%s %s/%s" % (config.pos_dir, team, pofiles[-1][1], newdir, link)) else: # Removing the link is undesirable: this translation # continues to be useful for the old domain as well. print "ln -s %s %s/%s" % (newlink, newdir, link) if __name__ == '__main__': apply(main, tuple(sys.argv[1:]))