Ejemplo n.º 1
0
def get_project(name: str, directory: str = '') -> None:
    """Clone a project from a GitHub name or git url.

    Put it in dir if this argument is given.
    A GitHub name without / will be considered as
    a leanprover-community project.
    If the name ends with ':foo' then foo will be interpreted
    as a branch name, and that branch will be checked out."""

    # check whether we can ssh into GitHub
    try:
        client = paramiko.client.SSHClient()
        client.set_missing_host_key_policy(paramiko.client.AutoAddPolicy())
        client.connect('github.com', username='******')
        client.close()
        ssh = True
    except (AuthenticationException, SSHException):
        ssh = False

    name, url, branch = parse_project_name(name, ssh)
    if branch:
        name = name + '_' + branch
    directory = directory or name
    if directory and Path(directory).exists():
        log.error(directory + ' already exists')
        sys.exit(-1)
    try:
        LeanProject.from_git_url(url, directory, branch, cache_url,
                                 force_download)
    except GitCommandError as err:
        handle_exception(err, 'Git command failed')
Ejemplo n.º 2
0
def handle_exception(exc, msg):
    if debug:
        raise exc
    else:
        log.error(msg)
        sys.exit(-1)