Example #1
0
 def run(self):
     git = self.repo.git
     #git.add('Sheet_4_(d)_Full_Data_data.csv')
     #git.add('foph_covid19_data_converted_unix.csv')
     #git.add('last_update.txt')
     git.add('data/*')
     commit_message = "Data updated: "
     self.repo.index.commit(commit_message)
     git.push()
Example #2
0
def publish(output=ABS_OUTPUT_PATH):
    """ Publishes the current master branch to GH Pages """
    src = git.SOURCE_BRANCH
    live = git.DEPLOY_BRANCH
    git.change_branch(live)
    git.merge(src)
    generate('./')
    com_stat = git.commit_all()
    if com_stat:
        git.push(live)
    git.change_branch(src)
Example #3
0
def publish(output = ABS_OUTPUT_PATH):
    """ Publishes the current master branch to GH Pages """
    src = git.SOURCE_BRANCH
    live = git.DEPLOY_BRANCH
    git.change_branch(live)
    git.merge(src)
    generate('./')
    com_stat = git.commit_all()
    if com_stat:
        git.push(live)
    git.change_branch(src)
Example #4
0
    def mergeShadow(self):
        print "Merging Shadow"
        git = self.shadow  

        #checkout a copy of the wiki branch
        print "Checkout %s" % (self.vcs.get("branch"))
        self.checkoutBranch(self.vcs.get("branch"),repo=self.shadow)
        self.shadow.active_branch.pull()
        #switch back to master
        print "Checkout %s" % (self.vcs.get("shadow_branch"))
        self.checkoutBranch(self.vcs.get("shadow_branch"),repo=self.shadow)
        self.shadow.active_branch.pull()
        git.merge(self.vcs.get("branch"),self.vcs.get("shadow_master"))
        git.push() 
Example #5
0
    def mergeShadow(self):
        print "Merging Shadow"
        git = self.shadow

        #checkout a copy of the wiki branch
        print "Checkout %s" % (self.vcs.get("branch"))
        self.checkoutBranch(self.vcs.get("branch"), repo=self.shadow)
        self.shadow.active_branch.pull()
        #switch back to master
        print "Checkout %s" % (self.vcs.get("shadow_branch"))
        self.checkoutBranch(self.vcs.get("shadow_branch"), repo=self.shadow)
        self.shadow.active_branch.pull()
        git.merge(self.vcs.get("branch"), self.vcs.get("shadow_master"))
        git.push()
Example #6
0
def cherry_pick_real(git, branches, frm, to):
    git.checkout("master")
    git.pull()
    for br in branches:
        print(f"switching to {br}...")
        git.checkout(br)
        print(f"pulling from remote repo...")
        git.pull()
        print(f"cherry picking {frm}..{to}...")
        git.cherry_pick(f"{frm}..{to}")
        print(f"pushing to remote repo...")
        git.push()
        print(f"switching to master...")
        git.checkout("master")
Example #7
0
def push(repo_dir):
    branches = c.read_value('repository.enabled_branches')
    preview_push_info = git.push(repo_dir, remote="origin", branches=branches, dry_run=True)
    print "If you push, you'd be pushing: "
    _display_push_info(preview_push_info)
    if not util.ask_yn('Do you wish to push?'):
        return None
    for i in range(5):
        try:
            rv = git.push(repo_dir, remote="origin", branches=branches, dry_run=False)
            util.write_json(push_info_file, rv)
            print "Push attempt %d worked" % int(i+1)
            return rv
        except:
            print "Push attempt %d failed" % int(i+1)
    raise git.PushFailure("remote %s branches %s" % (remote, util.e_join(branches)))
