Example #1
0
def main():
    Config = ConfigParser.SafeConfigParser()

    cfg_file = "make_pr.conf"
    if os.path.isfile(cfg_file):
        Config.readfp(open(cfg_file))
        for section in Config.sections():
            for option in Config.options(section):
                cfg[option] = Config.get(section, option)

    cfg["git_mirror_dir"] = os.path.expandvars(
        os.path.expanduser(cfg["gitdir"]))

    tracking = Tracking(dbpath=cfg["db_conn"])
    prev_max_pull_id = tracking.get_max_pull_id()

    print "prev_max_pull_id: %d" % prev_max_pull_id

    repo_obj = GitRepo(repo_path=cfg["git_mirror_dir"])
    all_pull_ids = repo_obj.get_all_pull_ids()

    pull_ids_to_work = [
        elem for elem in all_pull_ids if elem > prev_max_pull_id
    ]

    print "pull_ids_to_work: %s" % pull_ids_to_work

    newcount = 0
    for pull_id in pull_ids_to_work:
        message = make_gnats_message(pull_id=pull_id,
                                     cfg=cfg,
                                     pr_template=pr_template,
                                     repo_obj=repo_obj)
        fname = "pr%d.txt" % pull_id
        pr_file = open(fname, "w")
        pr_file.write(message)
        pr_file.close()
        print "Wrote out: %s" % fname
        # shell command to send-pr:
        #    yes s |send-pr -f x.out
        subprocess.check_call("yes s |send-pr -f %s" % fname, shell=True)
        tracking.record_pr_sent(pull_id)
        newcount += 1

    if newcount > 0:
        print "Finished successfully, made %d new prs!" % newcount
    else:
        print "Finished successfully, no new prs made"

    return 0
Example #2
0
    def scan_sloc(self, repo_name, repo_path, repo_owner, skip_path, suffix):
        db_session = self.create_db_session()
        row_repo = self.load_repository(db_session, repo_name)
        if row_repo == None:
            row_repo = Repository(name=repo_name, path=repo_path, owner=repo_owner)
            db_session.add(row_repo)

        gitrepo = GitRepo(repo_path + '/.git')
        existing_revision = [ _.hash for _ in row_repo.revisions]
        log.info(f'repo_name: {row_repo.name}')
        log.info(f'repo_path: {row_repo.path}')
        log.info(f'repo_owner: {row_repo.owner}')
        log.info(f'size of existing_revision: {len(existing_revision)}')

        analysis_cache = {}
        for commit in gitrepo.get_all_commit_id():
            date = datetime.datetime.fromtimestamp(int(commit.commit_time)).strftime('%Y-%m-%d %H:%M:%S')
            hash = str(commit.id)
            log.info(f'{date}, {hash}')

            if hash not in existing_revision:
                log.info('add revision')
                existing_revision.append(hash)
                row_revision = Revision(hash=hash,
                                        commit_time=datetime.datetime.fromtimestamp(int(commit.commit_time)))
                row_repo.revisions.append(row_revision)
                gitrepo.checkout_by(hash)

                row_revision.slocs = []
                for f in self.source_scanner(repo_path, skip_path, suffix):
                    fcontent = ''
                    with open(f, 'rb') as fh:
                        fcontent = fh.read()

                    if f in analysis_cache and analysis_cache[f][1] == fcontent:
                        analysis = analysis_cache[f][0]
                        # log.info('Use cache in analysis: %s', f)
                    else:
                        analysis = pygount.source_analysis(f, group='pygount', encoding='automatic')
                        analysis_cache[f] = (analysis, fcontent)
                        log.info(f'Analysis: {f}')

                    row_revision.slocs.append(Sloc(language=analysis.language,
                                                   filename=f, source_line=analysis.code,
                                                   empty_line=analysis.empty))
            db_session.commit()

        log.info('End of scaning.')
