#!/usr/bin/env python # -*- mode: python; coding: utf-8 -*- # Copyright © 2004 Translation Project """\ Fix the symlinks in the maintainer hierarchy. Usage: po-tidy-links [-n] -n dry run """ import os, sys, shutil, glob sys.path.insert(0, sys.path[0]+'/../lib') import config, data, registry dry_run=0 if "-n" in sys.argv: dry_run = 1 def checklink(arg, dir, fnames): for f in fnames: f = os.path.join(dir, f) if os.path.islink(f): if not os.path.exists(f): if dry_run: print "rm "+f else: os.unlink(f) #os.path.walk(os.path.join(config.last_path), checklink, None) files = data.load_postats().keys() missing = {} for dom, ver, team in files: linkname = os.path.join(config.last_path, dom, team+".po") if os.path.exists(linkname): continue try: missing[(dom,team)].append(registry.version(ver)) except KeyError: missing[(dom,team)]=[registry.version(ver)] for (dom, team), vers in missing.items(): vers.sort() ver = vers[-1].name source = "../../%s/%s/%s-%s.%s.po" % (config.pos_dir, team, dom, ver, team) target = os.path.join(config.last_path, dom, team+".po") assert not os.path.exists(source) t1 = os.path.normpath(os.path.join(os.path.dirname(target), source)) if not os.path.exists(t1): files = glob.glob1("%s/%s" % (config.pos_path, team), "%s-%s.%s*.po" % (dom, ver, team)) if len(files) != 1: print "%s does not exist, glob1 gives %s" % (t1, files) continue source = "../../%s/%s/%s" % (config.pos_dir, team, files[0]) t1 = os.path.normpath(os.path.join(os.path.dirname(target), source)) assert os.path.exists(t1), t1 if dry_run: print "ln -s %s %s" % (source, target) else: os.symlink(source, target)