Пример #1
0
def _get_git_repository_remote_origin(path):
    # check that path is a git working copy
    if not os.path.exists(os.path.join(path, '.git')):
        return None

    git = find_executable('git')
    if git:
        url = subprocess.check_output(
            [git, 'config', 'remote.origin.url'], cwd=path)
        return url.decode().rstrip()

    # extract url of remote origin from git config file
    with open(os.path.join(path, '.git', 'config'), 'r') as h:
        lines = h.read().splitlines()
    section = '[remote "origin"]'
    if section not in lines:
        return None
    section_index = lines.index(section)

    index = section_index + 1
    while index < len(lines):
        line = lines[index]
        if line.startswith('['):
            return None
        line = line.lstrip()
        line_parts = line.split(' = ', 1)
        if line_parts[0] == 'url':
            return line_parts[1]
        index += 1
    return None
Пример #2
0
def _get_git_repository_remote_origin(path):
    # check that path is a git working copy
    if not os.path.exists(os.path.join(path, '.git')):
        return None

    git = find_executable('git')
    if git:
        url = subprocess.check_output([git, 'config', 'remote.origin.url'],
                                      cwd=path)
        return url.decode().rstrip()

    # extract url of remote origin from git config file
    with open(os.path.join(path, '.git', 'config'), 'r') as h:
        lines = h.read().splitlines()
    section = '[remote "origin"]'
    if section not in lines:
        return None
    section_index = lines.index(section)

    index = section_index + 1
    while index < len(lines):
        line = lines[index]
        if line.startswith('['):
            return None
        line = line.lstrip()
        line_parts = line.split(' = ', 1)
        if line_parts[0] == 'url':
            return line_parts[1]
        index += 1
    return None
def get_hash(path):
    if os.path.exists(os.path.join(path, '.git')):
        return get_git_hash(path)

    if os.path.exists(os.path.join(path, '.hg')):
        hg = find_executable('hg')
        if not hg:
            return None
        hash_ = subprocess.check_output([hg, 'id', '--id'], cwd=path)
        return hash_.decode().rstrip()

    if os.path.exists(os.path.join(path, '.svn')):
        svnversion = find_executable('svnversion')
        if not svnversion:
            return None
        revision = subprocess.check_output([svnversion], cwd=path)
        return revision.decode().rstrip()

    assert False, 'Unsupported vcs type'
Пример #4
0
def _get_git_repository_version(path):
    # check that path is a git working copy
    if not os.path.exists(os.path.join(path, '.git')):
        return None

    git = find_executable('git')
    if not git:
        return None

    # check for local modifications
    try:
        any_modifications = subprocess.check_output([git, 'status', '--short'],
                                                    cwd=path)
    except subprocess.CalledProcessError:
        return None
    if any_modifications:
        print("Your git workspace contains local modifications. They won't " +
              'propagate to the actual jobs when not available from the git ' +
              'repository.',
              file=sys.stderr)

    # check if working copy is on a branch
    # (does not apply when a specific tag is checked out)
    url = subprocess.check_output([git, 'rev-parse', '--abbrev-ref', 'HEAD'],
                                  cwd=path)
    url = url.decode().rstrip()
    if url != 'HEAD':
        # get plain branch name on Jenkins
        prefix = 'heads/origin/'
        if url.startswith(prefix):
            url = url[len(prefix):]
        return url

    # check if working copy is on a tag
    try:
        with open(os.devnull, 'w') as h:
            tags = subprocess.check_output(
                [git, 'describe', '--exact-match', '--tags'],
                cwd=path,
                stderr=h)
        return tags.decode().splitlines()[0]
    except subprocess.CalledProcessError:
        pass

    # if the HEAD is detached the only way to retrieve the branch is
    # looking for the environment variable set by Jenkins
    env_var = 'GIT_BRANCH'
    if env_var in os.environ:
        git_branch = os.environ[env_var]
        prefix = 'origin/'
        if git_branch.startswith(prefix):
            return git_branch[len(prefix):]

    # use current hash
    return get_hash(path)
Пример #5
0
def get_hash(path):
    # check that path is a git working copy
    if not os.path.exists(os.path.join(path, '.git')):
        return None

    git = find_executable('git')
    if not git:
        return None

    hash_ = subprocess.check_output([git, 'rev-parse', 'HEAD'], cwd=path)
    return hash_.decode().rstrip()
def get_hash(path):
    if os.path.exists(os.path.join(path, '.git')):
        return get_git_hash(path)

    if os.path.exists(os.path.join(path, '.hg')):
        hg = find_executable('hg')
        if not hg:
            return None
        hash_ = subprocess.check_output(
            [hg, 'id', '--id'], cwd=path)
        return hash_.decode().rstrip()

    if os.path.exists(os.path.join(path, '.svn')):
        svnversion = find_executable('svnversion')
        if not svnversion:
            return None
        revision = subprocess.check_output(
            [svnversion], cwd=path)
        return revision.decode().rstrip()

    assert False, 'Unsupported vcs type'