Example #3
0
def main():
    Config = ConfigParser.SafeConfigParser()

    cfg_file = "make_pr.conf"
    if os.path.isfile(cfg_file):
        Config.readfp(open(cfg_file))
        for section in Config.sections():
            for option in Config.options(section):
                cfg[option] = Config.get(section, option)

    cfg["git_mirror_dir"] = os.path.expandvars(os.path.expanduser(cfg["gitdir"]))

    tracking = Tracking(dbpath=cfg["db_conn"])
    prev_max_pull_id = tracking.get_max_pull_id()

    print "prev_max_pull_id: %d" % prev_max_pull_id

    repo_obj = GitRepo(repo_path=cfg["git_mirror_dir"])
    all_pull_ids = repo_obj.get_all_pull_ids()

    pull_ids_to_work = [elem for elem in all_pull_ids if elem > prev_max_pull_id]

    print "pull_ids_to_work: %s" % pull_ids_to_work

    newcount = 0
    for pull_id in pull_ids_to_work:
        message = make_gnats_message(pull_id=pull_id,
                cfg=cfg,
                pr_template=pr_template,
                repo_obj=repo_obj)
        fname = "pr%d.txt" % pull_id
        pr_file = open(fname, "w")
        pr_file.write(message)
        pr_file.close()
        print "Wrote out: %s" % fname
        # shell command to send-pr:
        #    yes s |send-pr -f x.out
        subprocess.check_call("yes s |send-pr -f %s" % fname, shell=True)
        tracking.record_pr_sent(pull_id)
        newcount += 1

    if newcount > 0:
        print "Finished successfully, made %d new prs!" % newcount
    else:
        print "Finished successfully, no new prs made"

    return 0
Example #4
0
 def __init__(self):
     """
     Constructor initializing instance variables
     """
     dict.__init__(self)
     self['name'] = ''
     self['defaults'] = {}
     self['branches'] = {}
     self['updates'] = {}
     self['target'] = '/tmp/gitgather-deployment'
     self.git = GitRepo()
Example #5
0
class Repo(dict):
    """Represents a repository/ module
    """

    def __init__(self):
        """
        Constructor initializing instance variables
        """
        dict.__init__(self)
        self['name'] = ''
        self['defaults'] = {}
        self['branches'] = {}
        self['updates'] = {}
        self['target'] = '/tmp/gitgather-deployment'
        self.git = GitRepo()

    def add_branches(self, branches, deployment_settings):
        """
        Add branches to our Repo object
        """
        for branch, _branch_settings in branches.items():
            branch_name = str(branch)
            branch_settings = _branch_settings

            # REF
            if isinstance(_branch_settings, str) or isinstance(_branch_settings, float) or isinstance(_branch_settings, int):
                branch_settings = {'ref': str(_branch_settings)}
            if not isinstance(branch_settings.get('ref'), str):
                branch_settings['ref'] = str(branch_settings['ref'])

            if branch_name not in self['branches'].keys():
                self['branches'][branch_name] = branch_settings
            else:
                self['branches'][branch_name].update(branch_settings)

            # REPO
            if 'repo' not in self['branches'][branch_name].keys():
                self['branches'][branch_name]['repo'] = self.get('defaults').get('repo', self['name'])

            # URL
            if 'url' not in self['branches'][branch_name].keys():
                url = self.get('defaults').get('url', deployment_settings.get('defaults', {}).get('url'))
                if url is None:
                    base_url = self['branches'][branch_name].get('base_url', self.get('defaults').get(
                        'base_url', deployment_settings.get('defaults', {}).get('base_url')))
                    url = '{}/{}'.format(base_url, self['branches'][branch_name]['repo'])

                self['branches'][branch_name]['url'] = url

    def sync(self, local_branch, remote_branch, root=''):
        """
        Sync/ update/ deploy a repository
        """
        src_path = '{}/{}'.format(self.git.get_path(), root)
        dst_path = '{}/{}/{}/'.format(self.get('target'), local_branch, self.get('name'))

        if not os.path.isdir(dst_path):
            os.makedirs(dst_path)
        if not src_path.endswith('/'):
            src_path += '/'
        if not dst_path.endswith('/'):
            dst_path += '/'

        self.git.checkout(remote_branch)

        print(rsync('--verbose', '--archive', '--checksum', '--delete', '--exclude=.git/', src_path, dst_path))  # TODO