Example #8
0
    def put(self):
        """action sent from js. Does all the work!"""

        # get current directory (to return later)
        #might not be needed
        cwd = os.getcwd()

        try:
            # make connection to git remote server
            git = git_cnxn()

            # obtain filename and msg for commit
            data = json.loads(self.request.body.decode('utf-8'))
            filename = urllib.parse.unquote(data['filename'])
            msg = data['msg']
            add_all = data['add_all']
            pull = data['pull']
            if pull:
                git.pull()
                self.write({
                    'status':
                    200,
                    'statusText':
                    ('Success!  '
                     'Pulled from {} everything up to date!'.format(git.url))
                })
            else:
                git.pull()
                git.add(filename, add_all)
                git.commit(msg)
                git.push()
                #git_pr()
                # close connection
                self.write({
                    'status':
                    200,
                    'statusText':
                    ('Success!  '
                     'Changes to {} captured on branch {} at {}'.format(
                         filename, git.branch_nm, git.url))
                })

            # return to directory
            os.chdir(cwd)
        except ErrorPrintToJupyter as e:
            self.error_and_return(cwd, str(e).replace('\n', '</br> '))
Example #9
0
def git_sync():
  
  branch_name = git.branch_name()

  if git.is_dirty():
    print_color('fatal: Can\'t publish a dirty directory.', colors.FAIL)
    quit()

  if git.has_untracked():
    print_color('fatal: There are untracked files.', colors.FAIL)
    quit()

  git.pull(branch_name)

  if git.is_dirty():
    print_color('Fix merge conflicts.', colors.FAIL)
    quit()

  git.push(branch_name)
Example #10
0
  def txn(branch):
    
    # git ignore everything except hostery file and gitignore.
    command('git rm --cached . -r', verbose=True)
    git_ignore = open('.gitignore', 'w')
    git_ignore.write('*\n!.gitignore\n!%s'%HOSTERY_FILE)
    git_ignore.close()
    git.add('.gitignore')

    # make hostery file
    hostery_file = open(HOSTERY_FILE, 'w')
    hostery_file.write(json.dumps({}))
    hostery_file.close()

    # add, commit, push.
    git.add(HOSTERY_FILE)
    command('git status', multiline=True, verbose=True)
    git.commit('hostery init')
    git.push(branch)
Example #11
0
def run(force):
    current_branch = git_current_branch.get()
    if current_branch == "master":
        sys.stdout.write("Current branch is `master`. This is not allowed. Quitting....\n")
        return

    result = git.push(current_branch, force)
    if result.stdout:
        sys.stdout.write(result.stdout)
    if result.stderr:
        sys.stdout.write(result.stderr)
Example #12
0
def merge(repo_dir, gaia_url, branch_to, branch_from):
    git.delete_gaia(repo_dir)
    t = util.time_start()
    if os.path.exists(repo_dir):
        print "Updating Gaia"
        git.update_gaia(repo_dir, gaia_url)
        print "Updated Gaia in %0.2f seconds" % util.time_end(t)
    else:
        print "Creating Gaia"
        git.create_gaia(repo_dir, gaia_url)  # This is sadly broken
        print "Created Gaia in %0.2f seconds" % util.time_end(t)

    print "Merging %s into branch %s" % (branch_from, branch_to)
    if not branch_to in git.branches(repo_dir):
        print >> sys.stderr, "Asking to merge into a branch that doesn't exist (%s)" % branch_to
        return None
    if not branch_from in git.branches(repo_dir):
        print >> sys.stderr, "Asking to merge from a branch that doesn't exist (%s)" % branch_from
        return None

    git.checkout(repo_dir, branch_to)
    start_commit = git.get_rev(repo_dir)
    git.merge(repo_dir, branch_from, strategy="recursive")
    end_commit = git.get_rev(repo_dir)
    print "Merge range is %s..%s" % (start_commit[:7], end_commit[:7])
    print git.log(repo_dir, "%s..%s" % (start_commit, end_commit), pretty="oneline")
    print "Dry Run push"
    git.push(repo_dir, remote="origin", branches=[branch_to], dry_run=True)
    info = git.push(repo_dir, remote="origin", branches=[branch_to])
    print "Would be pusing to %s" % info["url"]
    for branch in info["branches"].keys():
        s, e = info["branches"][branch]
        print "  %s: %s..%s" % (branch, s, e)
    if util.ask_yn("Push for realises?"):
        info = git.push(repo_dir, remote="origin", branches=[branch_to], dry_run=False)
        print "Pushed to %s" % info["url"]
        for branch in info["branches"].keys():
            s, e = info["branches"][branch]
            print "  %s: %s..%s" % (branch, s, e)
        comment(repo_dir, branch_to, "%s..%s" % (start_commit, end_commit))
