示例#1
0
    def sync_repos(self, sync_all=False):
        if sync_all:
            self.logger.debug('Going to sync all repos from scratch (sync_all=True)')
            for deployment_name, repolist in Helper.sorted_dict(self).items():
                for repo_name, repo in Helper.sorted_dict(repolist).items():
                    for branch_name, branch_settings in Helper.sorted_dict(repo.get('branches')).items():
                        pass  # TODO
        else:
            pending_updates = []
            for deployment_name, repolist in Helper.sorted_dict(self).items():
                for repo_name, repo in Helper.sorted_dict(repolist).items():
                    if repo.get('updates').get('updated_refs'):
                        pending_updates.append(repo.get('updates'))
            if pending_updates:
                for pending_update in pending_updates:
                    cache_name = pending_update.get('cache').name

                    for updated_ref in pending_update.get('updated_refs'):
                        repo_name = updated_ref.get('repo')
                        repo_url = updated_ref.get('url')
                        repo_ref = updated_ref.get('ref')

                        for deployment_name, repolist in Helper.sorted_dict(self).items():
                            for repo_name, repo in Helper.sorted_dict(repolist).items():
                                for branch_name, branch_settings in Helper.sorted_dict(repo.get('branches')).items():
                                    if repo_url == branch_settings.get('url') and \
                                       repo_ref == branch_settings.get('ref') and \
                                       cache_name == branch_settings.get('cache', repo.get('defaults').get('cache')):
                                        root = branch_settings.get('root', repo.get('defaults').get('root', ''))
                                        repo.sync(branch_name, repo_ref, root)
示例#2
0
    def update(self, repo):
        """
        Update the cache, e.g. the Git repository in the file system
        """
        self.repo = repo
        branches = self.repo.get('branches')
        changed_refs = []

        for branch_name, branch_settings in Helper.sorted_dict(branches).items():
            repo_path = '{}/{}'.format(self.path, branch_settings.get('repo'))
            repo['remotes'] = {'origin': {'url': branch_settings.get('url')}}

            # the following methods are idempotent, don't worry about their names
            self.repo.git.set_path(repo_path)
            self.repo.git.init()
            self.repo.git.add_remotes(repo['remotes'])

            self.logger.debug('Searching for updates of remote repo %s (ref: %s) in cache %s', self.repo.get('name'), branch_settings.get(
                'ref'), self.name)
            update_info = self.repo.git.update_ref(branch_settings.get('ref'), 'origin', branch_settings.get('repo'))
            if update_info.get('updated'):
                self.logger.info('Found updates of remote repo %s, scheduling repo deployment of ref %s', self.repo.get('name'),
                                 branch_settings.get('ref'))
                changed_refs.append(update_info)
        return changed_refs
示例#3
0
    def update(self, repo):
        """
        Update the cache, e.g. the Git repository in the file system
        """
        self.repo = repo
        branches = self.repo.get('branches')
        changed_refs = []

        for branch_name, branch_settings in list(
                Helper.sorted_dict(branches).items()):
            repo_path = '{}/{}'.format(self.path, branch_settings.get('repo'))
            repo['remotes'] = {'origin': {'url': branch_settings.get('url')}}

            # the following methods are idempotent, don't worry about their names
            self.repo.git.set_path(repo_path)
            self.repo.git.init()
            self.repo.git.add_remotes(repo['remotes'])

            self.logger.debug(
                'Searching for updates of remote repo %s (ref: %s) in cache %s',
                self.repo.get('name'), branch_settings.get('ref'), self.name)
            update_info = self.repo.git.update_ref(branch_settings.get('ref'),
                                                   'origin',
                                                   branch_settings.get('repo'))
            if update_info.get('updated'):
                self.logger.info(
                    'Found updates of remote repo %s, scheduling repo deployment of ref %s',
                    self.repo.get('name'), branch_settings.get('ref'))
                changed_refs.append(update_info)
        return changed_refs
示例#4
0
    def sync_repos(self, sync_all=False):
        if sync_all:
            self.logger.debug(
                'Going to sync all repos from scratch (sync_all=True)')
            for deployment_name, repolist in list(
                    Helper.sorted_dict(self).items()):
                for repo_name, repo in list(
                        Helper.sorted_dict(repolist).items()):
                    for branch_name, branch_settings in list(
                            Helper.sorted_dict(repo.get('branches')).items()):
                        pass  # TODO
        else:
            pending_updates = []
            for deployment_name, repolist in list(
                    Helper.sorted_dict(self).items()):
                for repo_name, repo in list(
                        Helper.sorted_dict(repolist).items()):
                    if repo.get('updates').get('updated_refs'):
                        pending_updates.append(repo.get('updates'))
            if pending_updates:
                for pending_update in pending_updates:
                    cache_name = pending_update.get('cache').name

                    for updated_ref in pending_update.get('updated_refs'):
                        repo_name = updated_ref.get('repo')
                        repo_url = updated_ref.get('url')
                        repo_ref = updated_ref.get('ref')

                        for deployment_name, repolist in list(
                                Helper.sorted_dict(self).items()):
                            for repo_name, repo in list(
                                    Helper.sorted_dict(repolist).items()):
                                for branch_name, branch_settings in list(
                                        Helper.sorted_dict(
                                            repo.get('branches')).items()):
                                    if repo_url == branch_settings.get('url') and \
                                       repo_ref == branch_settings.get('ref') and \
                                       cache_name == branch_settings.get('cache', repo.get('defaults').get('cache')):
                                        root = branch_settings.get(
                                            'root',
                                            repo.get('defaults').get(
                                                'root', ''))
                                        repo.sync(branch_name, repo_ref, root)