Пример #7
0
def get_hash(path):
    # check that path is a git working copy
    if not os.path.exists(os.path.join(path, '.git')):
        return None

    git = find_executable('git')
    if not git:
        return None

    hash_ = subprocess.check_output(
        [git, 'rev-parse', 'HEAD'], cwd=path)
    return hash_.decode().rstrip()
Пример #8
0
def _get_git_repository_version(path):
    # check that path is a git working copy
    if not os.path.exists(os.path.join(path, '.git')):
        return None

    git = find_executable('git')
    if not git:
        return None

    # check for local modifications
    try:
        any_modifications = subprocess.check_output(
            [git, 'status', '--short'], cwd=path)
    except subprocess.CalledProcessError:
        return None
    if any_modifications:
        print("Your git workspace contains local modifications. They won't " +
              'propagate to the actual jobs when not available from the git ' +
              'repository.', file=sys.stderr)

    # check if working copy is on a branch
    # (does not apply when a specific tag is checked out)
    url = subprocess.check_output(
        [git, 'rev-parse', '--abbrev-ref', 'HEAD'], cwd=path)
    url = url.decode().rstrip()
    if url != 'HEAD':
        # get plain branch name on Jenkins
        prefix = 'heads/origin/'
        if url.startswith(prefix):
            url = url[len(prefix):]
        return url

    # check if working copy is on a tag
    try:
        with open(os.devnull, 'w') as h:
            tags = subprocess.check_output(
                [git, 'describe', '--exact-match', '--tags'],
                cwd=path, stderr=h)
        return tags.decode().splitlines()[0]
    except subprocess.CalledProcessError:
        pass

    # if the HEAD is detached the only way to retrieve the branch is
    # looking for the environment variable set by Jenkins
    env_var = 'GIT_BRANCH'
    if env_var in os.environ:
        git_branch = os.environ[env_var]
        prefix = 'origin/'
        if git_branch.startswith(prefix):
            return git_branch[len(prefix):]

    # use current hash
    return get_hash(path)
Пример #9
0
def get_wrapper_scripts():
    wrapper_scripts = {}
    for filename in ['apt-get.py', 'git.py']:
        abs_file_path = find_executable(filename)
        if not abs_file_path:
            wrapper_script_path = os.path.join(
                os.path.dirname(os.path.dirname(os.path.dirname(__file__))),
                'scripts', 'wrapper')
            abs_file_path = os.path.join(wrapper_script_path, filename)
        with open(abs_file_path, 'r') as h:
            content = h.read()
            wrapper_scripts[filename] = content
    return wrapper_scripts
Пример #10
0
def _get_git_repository_version(path):
    # check that path is a git working copy
    if not os.path.exists(os.path.join(path, '.git')):
        return None

    git = find_executable('git')
    if not git:
        return None

    # check for local modifications
    try:
        any_modifications = subprocess.check_output([git, 'status', '--short'],
                                                    cwd=path)
    except subprocess.CalledProcessError:
        return None
    if any_modifications:
        print("Your git workspace contains local modifications. They won't " +
              'propagate to the actual jobs when not available from the git ' +
              'repository.',
              file=sys.stderr)

    # check if working copy is on a branch
    # (does not apply when a specific tag is checked out)
    url = subprocess.check_output([git, 'rev-parse', '--abbrev-ref', 'HEAD'],
                                  cwd=path)
    url = url.decode().rstrip()
    if url != 'HEAD':
        return url

    # check if working copy is on a tag
    try:
        tags = subprocess.check_output(
            [git, 'describe', '--exact-match', '--tags'], cwd=path)
        return tags.decode().splitlines()[0]
    except subprocess.CalledProcessError:
        pass

    # use current hash
    return get_hash(path)
Пример #11
0
def _get_git_repository_version(path):
    # check that path is a git working copy
    if not os.path.exists(os.path.join(path, '.git')):
        return None

    git = find_executable('git')
    if not git:
        return None

    # check for local modifications
    try:
        any_modifications = subprocess.check_output(
            [git, 'status', '--short'], cwd=path)
    except subprocess.CalledProcessError:
        return None
    if any_modifications:
        print("Your git workspace contains local modifications. They won't " +
              'propagate to the actual jobs when not available from the git ' +
              'repository.', file=sys.stderr)

    # check if working copy is on a branch
    # (does not apply when a specific tag is checked out)
    url = subprocess.check_output(
        [git, 'rev-parse', '--abbrev-ref', 'HEAD'], cwd=path)
    url = url.decode().rstrip()
    if url != 'HEAD':
        return url

    # check if working copy is on a tag
    try:
        tags = subprocess.check_output(
            [git, 'describe', '--exact-match', '--tags'], cwd=path)
        return tags.decode().splitlines()[0]
    except subprocess.CalledProcessError:
        pass

    # use current hash
    return get_hash(path)