Example #13
0
  def write_txn(branch):

    if sync:
      git.pull(branch)

    hostery_file = open(HOSTERY_FILE, 'r')
    all_data = json.loads(hostery_file.read())
    all_data.update(data)
    hostery_file.close()

    hostery_file = open(HOSTERY_FILE, 'w')
    hostery_file.write(json.dumps(all_data, indent=2))
    hostery_file.close()

    git.add(HOSTERY_FILE)

    # command('git status', verbose=True)

    git.commit('hostery mark')

    if sync:
      git.push(branch)

    return all_data
Example #14
0
	def push(self, what):
		if type(what) is list:
			for w in what:
				p=w.split(':')
				git.push(p[0], p[1], self.stdout)
		elif ':' in what:
			p=what.split(':')
			git.push(p[0], p[1], self.stdout)
		elif what in self.config['git']['push']:
			for key, val in self.config['git']['push'][what].iteritems():
				git.push(key, val, self.stdout)
		else:
			print 'we do not know what you are trying to do here...'
    def _sync(self, remote):
        """
        Pushes all normal branches from a source repo to gerrit.

        @param remote - gerrit.Remote object

        """
        # Only sync if source repo is provided.
        if not self.source:
            return

        # Only sync if heads and/or tags are specified
        if not self.heads and not self.tags:
            return

        msg = "Project %s: syncing with repo %s." % (self.name, self.source)
        logger.info(msg)
        print msg

        repo_dir = '~/tmp'
        repo_dir = os.path.expanduser(repo_dir)
        repo_dir = os.path.abspath(repo_dir)

        # Make Empty directory - We want this to stop and fail on OSError
        if not os.path.isdir(repo_dir):
            os.makedirs(repo_dir)
            logger.debug(
                "Project %s: Created directory %s" % (self.name, repo_dir)
            )

        # Save the current working directory
        old_cwd = os.getcwd()

        try:
            # Change cwd to that repo
            os.chdir(repo_dir)

            uuid_dir = str(uuid4())
            repo_dir = os.path.join(repo_dir, uuid_dir)

            # Do a git clone --bare <source_repo>
            git.clone(self.source, name=uuid_dir, bare=True)

            # Change to bare cloned directory
            os.chdir(uuid_dir)

            # Add remote named gerrit
            ssh_url = 'ssh://%s@%s:%s/%s' % (
                remote.username,
                remote.host,
                remote.port,
                self.name
            )
            git.add_remote('gerrit', ssh_url)

            # Push heads
            if self.heads:
                kwargs = {'all_': True}
                if self.force:
                    kwargs['force'] = True
                git.push('gerrit', **kwargs)

            # Push tags
            if self.tags:
                kwargs = {'tags': True}
                if self.force:
                    kwargs['force'] = True
                git.push('gerrit', **kwargs)

            ref_kwargs = self.ref_kwargs()

            # Grab origin refs
            origin_refset = git.remote_refs('origin', **ref_kwargs)

            # Grab gerrit refs
            gerrit_refset = git.remote_refs('gerrit', **ref_kwargs)

            # Find refs that should be removed.
            prune_refset = gerrit_refset - origin_refset
            if self.preserve_prefix == PRESERVE_ALL_BRANCHES:
                msg = "Project %s: Preserving all refs" % self.name
                logger.debug(msg)
                print msg
                prune_refset = set([])
            elif not self.preserve_prefix is None:
                msg = "Project %s: Preserving refs with prefixes of %s" \
                      % (self.name, self.preserve_prefix)
                logger.debug(msg)
                print msg
                heads_prefix = "refs/heads/%s" % self.preserve_prefix
                tags_prefix = "refs/tags/%s" % self.preserve_prefix
                keep = lambda ref: not ref.startswith(heads_prefix) and \
                    not ref.startswith(tags_prefix)
                prune_refset = filter(keep, prune_refset)

            # Prefix each ref in refset with ':' to delete
            colonize = lambda ref: ':%s' % ref
            prune_refset = map(colonize, prune_refset)

            # Remove branches no longer needed
            if prune_refset:
                git.push('gerrit', refspecs=prune_refset)

        finally:
            # Change to old current working directory
            os.chdir(old_cwd)

            # Attempt to clean up created directory
            shutil.rmtree(repo_dir)
    def _config(self, remote, conf, groups):
        """
        Builds the groups file and project.config file for a project.

        @param remote - gerrit.Remote object
        @param conf - Dict containing git config information
        @param groups - List of groups

        """
        if not self.config:
            return

        msg = "Project %s: Configuring." % self.name
        logger.info(msg)
        print msg

        repo_dir = '~/tmp'
        repo_dir = os.path.expanduser(repo_dir)
        repo_dir = os.path.abspath(repo_dir)

        uuid_dir = str(uuid4())
        repo_dir = os.path.join(repo_dir, uuid_dir)

        # Make Empty directory - We want this to stop and fail on OSError
        logger.debug(
            "Project %s: Creating directory %s" % (self.name, repo_dir)
        )
        os.makedirs(repo_dir)

        # Save the current working directory
        old_cwd = os.getcwd()

        origin = 'origin'

        try:
            # Change cwd to that repo
            os.chdir(repo_dir)

            # Git init empty directory
            git.init()

            # Add remote origin
            ssh_url = 'ssh://%s@%s:%s/%s' % (
                remote.username,
                remote.host,
                remote.port,
                self.name
            )

            git.add_remote(origin, ssh_url)

            # Fetch refs/meta/config for project
            refspec = 'refs/meta/config:refs/remotes/origin/meta/config'
            git.fetch(origin, refspec)

            # Checkout refs/meta/config
            git.checkout_branch('meta/config')

            # Get md5 of existing config
            _file = os.path.join(repo_dir, 'project.config')
            contents = ''
            try:
                with open(_file, 'r') as f:
                    contents = f.read()
            except IOError:
                pass
            existing_md5 = hashlib.md5(contents).hexdigest()

            # Get md5 of new config
            with open(self.config, 'r') as f:
                contents = f.read()
            new_md5 = hashlib.md5(contents).hexdigest()

            msg = "Project %s: Md5 comparision\n%s\n%s"
            msg = msg % (self.name, existing_md5, new_md5)
            logger.debug(msg)
            print msg

            # Only alter if checksums do not match
            if existing_md5 != new_md5:

                logger.debug(
                    "Project %s: config md5's are different." % self.name
                )

                # Update project.config file
                _file = os.path.join(repo_dir, 'project.config')
                with open(_file, 'w') as f:
                    f.write(contents)

                # Update groups file
                group_contents = groups_file_contents(groups)
                _file = os.path.join(repo_dir, 'groups')
                with open(_file, 'w') as f:
                    f.write(group_contents)

                # Git config user.email
                git.set_config('user.email', conf['git-config']['email'])

                # Git config user.name
                git.set_config('user.name', conf['git-config']['name'])

                # Add groups and project.config
                git.add(['groups', 'project.config'])

                # Git commit
                git.commit(message='Setting up %s' % self.name)

                # Git push
                git.push(origin, refspecs='meta/config:refs/meta/config')
                logger.info("Project %s: pushed configuration." % self.name)

            else:
                msg = "Project %s: config unchanged." % self.name
                logger.info(msg)
                print msg

        finally:
            # Change to old current working directory
            os.chdir(old_cwd)

            # Attempt to clean up created directory
            shutil.rmtree(repo_dir)
