~abentley/juju-ci-tools/client-from-config-4

« back to all changes in this revision

Viewing changes to make-buildvars

  • Committer: seman.said at canonical
  • Date: 2016-02-26 19:04:29 UTC
  • mto: This revision was merged to the branch mainline in revision 1302.
  • Revision ID: seman.said@canonical.com-20160226190429-nkvgz5kxdl06dd33
Moved logging config to main function.

Show diffs side-by-side

added added

removed removed

Lines of Context:
59
59
        commit, ref = ls_remote(repo_url, revision_spec, tag=True)
60
60
    if commit is None:
61
61
        commit = revision_spec
62
 
    return None, commit
63
 
 
64
 
 
65
 
def get_git_version(branch, commit):
66
 
    protocol, branch_name, repo_name = branch.split(':')
67
62
    domain, user, repo = repo_name.split('/')
68
63
    template = 'https://raw.githubusercontent.com/{}/{}/{}/version/version.go'
69
64
    file_url = template.format(user, repo, commit)
70
65
    response = urllib2.urlopen(file_url)
71
 
    return parse_version(response.read())
 
66
    version = parse_version(response.read())
 
67
    return None, commit, version
72
68
 
73
69
 
74
70
if __name__ == '__main__':
84
80
    if branch.startswith('lp:'):
85
81
        logging.error('Launchpad branches are no longer supported.')
86
82
        sys.exit(1)
87
 
    revno, revision_id = get_git_revision_info(branch, revision_spec)
88
 
    version = None
89
 
    version_str = ''
90
 
    try:
91
 
        version = get_git_version(branch, revision_id)
92
 
        version_str = str(version)
93
 
    finally:
94
 
        with open('buildvars.bash', 'w') as f:
95
 
            f.write(dedent("""\
96
 
                export BRANCH=%s
97
 
                export REVISION_ID='%s'
98
 
                export VERSION=%s
99
 
            """ % (branch, revision_id, version_str)))
100
 
            if revno is not None:
101
 
                f.write('export REVNO=%s\n' % revno)
102
 
        with open('buildvars.json', 'w') as f:
103
 
            json.dump({
104
 
                'branch': branch,
105
 
                'revision_id': revision_id,
106
 
                'version': version,
107
 
                'revision_build': args.revision_build,
108
 
                }, f, indent=2)
109
 
 
 
83
    else:
 
84
        revno, revision_id, version = get_git_revision_info(
 
85
            branch, revision_spec)
 
86
    with open('buildvars.bash', 'w') as f:
 
87
        f.write(dedent("""\
 
88
            export BRANCH=%s
 
89
            export REVISION_ID='%s'
 
90
            export VERSION=%s
 
91
        """ % (branch, revision_id, version)))
 
92
        if revno is not None:
 
93
            f.write('export REVNO=%s\n' % revno)
 
94
    with open('buildvars.json', 'w') as f:
 
95
        json.dump({
 
96
            'branch': branch,
 
97
            'revision_id': revision_id,
 
98
            'version': version,
 
99
            'revision_build': args.revision_build,
 
100
            }, f, indent=2)