def clone(self, repo_address: str, code_dir: str, token: str):
        logger.info("\tCloning Hg: " + self.get_safe_address(repo_address, token) + " to: " + code_dir)
        revision_id = None
        hgapi.hg_clone(repo_address, code_dir)

        #TODO: Determine date and id for Hg

        return revision_id
Example #2
0
def build_and_push(args):
    error = None
    output = []
    folder = None

    client = get_docker_client()

    kwargs = {"nocache": args["nocache"]}
    if args["url"]:
        folder = get_working_dir()
        try:
            hg_clone(args["url"], folder)
            dockerfile = os.path.join(folder, "Dockerfile")
            if not os.path.exists(dockerfile):
                error = "Repository has no file named 'Dockerfile'"
            kwargs['path'] = folder
        except HgException as e:
            error = "Could not clone repository: %s" % e
    elif args["path"]:
        kwargs['path'] = args["path"]
    else:
        error = "Must provide a dockerfile or a repository"
    if error:
        return {"error": error}

    error = "Build failed"
    base_tag = "_".join((app.config['DOCKER_REGISTRY_URL'], args['user']))
    tag = '/'.join((base_tag, args["name"]))
    result = client.build(tag=tag, **kwargs)
    for line in result:
        output.append(json.loads(line.decode()))
        if "Successfully built" in str(line):
            error = None
    if not error:
        client.push(repository=tag,
                    insecure_registry=app.config['DOCKER_REGISTRY_INSECURE'])

    if folder:
        shutil.rmtree(folder)
    if args["path"]:
        shutil.rmtree(args["path"])

    return {
        "name": args["name"],
        "content": args["content"],
        "error": error,
        "output": output,
        "tag": tag
    }
Example #3
0
def hg_clone(url, path, branch="default", revision=None):
    url = get_url(url)
    extended_args = ['--pull']
    revision = revision or branch
    if revision:
        extended_args.append('-u')
        extended_args.append(revision)
    retries = 2
    while retries:
        retries -= 1
        try:
            client = hgapi.hg_clone(url, path, *extended_args)
            res = check_revision(client, path, revision, branch)
            print "Repo " + t.bold(path) + t.green(" Updated") + \
                " to Revision:" + revision
            return res
        except hgapi.HgException, e:
            if retries:
                print t.bold_yellow('[' + path + '] (%d)' % retries)
            else:
                print t.bold_red('[' + path + '] (%d)' % retries)
            print "Error running %s: %s" % (e.exit_code, str(e))
            if retries:
                continue
            return -1
        except:
Example #4
0
def hg_clone(url, dirname = None, revision = None, basedir = None):
    name, _ = parse_hg_url(url)
    dirname, renamed = dirname or name, False
    initial = dirname
    if exists(dirname):
        warn("WARNING: directory '%s' already exists!" % join(os.getcwd(), dirname))
        idx, renamed = 1, True
        while True:
            dirname = "%s_%d" % (initial, idx)
            if not exists(dirname):
                break
            idx = idx + 1
    info("[%s] -> %s... (%s) %s" % (url, abspath(dirname), revision or "default", ("(renamed from '%s' to '%s')" % (initial, dirname)) if renamed else ""))
    try:
        hgapi.hg_clone(url, dirname, '-u', revision or "default")
    except hgapi.HgException:
        error("Error running 'hg clone', aborting.")
        os._exit(1)
    return abspath(dirname)
Example #5
0
def hg_to_git(hg_path, git_path):
    """
    Convert the Bitbucket repo to a Github repo. First clone the hg_path,
    then add the hggit extension to this clone, and lastly push the clone
    to github.
    :param hg_path: The Bitbucket Mercurial based repository.
    :param git_path: The Github (obviously Git based) repository.
    :return:
    """
    logger.debug('Converting {} to {}.'.format(hg_path, git_path))
    with TemporaryDirectory(prefix='hg-') as hg_repo_path:
        logger.debug('Cloning {} to {}...'.format(hg_path, hg_repo_path))
        hg_repo = hgapi.hg_clone(hg_path, hg_repo_path)
        add_hggit_extension_and_git_path(hg_repo_path, git_path)
        logger.debug('Bookmarking the clone...')
        hg_repo.hg_bookmarks(action=hgapi.Repo.BOOKMARK_CREATE, name='master')
        logger.debug('Pushing it to github...')
        hg_repo.hg_push('github')
Example #6
0
 def clone(self, url, path):
     hgapi.hg_clone(url, path)
Example #7
0
 def __init__(self, *args, **kwargs):
     Repository.__init__(self, *args, **kwargs)
     if os.path.exists(self.local_path) and os.path.isdir(self.local_path):
         self.repo = hgapi.Repo(self.local_path)
     else:
         self.repo = hgapi.hg_clone(self.url, self.local_path)