Example #17
0
		except:
			git.checkout(b=monit_node)
			
		#git.checkout("HEAD", b=monit_node)

		filename = monit_node + "/" + f['applicationsolution_name'] + "_" + \
				f['url'].replace("://", "_").replace("/","_") + ".conf"
		filepath = telegraf_dir + "/" + filename
		print(filename)
		with open(filepath, 'w') as fi:
			fi.write("[[inputs.url_monitor]]\n" + \
					"\tapp = " + '"' +  f['applicationsolution_name'] + '"\n' + \
					"\taddress = " + '"' + f['url'] + '"\n' + \
					"\tresponse_timeout = \"" + response_timeout + '"\n' + \
					"\tmethod = " + '"' + f['method'] + '"\n' + \
					"\trequire_str = " + "'" + f['require_str'] + "'\n" + \
					"\trequire_code = " + "'" + f['require_code'] + "'\n" + \
					"\tfailed_count = " + f['failed_count'] + '\n' + \
					"\tfailed_timeout = " + f['timeout'] + '\n' + \
					"\tfollow_redirects = " + follow_redirects + '\n' + \
					"\tbody = " + "'" + f['body'] + "'\n" + \
					"\tinsecure_skip_verify = " + insecure_skip_verify + '\n' + \
					"\t[inputs.url_monitor.headers]\n\t\t" + h_str + '\n')

		git.add(filename)
		try:
			git.commit(m=filename)
		except:
			print(git.status())
		git.push("origin", monit_node)
    text = readme.read()
    for sub in subs:
        (find, replace) = sub
        text = re.sub(find, replace, text)
    readme.seek(0)
    readme.write(text)

