コード例 #1
0
ファイル: filehandler.py プロジェクト: dahool/vertaal
    def update_repo(self):
        from versioncontrol.manager import Manager, LockRepo
        from versioncontrol.models import BuildCache
        
        do_update = True
        try:
            b = BuildCache.objects.get(component=self.pofile.component,
                                       release=self.pofile.release)
        except:
            b = BuildCache.objects.create(component=self.pofile.component,
                                          release=self.pofile.release)
        else:
            updategap = getattr(settings,'FILE_UPDATE_GAP',900)
            diff = dt.now() - b.updated
            diffm = (diff.seconds/60)
            if b.is_locked or updategap == 0 or diff.seconds < updategap:
                logger.debug("No need to update. Last updated %s. %s minutes ago. Current lock %s." % (
                                                                            b.updated,
                                                                            diffm,
                                                                            b.is_locked))
                do_update = False
            else:
                logger.debug("Updating. Last updated %s. %s minutes ago." % (b.updated,
                                                                             diffm))
                b.lock()

        if do_update:
            try:
                man = Manager(self.pofile.release.project,
                                   self.pofile.release,
                                   self.pofile.component,
                                   self.pofile.language)            
                with LockRepo(self.pofile.release.project.slug,
                              self.pofile.release.slug,
                              self.pofile.component.slug,
                              self.pofile.language.code) as lock:        
                    man.refresh()
            except Exception, e:
                logger.error(e)
                raise
            finally:
コード例 #2
0
ファイル: refreshrepo.py プロジェクト: dahool/vertaal
    def handle(self, *args, **options):

        self.stdout.write('Started.\n')
        logger.info("Start")
        t_start = time.time() 

        potonly = options['potonly']
        
        BOT_USERNAME = getattr(settings, 'BOT_USERNAME', 'bot')
        BOT_USER = User.objects.get(username=BOT_USERNAME)

        projects = Project.objects.filter(enabled=True, read_only=False)
        
        b = None
        failedProjects = []
        try:
            for project in projects:
                teams = project.teams.all()
                for release in project.releases.filter(enabled=True, read_only=False):
                    for component in project.components.all():

                        try:
                            b = BuildCache.objects.get(component=component, release=release)
                            if b.is_locked:
                                logger.info("%s - %s is locked" % (release, component))
                                break
                        except:
                            b = BuildCache.objects.create(component=component,
                                                      release=release)
                        
                        b.lock()

                        try:
                            if not potonly:
                                for team in teams:
                                    if project.slug in failedProjects:
                                        self.stdout.write("Project %s skipped because previous fails\n" % project.slug)
                                        logger.info("Project %s skipped because previous fails" % project.slug)
                                        break
                                    
                                    logger.info("Refresh project %s, release %s, component %s, team %s" % (project.name,
                                                                                                          release.name,
                                                                                                          component.name,
                                                                                                          team.language.name))
                                    man = Manager(project, release, component, team.language, user=BOT_USER)
                                    
                                    try:
                                        logger.debug('Create lock')
                                        with LockRepo(project.slug,
                                                      release.slug,
                                                      component.slug,
                                                      team.language.code) as lock:
                                            logger.debug('Refresh')
                                            man.revert()
                                            man.refresh()
                                        logger.debug('Process Stats')
                                        man.update_stats(False)
                                    except Exception, e:
                                        failedProjects.append(project.slug)
                                        logger.error(e)
                                        traceback.print_exc(file=sys.stdout)
                                    finally:
                                        del man
                                    
                            if component.potlocation:
                                logger.info("Processing POT")
                                repo = POTUpdater(project, release, component)
                                try:
                                    repo.update_stats(True)
                                except Exception, e:
                                    logger.error(e)
                                    traceback.print_exc(file=sys.stdout)
                                finally:
                                    del repo
コード例 #3
0
ファイル: updatestats.py プロジェクト: dahool/vertaal
    def do_handle(self, *args, **options):
        global notification, potnotification
                
        self.stdout.write('Started.\n')
        logger.info("Start")
        t_start = time.time() 

        init_env()
        
        dorefresh = not options['statsonly']

        BOT_USERNAME = getattr(settings, 'BOT_USERNAME', 'bot')
        BOT_USER = User.objects.get(username=BOT_USERNAME)
            
        pre_save.connect(update_callback, sender=POFile)
        rsp = None
        projects = Project.objects.filter(enabled=True, read_only=False)
        b = None
        try:
            failedProjects = []
            for project in projects:
                teams = project.teams.all()
                for release in project.releases.filter(enabled=True, read_only=False):
                    for component in project.components.all():
                        b = None
                        try:
                            b = BuildCache.objects.get(component=component, release=release)
                            if b.is_locked:
                                logger.info("Project %s - Component %s - Release %s is LOCKED" % (project.name,
                                                                                                  component.name,
                                                                                                  release.name))
                                break
                            else:
                                b.lock()
                        except BuildCache.DoesNotExist:
                            b = BuildCache.objects.create(component=component,
                                                      release=release)
                            b.lock()
                        except Exception, e:
                            b = None
                            logger.error(e)
                            traceback.print_exc(file=sys.stdout)
                        if b:
                            for team in teams:
                                if project.slug in failedProjects:
                                    self.stdout.write("Project %s skipped because previous fails\n" % project.slug)
                                    logger.info("Project %s skipped because previous fails" % project.slug)
                                    break
                                                                    
                                logger.info("Update project %s, release %s, component %s, team %s" % (project.name,
                                                                                                      release.name,
                                                                                                      component.name,
                                                                                                      team.language.name))
                                man = Manager(project, release, component, team.language, user=BOT_USER)
                                try:
                                    with LockRepo(project.slug,
                                                  release.slug,
                                                  component.slug,
                                                  team.language.code) as lock:        
                                        if dorefresh:
                                            man.revert()
                                            b.setrev(man.refresh())
                                        man.update_stats(False)
                                except Exception, e:
                                    failedProjects.append(project.slug)
                                    logger.error(e)
                                    traceback.print_exc(file=sys.stdout)
                                finally:
                                    del man