def setUp(self): self.powerline = mock.MagicMock() self.dirname = tempfile.mkdtemp() sh.cd(self.dirname) sh.hg("init", ".") self.segment = hg.Segment(self.powerline)
def setUp(self): self.powerline = mock.MagicMock() self.powerline.segment_conf.side_effect = dict_side_effect_fn({ ("vcs", "show_symbol"): False, }) self.dirname = tempfile.mkdtemp() sh.cd(self.dirname) sh.hg("init", ".") self.segment = hg.Segment(self.powerline, {})
def clone_locally(self, dst_dir): """clones the repo into dst_dir""" conf = self.configuration repo = conf.get('buildbot-configs', 'repo') cmd = ('clone', repo, dst_dir) log.debug('running sh {0}'.format(' '.join(cmd))) self.local_checkout_dir = dst_dir try: sh.hg('clone', repo, dst_dir) except sh.ErrorReturnCode as error: msg = 'clone failed' msg = '{0}: hg {1}'.format(msg, ' '.join(cmd)) msg = '{0} - error: {1}'.format(msg, error) log.debug(msg) raise BuildbotConfigsError('clone failed')
def push(self): """pushes local changes to the remote repository""" self._update_hgrc() try: # logging what is about to be pushed cmd = ('out', '-p') for line in hg(cmd, _cwd=self.local_checkout_dir): log.debug(line.strip()) # and now log the push command for line in hg('push', _cwd=self.local_checkout_dir): log.debug(line.strip()) except ErrorReturnCode as error: msg = 'push failed: {0}'.format(error) log.debug(msg) raise RepositoryError(msg)
def hg_push(url): """Push commits to repository, provided that we are already in the repo. """ val = hg("push", "--insecure", url) if val.exit_code != 0: raise ValueError ("Commit failed with status ", val) else: return val
def hg_push(url): """Push commits to repository, provided that we are already in the repo. """ val = hg("push", "--insecure", url) if val.exit_code != 0: raise ValueError("Commit failed with status ", val) else: return val
def commit(self, commit_message): """commit local changes""" try: cmd = ('commit', '-m', commit_message) for line in hg(cmd, _cwd=self.local_checkout_dir): log.debug(line.strip()) except ErrorReturnCode as error: msg = 'commit failed: {0}'.format(error) raise RepositoryError(msg)
def clone_repo(*, branch: str, repo_url: str, apps_folder: Path, template_repo_url: str, app_path: Path, app_group: str, hg: bool, local: bool, verbose: int, ): app_name, app_user, _, _ = parse_url(repo_url, apps_folder=apps_folder, verbose=verbose,) rename_cloned_repo = False if template_repo_url: template_app_name, template_app_user, _, _ = parse_url(template_repo_url, apps_folder=apps_folder, verbose=verbose,) repo_to_clone_url = template_repo_url if template_app_name != app_name: rename_cloned_repo = True else: repo_to_clone_url = repo_url if hg: sh.hg('clone', repo_to_clone_url, str(app_path)) else: sh.git.clone(repo_to_clone_url, str(app_path)) if branch != "master": branch_cmd = "git checkout -b " + '"' + branch + '"' ic(branch_cmd) os.system(branch_cmd) if not rename_cloned_repo: # when renaming a template repo, dont want to fork if its one of my repos git_fork_cmd = "hub fork" os.system(git_fork_cmd) else: rename_repo_at_app_path(app_path=app_path, app_group=app_group, local=local, hg=hg, old_name=template_app_name, new_name=app_name, verbose=verbose, )
def hgrepo(root): hglog = sh.hg('log', '-l', '1', template=HGLOG).split('\n', 5) branch = (os.environ.get('CIRCLE_BRANCH') or os.environ.get('TRAVIS_BRANCH', sh.hg('branch').strip())) remotes = [x.split(' = ') for x in sh.hg('paths')] return { 'head': { 'id': hglog[0], 'author_name': hglog[1], 'author_email': hglog[2], 'committer_name': hglog[3], 'committer_email': hglog[4], 'message': hglog[5].strip(), }, 'branch': branch, 'remotes': [{ 'name': remote[0], 'url': remote[1] } for remote in remotes] }
def tag(self, tag='default'): """tags a repository with tag, if tag is not provided, it will use tag_name function do determine the tag""" conf = self.configuration if tag == 'default': products = conf.get_list('common', 'staging_release') version = conf.get('common', 'version') tag = tag_name(version, products) try: cmd = ('tag', '-f', tag) for line in hg(cmd, _cwd=self.local_checkout_dir): log.debug(line.strip()) except ErrorReturnCode as error: msg = 'tag failed: {0}'.format(error) log.debug(msg) raise RepositoryError(msg)
def clone_locally(self, dst_dir, branch='default', clone_from='user'): """clones the repo into dst_dir""" conf = self.configuration repo = conf.get(self.name, 'mozilla_repo') if clone_from != 'mozilla': repo = conf.get(self.name, 'user_repo') cmd = ('clone', repo, dst_dir) log.debug('running sh {0}'.format(' '.join(cmd))) self.local_checkout_dir = dst_dir hg_cmd = ('clone', '-b', branch, repo, dst_dir) try: for line in hg(hg_cmd, _iter=True): log.debug(line.strip()) except ErrorReturnCode as error: msg = 'clone failed' msg = '{0}: hg {1}'.format(msg, ' '.join(cmd)) msg = '{0} - error: {1}'.format(msg, error) log.debug(msg) raise RepositoryError('clone failed')
def hg_clone(remote, local): val = hg("clone", "--insecure", remote, local) if val.exit_code != 0: raise ValueError ("Clone failed with status ", val) else: return val
def hg_clone(remote, local): val = hg("clone", "--insecure", remote, local) if val.exit_code != 0: raise ValueError("Clone failed with status ", val) else: return val
def _checkout_new_branch(self, branch): sh.hg("branch", branch)
def _add_and_commit(self, filename): sh.touch(filename) sh.hg("add", filename) sh.hg("commit", "-m", "add file " + filename)
mj = MasterJson(config, 'master_config.json.ini') mj.write('') bc = BuildbotConfigs(config) # url = config.get('locales', 'url') # locales = locales.get_shipped_locales(url) # print locales # bc.delete_user_repo() # bc.create_repo() tmp_dir = '/tmp/bc-conf' # shutil.rmtree(tmp_dir, ignore_errors=True) # bc.clone_locally('/tmp/bc-conf') bc.local_checkout_dir = tmp_dir #bc.prepare_for_staging() sh.hg('revert', '--all', _cwd=tmp_dir) replace_me = list() username = config.get('common', 'username') bug = config.get('common', 'tracking_bug') for repo in config.options('repositories'): src_repo = config.get(repo, 'src_repo_name') dst_repo = config.get(repo, 'dst_repo_name') src_repo = "{0}".format(src_repo) dst_repo = "{0}".format(dst_repo) a = (src_repo, dst_repo) replace_me.append(a) #fx_repo = 'users/stage-ffxbld/{0}'.format(repo) #user_repo = 'users/{0}_mozilla.com/{1}-{2}'.format(username, repo, bug) #a = (fx_repo, user_repo) #replace_me.append(a)