print(INFO + "Adding git changes." + ENDC)
git.add(readme_file)
if not git.status("-s"):
    print(INFO + "No changes. Exiting." + ENDC)
    sys.exit(0)
git.commit('-m',
           f'Update {readme_file} examples to reflect new version {version}')

push_failures = 0
while True:
    try:
        print(INFO + "Pushing updated README." + ENDC)
        git.push()
        break
    except GitCommandError:
        push_failures += 1
        if push_failures <= 5:
            print(NOTICE + "Failed to push. Going to pull and try again." +
                  ENDC)
            git.pull(rebase=True)
        else:
            print(ERROR + "Failed to push again. Giving up." + ENDC)
            raise
Example #19
0
        print('Exiting... with local changes still in place')
        exit()

    print(f'Building a new docker image from {base_dockerfile} in {build_dir}')
    os.chdir(build_dir)
    call(["docker", "build", '-t', tag, '-f', base_dockerfile, '.'])

    print(f'Finished building, tagging {tag} as {remote_tag}')
    call(["docker", "tag", tag, remote_tag])

    print(f'Tagged {remote_tag}, pushing to docker hub')
    call(["docker", 'push', remote_tag])

    print(f'Comitting changes and pushing to {tag}')
    git.commit('-m', f'Committing scripted changes')
    git.push('-v', 'origin', tag)

    head = f'{GITUSERNAME}:{tag}'
    print(f'Opening PR to merge "{head}" into "{SRCBRANCH}"')

    try:
        g = Github(GITHUBTOKEN)
        org = g.get_organization(ORGNAME)
        repo_instance = org.get_repo(REPONAME)

        repo_instance.create_pull(
            title=f'Point Dockerfile.test at new base image {remote_tag}',
            body=f'Automatically created PR that points the tester dockerfile at the new base image that was created from update_base_image.py',
            base=SRCBRANCH,
            head=head
        )
Example #20
0
    pass

# base = "master"
# head = f'ahonnecke:{new_branch}'
# print(f'Opening PR to merge "{head}" into "{base}"')
# web_repo = org.get_repo('web')
# web_repo.create_pull(
#     title=f'Warm up cache',
#     body="Scripted update to warm up the CI cache",
#     base=base,
#     head=head
# )

