Esempio n. 1
0
    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('/')))

        if ms.status == Milestone.SHIPPED:
            sos = ms.signoffs
        else:
            sos = accepted_signoffs(id=ms.appver_id)
        sos=dict(sos.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])
Esempio n. 2
0
    def handle(self, *args, **options):
        rebase = options.get('rebase', False)
        update = options.get('update', False)
        all = options.get('all', False)
        if rebase:
            pull_args = ['--rebase']
        elif update:
            pull_args = ['-u']
        from life.models import Repository, Changeset
        from mercurial.dispatch import dispatch as hgdispatch
        import os.path
        from django.conf import settings

        def resolve(path):
            return os.path.join(settings.REPOSITORY_BASE, *path.split('/'))

        # check for last push helper file
        if not all and os.path.isfile(resolve('.latest_cs')):
            latest_cs = int(open(resolve('.latest_cs')).read())
            repos = Repository.objects.filter(changesets__id__gt=latest_cs).distinct()
        else:
            repos = Repository.objects.all()
        latest_cs = Changeset.objects.order_by('-pk')[0].id

        for name, url in repos.values_list('name','url'):
            repopath = str(resolve(name))
            if not os.path.isdir(os.path.join(repopath, '.hg')):
                # new repo, need to clone
                if os.path.isdir(repopath):
                    print "\n\nCannot clone %s, existing directory in the way\n\n" % name
                    continue
                _parent = os.path.dirname(repopath)
                if not os.path.isdir(_parent):
                    try:
                        os.makedirs(_parent)
                    except Exception, e:
                        print "\n\nFailed to prepare for clone, %s\n\n" % str(e)
                        continue
                hgdispatch(['clone', str(url), repopath])
            else:
                hgdispatch(['pull', '-R', repopath] + pull_args)