def handle(self, *args, **options): if len(args) != 2: raise CommandError, "two arguments required, old and new appversion" fork = AppVersion.objects.get(code=args[0]) target = AppVersion.objects.get(code=args[1]) if fork.tree.l10n != target.tree.l10n: raise CommandError, "Fork and target appversion don't share l10n" fsos = _signoffs(fork) tsos = _signoffs(target) known_push_ids = dict(tsos.values_list('locale__code','push__id')) sos = fsos.exclude(push__id__in=known_push_ids.values()) for so in sos.order_by('locale__code').select_related('locale'): if so.push_id <= known_push_ids[so.locale.code]: print "not merging %s, target newer" % so.locale.code continue print "merging " + so.locale.code _so = target.signoffs.create(push = so.push, author = so.author, when = so.when, locale = so.locale) for a in so.action_set.order_by('pk'): _so.action_set.create(flag = a.flag, author = a.author, when = a.when, comment = a.comment)
def handle(self, *args, **options): appver = options.get('appver', None) if appver is None: ms = options.get('ms', None) if ms is not None: av_or_m = Milestone.objects.get(code=ms) else: av_or_m = AppVersion.objects.get(code=appver) if not args or av_or_m is None: return sos = _signoffs(av_or_m).annotate(tip=Max('push__changesets__id')) tips = dict(sos.values_list('locale__code', 'tip')) revmap = dict(Changeset.objects.filter(id__in=tips.values()).values_list('id', 'revision')) multi = map(lambda s: s.strip(), open(args[0]).readlines()) chunks = [] for loc in sorted(tips.keys()): platforms = ['"maemo"'] if loc in multi: platforms.append('"maemo-multilocale"') platforms = ', '.join(platforms) chunks.append(''' "%(loc)s": { "revision": "%(rev)s", "platforms": [%(plat)s] }''' % {"loc":loc, "rev":revmap[tips[loc]][:12], "plat": platforms}) out = "{\n%s\n}" % ",\n".join(chunks) print out
def handle(self, *args, **options): if len(args) != 2: raise CommandError, "two arguments required, old and new appversion" old = AppVersion.objects.get(code=args[0]) new = AppVersion.objects.get(code=args[1]) if old.tree.l10n != new.tree.l10n: raise CommandError, "Old and new appversion don't share l10n" sos = _signoffs(old) for so in sos: print "transplanting " + so.locale.code _so = new.signoffs.create(push = so.push, author = so.author, when = so.when, locale = so.locale) for a in so.action_set.order_by('pk'): _so.action_set.create(flag = a.flag, author = a.author, when = a.when, comment = a.comment)
def handle(self, *args, **options): quiet = options.get('quiet', False) if not args: return try: ms = Milestone.objects.get(code=args[0]) except: raise CommandError, "No milestone with code %s found" % args[0] forest = ms.appver.tree.l10n.name.split('/') def resolve(path): return os.path.join(settings.REPOSITORY_BASE, *(forest + path.split('/'))) sos=dict(_signoffs(ms).values_list('locale__code', 'push_id')) tips = dict(Push.objects.filter(id__in=sos.values()).annotate(tip=Max('changesets__id')).values_list('id', 'tip')) revs = dict(Changeset.objects.filter(id__in=tips.values()).values_list('id','revision')) from mercurial.dispatch import dispatch as hgdispatch for loc in sorted(sos.keys()): repopath = resolve(loc) rev = revs[tips[sos[loc]]] hgdispatch(['update', '-R', repopath, '-r', rev])
def statuses(req, ms_code): """JSON work horse for the about() view. @see: about """ try: ms = Milestone.objects.get(code=ms_code) except: return HttpResponse('no milestone found for %s' % ms_code) sos_vals = _signoffs(ms).values_list('id','push__id', 'locale__code') sos = dict(d[:2] for d in sos_vals) loc2push = dict((d[2], d[1]) for d in sos_vals) locales = sorted(d[2] for d in sos_vals) allpushes = sos.values() def runs2dict(rs, prefix=''): fields = [prefix + f for f in ['locale__code']+Run.dfields] dcs = Run.to_class_string(runs.values(*fields), prefix) return dict((d[prefix+'locale__code'], {'class': cls, 'val': strval}) for d, cls, strval in dcs) # if the milestone is not shipped, let's check the active Runs, too active = {} if ms.status != 2: runs = Run.objects.filter(active__isnull=False) runs = runs.filter(tree__appversion__milestone=ms) active = runs2dict(runs) # if we have a previously shipped milestone, check the diffs previous = {} so_ids = dict((d[2], d[0]) for d in sos_vals) # current signoff ids pso = Milestone_Signoffs.objects.filter(milestone__id__lt=ms.id, milestone__appver__milestone=ms.id) pso = pso.order_by('milestone__id') for loc, sid, pid, mcode in pso.values_list('signoff__locale__code', 'signoff__id', 'signoff__push__id', 'milestone__code'): previous[loc] = {'signoff': sid, 'push': pid, 'stone': mcode} # whatever is in so_ids but not in previous is added added = [loc for loc in so_ids.iterkeys() if loc not in previous] removed = [] # not yet used # drop those from previous that we're shipping in the same rev for loc, details in previous.items(): if loc in so_ids: if so_ids[loc] <= details['signoff']: previous.pop(loc) else: removed.append(loc) allpushes += [d['push'] for d in previous.itervalues()] # get the most recent result for the signed off stamps cs = Changeset.objects.filter(pushes__id__in=sos.values()) cs_ids = list(cs.values_list('id',flat=True)) runs = Run_Revisions.objects.filter(changeset__id__in=cs_ids, run__tree__appversion__milestone=ms) latest = runs2dict(runs, 'run__') # get the snapshots from the sign-offs snaps = Snapshot.objects.filter(signoff__id__in=sos.keys(), test=0) runs = Run.objects.filter(id__in=list(snaps.values_list('tid',flat=True))) snapshots = runs2dict(runs) # get the shortrev's for all pushes, current sign-offs and previous pushes = Push.objects.annotate(tip=Max('changesets__id')) pushes = pushes.filter(id__in=allpushes) tips = dict(pushes.values_list('id', 'tip')) revmap = dict(Changeset.objects.filter(id__in=tips.values()).values_list('id', 'revision')) # generator to convert the various information to exhibit json def items(): for loc in locales: d = {'label': loc, 'revision': revmap[tips[loc2push[loc]]][:12]} if loc in active: d['active'] = active[loc]['val'] d['active_class'] = active[loc]['class'] if loc in latest: d['latest'] = latest[loc]['val'] d['latest_class'] = latest[loc]['class'] if loc in snapshots: d['snapshot'] = snapshots[loc]['val'] d['snapshot_class'] = snapshots[loc]['class'] if loc in previous: d['updatedFromRev'] = revmap[tips[previous[loc]['push']]][:12] d['updatedFrom'] = previous[loc]['stone'] elif loc in added: d['added'] = 'added' yield d return HttpResponse(simplejson.dumps({'items': list(items())}, indent=2), mimetype="text/plain")
def json_changesets(request): """Create a json l10n-changesets. This takes optional arguments of triples to link to files in repos specifying a special platform build. Used for multi-locale builds for fennec so far. multi_PLATFORM_repo: repository to load maemo-locales from multi_PLATFORM_rev: revision of file to load (default is usually fine) multi_PLATFORM_path: path inside the repo, say locales/maemo-locales XXX: For use in Firefox, this needs to learn about Japanese, still. """ if request.GET.has_key('ms'): av_or_m = Milestone.objects.get(code=request.GET['ms']) elif request.GET.has_key('av'): av_or_m = AppVersion.objects.get(code=request.GET['av']) else: return HttpResponse('No milestone or appversion given') sos = _signoffs(av_or_m).annotate(tip=Max('push__changesets__id')) tips = dict(sos.values_list('locale__code', 'tip')) revmap = dict(Changeset.objects.filter(id__in=tips.values()).values_list('id', 'revision')) platforms = re.split('[ ,]+', request.GET['platforms']) multis = defaultdict(dict) for k, v in request.GET.iteritems(): if not k.startswith('multi_'): continue plat, prop = k.split('_')[1:3] multis[plat][prop] = v extra_plats = defaultdict(list) try: from mercurial.hg import repository from mercurial.ui import ui as _ui except: _ui = None if _ui is not None: for plat in sorted(multis.keys()): try: props = multis[plat] path = os.path.join(settings.REPOSITORY_BASE, props['repo']) repo = repository(_ui(), path) ctx = repo[props['rev']] fctx = ctx.filectx(props['path']) locales = fctx.data().split() for loc in locales: extra_plats[loc].append(plat) except: pass tmpl = ''' "%(loc)s": { "revision": "%(rev)s", "platforms": ["%(plats)s"] }''' content = ('{\n' + ',\n'.join(tmpl % {'loc': l, 'rev': revmap[tips[l]][:12], 'plats': '", "'.join(platforms+extra_plats[l]) } for l in sorted(tips.keys()) ) + '\n}\n') r = HttpResponse(content, content_type='text/plain; charset=utf-8') r['Content-Disposition'] = 'inline; filename=l10n-changesets.json' return r