num = input("How many times brah?: ")

for x in range(0, int(num)):
    print(f'Pushing {x}...')
    with open(cache_warmer_filename, "a") as cache_warmer_file:
        cache_warmer_file.write(f'# {x} units warmer\n')
        cache_warmer_file.close()

    web_repo.index.add([cache_warmer_filename])
    git.commit('-m', f'warming cache')
    git.push('-v', 'origin', new_branch)

    # web_repo.index.add([cache_warmer_filename])
    # web_repo.git.commit('-m', 'warming circleCI')
    # web_repo.remotes.origin.push(refspec=f'{branch}:{branch}')
    print(f'Sleeping {delay} seconds after iteration {x}...')
    sleep(delay)
Example #21
0
    def _sync(self, remote):
        """
        Pushes all normal branches from a source repo to gerrit.

        @param remote - gerrit.Remote object

        """
        # Only sync if source repo is provided.
        if not self.source:
            return

        # Only sync if heads and/or tags are specified
        if not self.heads and not self.tags:
            return

        msg = "Project %s: syncing with repo %s." % (self.name, self.source)
        logger.info(msg)
        print msg

        repo_dir = '~/tmp'
        repo_dir = os.path.expanduser(repo_dir)
        repo_dir = os.path.abspath(repo_dir)

        # Make Empty directory - We want this to stop and fail on OSError
        if not os.path.isdir(repo_dir):
            os.makedirs(repo_dir)
            logger.debug("Project %s: Created directory %s" %
                         (self.name, repo_dir))

        # Save the current working directory
        old_cwd = os.getcwd()

        try:
            # Change cwd to that repo
            os.chdir(repo_dir)

            uuid_dir = str(uuid4())
            repo_dir = os.path.join(repo_dir, uuid_dir)

            # Do a git clone --bare <source_repo>
            git.clone(self.source, name=uuid_dir, bare=True)

            # Change to bare cloned directory
            os.chdir(uuid_dir)

            # Add remote named gerrit
            ssh_url = 'ssh://%s@%s:%s/%s' % (remote.username, remote.host,
                                             remote.port, self.name)
            git.add_remote('gerrit', ssh_url)

            # Push heads
            if self.heads:
                kwargs = {'all_': True}
                if self.force:
                    kwargs['force'] = True
                git.push('gerrit', **kwargs)

            # Push tags
            if self.tags:
                kwargs = {'tags': True}
                if self.force:
                    kwargs['force'] = True
                git.push('gerrit', **kwargs)

            ref_kwargs = self.ref_kwargs()

            # Grab origin refs
            origin_refset = git.remote_refs('origin', **ref_kwargs)

            # Grab gerrit refs
            gerrit_refset = git.remote_refs('gerrit', **ref_kwargs)

            # Find refs that should be removed.
            prune_refset = gerrit_refset - origin_refset
            if self.preserve_prefix:
                msg = "Project %s: Preserving refs with prefixes of %s" \
                      % (self.name, self.preserve_prefix)
                logger.debug(msg)
                print msg
                heads_prefix = "refs/heads/%s" % self.preserve_prefix
                tags_prefix = "refs/tags/%s" % self.preserve_prefix
                keep = lambda ref: not ref.startswith(heads_prefix) and \
                    not ref.startswith(tags_prefix)
                prune_refset = filter(keep, prune_refset)

            # Prefix each ref in refset with ':' to delete
            colonize = lambda ref: ':%s' % ref
            prune_refset = map(colonize, prune_refset)

            # Remove branches no longer needed
            if prune_refset:
                git.push('gerrit', refspecs=prune_refset)

        finally:
            # Change to old current working directory
            os.chdir(old_cwd)

            # Attempt to clean up created directory
            shutil.rmtree(repo_dir)
Example #22
0
    def _mirror_one(self, branch, input_work_dir, output_reference):
        self.debug('*********** start work for branch %s -> %s' % (
            branch,
            self.output_branch_name(branch),
        ))

        if not self._need_to_mirror(branch, input_work_dir, output_reference):
            return True

        with tempdir.tempdir() as tmpdir:
            output_work_dir = os.path.join(tmpdir, 'output')
            start_commit, new_branch = self._prepare_output_git(
                branch, input_work_dir, output_work_dir, output_reference)

            commits = self._find_commits(branch, start_commit, input_work_dir,
                                         output_work_dir)

            os.chdir(tmpdir)

            committed_anything = False

            last_failure = None

            try:
                # In this case we're already done, the loop below would be skipped
                # completely, but we can't even calculate the (unnecessary)
                # prep_prev_commit and similar, nor do we really have to check out
                # the code to generate nothing. However, if it's a new branch we
                # may have to push it out, so go through the "finally:" segment of
                # the code (and hence have the return statement within the "try:"
                # block.
                # The output tree is correct since self._prepare_output_git() will
                # leave it at the commit it wanted to start generating from (even
                # if there's nothing to generate, it doesn't consider that.)
                if len(commits) == 0:
                    return True

                prep_prev_commit = Commit(
                    git.rev_parse(commits[0].tree_id + '^',
                                  tree=input_work_dir), input_work_dir)
                self._checkout(prep_prev_commit.tree_id, input_work_dir)
                submodules = self._submodule_status(input_work_dir)

                for commit in commits:
                    prev_commit = prep_prev_commit
                    prep_prev_commit = commit
                    if not self._create_output(branch, commit, input_work_dir,
                                               output_work_dir, start_commit,
                                               new_branch):
                        if last_failure is None:
                            last_failure = commit
                        continue

                    if last_failure:
                        last_failure_shortlog = git.shortlog(
                            last_failure, commit)
                    else:
                        last_failure_shortlog = None

                    git.add('.', tree=output_work_dir)

                    prev_submodules = submodules
                    submodules = self._submodule_status(input_work_dir)

                    if self.is_modified(tree=output_work_dir):
                        parents = [git.rev_parse('HEAD', tree=output_work_dir)]
                        tree_id = git.write_tree(tree=output_work_dir)
                        for s in submodules:
                            if not s in prev_submodules:
                                continue
                            if prev_submodules[s] != submodules[s]:
                                parents += self._handle_submodule(
                                    branch, prev_commit, s, prev_submodules[s],
                                    submodules[s], input_work_dir,
                                    output_work_dir, start_commit, new_branch)
                        self._commit_modified(commit, input_work_dir,
                                              output_work_dir,
                                              last_failure_shortlog, tree_id,
                                              parents)
                        committed_anything = True
                    elif new_branch and self.always_commit_new_branch:
                        self._commit_new_branch(commit, output_work_dir)
                        committed_anything = True
                        new_branch = False

                    last_failure = None
                    git.set_note(self.notes_branch,
                                 'HEAD',
                                 commit.tree_id,
                                 tree=output_work_dir,
                                 env=self._commit_env())
            except Abort:
                return False
            finally:
                # if necessary, push to the server from the output_work_dir
                git.set_origin_url(self._output_tree, gitdir=output_work_dir)
                if committed_anything or new_branch:
                    git.push(opts=[
                        '-q', 'origin',
                        'HEAD:' + self.output_branch_name(branch)
                    ],
                             tree=output_work_dir)
                git.push(opts=[
                    '-q', '-f', 'origin', 'refs/notes/' + self.notes_branch
                ],
                         tree=output_work_dir)

            return True
Example #23
0
from apps import app
from git import verify_new_branch, clone, push, merge
from k8s import apply_cluster, verify_existed
from efs import efs_create_directory
import sys

emissor = sys.argv[1]
ambiente = sys.argv[2]
new_branch = sys.argv[3]


def create_object(emissor, ambiente, new_branch):
    app_object = app(name_app = emissor, ambiente = ambiente, new_branch = new_branch)
    return app_object

if __name__ == "__main__":
    verify_new_branch(new_branch, ambiente)
    clone(new_branch, ambiente)
    app_object = create_object(emissor, ambiente, new_branch)
    NEW_COMMIT = verify_existed(app_object.name_deployment, app_object.name_ingress, app_object.name_app, app_object.ambiente)
    NEW_PUSH = push(NEW_COMMIT, app_object.ambiente, app_object.new_branch)
    merge(app_object.ambiente, NEW_PUSH, app_object.new_branch)
    efs_create_directory(app_object.name_app, app_object.ambiente)
    apply_cluster(app_object.name_app, app_object.name_deployment, app_object.name_ingress, app_object.ambiente)
Example #24
0
    def _config(self, remote, conf, groups):
        """
        Builds the groups file and project.config file for a project.

        @param remote - gerrit.Remote object
        @param conf - Dict containing git config information
        @param groups - List of groups

        """
        if not self.config:
            return

        msg = "Project %s: Configuring." % self.name
        logger.info(msg)
        print msg

        repo_dir = '~/tmp'
        repo_dir = os.path.expanduser(repo_dir)
        repo_dir = os.path.abspath(repo_dir)

        uuid_dir = str(uuid4())
        repo_dir = os.path.join(repo_dir, uuid_dir)

        # Make Empty directory - We want this to stop and fail on OSError
        logger.debug("Project %s: Creating directory %s" %
                     (self.name, repo_dir))
        os.makedirs(repo_dir)

        # Save the current working directory
        old_cwd = os.getcwd()

        origin = 'origin'

        try:
            # Change cwd to that repo
            os.chdir(repo_dir)

            # Git init empty directory
            git.init()

            # Add remote origin
            ssh_url = 'ssh://%s@%s:%s/%s' % (remote.username, remote.host,
                                             remote.port, self.name)

            git.add_remote(origin, ssh_url)

            # Fetch refs/meta/config for project
            refspec = 'refs/meta/config:refs/remotes/origin/meta/config'
            git.fetch(origin, refspec)

            # Checkout refs/meta/config
            git.checkout_branch('meta/config')

            # Get md5 of existing config
            _file = os.path.join(repo_dir, 'project.config')
            contents = ''
            try:
                with open(_file, 'r') as f:
                    contents = f.read()
            except IOError:
                pass
            existing_md5 = hashlib.md5(contents).hexdigest()

            # Get md5 of new config
            with open(self.config, 'r') as f:
                contents = f.read()
            new_md5 = hashlib.md5(contents).hexdigest()

            msg = "Project %s: Md5 comparision\n%s\n%s"
            msg = msg % (self.name, existing_md5, new_md5)
            logger.debug(msg)
            print msg

            # Only alter if checksums do not match
            if existing_md5 != new_md5:

                logger.debug("Project %s: config md5's are different." %
                             self.name)

                # Update project.config file
                _file = os.path.join(repo_dir, 'project.config')
                with open(_file, 'w') as f:
                    f.write(contents)

                # Update groups file
                group_contents = groups_file_contents(groups)
                _file = os.path.join(repo_dir, 'groups')
                with open(_file, 'w') as f:
                    f.write(group_contents)

                # Git config user.email
                git.set_config('user.email', conf['git-config']['email'])

                # Git config user.name
                git.set_config('user.name', conf['git-config']['name'])

                # Add groups and project.config
                git.add(['groups', 'project.config'])

                # Git commit
                git.commit(message='Setting up %s' % self.name)

                # Git push
                git.push(origin, refspecs='meta/config:refs/meta/config')
                logger.info("Project %s: pushed configuration." % self.name)

            else:
                msg = "Project %s: config unchanged." % self.name
                logger.info(msg)
                print msg

        finally:
            # Change to old current working directory
            os.chdir(old_cwd)

            # Attempt to clean up created directory
            shutil.rmtree(repo_dir)