~ubuntu-branches/ubuntu/saucy/python-glanceclient/saucy

« back to all changes in this revision

Viewing changes to glanceclient/openstack/common/setup.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Chuck Short, Adam Gandleman
  • Date: 2012-07-06 11:31:31 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20120706113131-8g4f0y6i83qf7vjm
Tags: 1:0.1.1-0ubuntu1
[ Chuck Short ]
* New upstream release.
* debian/rules: Fix test suite 
* debian/patches/fix-ubuntu-tests: Re-introduced to prevent downloading 
  virtualenv deps.
* debian/watch: Update with new location.

[ Adam Gandleman ]
* debian/control: wrap-and-sort, add python-setuptools to Depends.
* debian/pydist-overrides: Override python-keystoneclient.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
Utilities with minimum-depends for use in setup.py
20
20
"""
21
21
 
 
22
import datetime
22
23
import os
23
24
import re
24
25
import subprocess
 
26
import sys
25
27
 
26
28
from setuptools.command import sdist
27
29
 
33
35
        for l in fp:
34
36
            l = l.strip()
35
37
            if not l.startswith('#') and ' ' in l:
36
 
                canonical_email, alias = [x for x in l.split(' ')
37
 
                                          if x.startswith('<')]
 
38
                canonical_email, alias = l.split(' ')
38
39
                mapping[alias] = canonical_email
39
40
    return mapping
40
41
 
76
77
        # -f lines are for index locations, and don't get used here
77
78
        elif re.match(r'\s*-f\s+', line):
78
79
            pass
 
80
        # argparse is part of the standard library starting with 2.7
 
81
        # adding it to the requirements list screws distro installs
 
82
        elif line == 'argparse' and sys.version_info >= (2, 7):
 
83
            pass
79
84
        else:
80
85
            requirements.append(line)
81
86
 
113
118
def _run_shell_command(cmd):
114
119
    output = subprocess.Popen(["/bin/sh", "-c", cmd],
115
120
                              stdout=subprocess.PIPE)
116
 
    return output.communicate()[0].strip()
117
 
 
118
 
 
119
 
def write_vcsversion(location):
120
 
    """Produce a vcsversion dict that mimics the old one produced by bzr.
121
 
    """
122
 
    if os.path.isdir('.git'):
123
 
        branch_nick_cmd = 'git branch | grep -Ei "\* (.*)" | cut -f2 -d" "'
124
 
        branch_nick = _run_shell_command(branch_nick_cmd)
125
 
        revid_cmd = "git rev-parse HEAD"
126
 
        revid = _run_shell_command(revid_cmd).split()[0]
127
 
        revno_cmd = "git log --oneline | wc -l"
128
 
        revno = _run_shell_command(revno_cmd)
129
 
        with open(location, 'w') as version_file:
130
 
            version_file.write("""
131
 
# This file is automatically generated by setup.py, So don't edit it. :)
132
 
version_info = {
133
 
    'branch_nick': '%s',
134
 
    'revision_id': '%s',
135
 
    'revno': %s
136
 
}
137
 
""" % (branch_nick, revid, revno))
 
121
    out = output.communicate()
 
122
    if len(out) == 0:
 
123
        return None
 
124
    if len(out[0].strip()) == 0:
 
125
        return None
 
126
    return out[0].strip()
 
127
 
 
128
 
 
129
def _get_git_next_version_suffix(branch_name):
 
130
    datestamp = datetime.datetime.now().strftime('%Y%m%d')
 
131
    if branch_name == 'milestone-proposed':
 
132
        revno_prefix = "r"
 
133
    else:
 
134
        revno_prefix = ""
 
135
    _run_shell_command("git fetch origin +refs/meta/*:refs/remotes/meta/*")
 
136
    milestone_cmd = "git show meta/openstack/release:%s" % branch_name
 
137
    milestonever = _run_shell_command(milestone_cmd)
 
138
    if not milestonever:
 
139
        milestonever = ""
 
140
    post_version = _get_git_post_version()
 
141
    revno = post_version.split(".")[-1]
 
142
    return "%s~%s.%s%s" % (milestonever, datestamp, revno_prefix, revno)
 
143
 
 
144
 
 
145
def _get_git_current_tag():
 
146
    return _run_shell_command("git tag --contains HEAD")
 
147
 
 
148
 
 
149
def _get_git_tag_info():
 
150
    return _run_shell_command("git describe --tags")
 
151
 
 
152
 
 
153
def _get_git_post_version():
 
154
    current_tag = _get_git_current_tag()
 
155
    if current_tag is not None:
 
156
        return current_tag
 
157
    else:
 
158
        tag_info = _get_git_tag_info()
 
159
        if tag_info is None:
 
160
            base_version = "0.0"
 
161
            cmd = "git --no-pager log --oneline"
 
162
            out = _run_shell_command(cmd)
 
163
            revno = len(out.split("\n"))
 
164
        else:
 
165
            tag_infos = tag_info.split("-")
 
166
            base_version = "-".join(tag_infos[:-2])
 
167
            revno = tag_infos[-2]
 
168
        return "%s.%s" % (base_version, revno)
138
169
 
139
170
 
140
171
def write_git_changelog():
174
205
"""
175
206
 
176
207
 
 
208
def read_versioninfo(project):
 
209
    """Read the versioninfo file. If it doesn't exist, we're in a github
 
210
       zipball, and there's really know way to know what version we really
 
211
       are, but that should be ok, because the utility of that should be
 
212
       just about nil if this code path is in use in the first place."""
 
213
    versioninfo_path = os.path.join(project, 'versioninfo')
 
214
    if os.path.exists(versioninfo_path):
 
215
        with open(versioninfo_path, 'r') as vinfo:
 
216
            version = vinfo.read().strip()
 
217
    else:
 
218
        version = "0.0.0"
 
219
    return version
 
220
 
 
221
 
 
222
def write_versioninfo(project, version):
 
223
    """Write a simple file containing the version of the package."""
 
224
    open(os.path.join(project, 'versioninfo'), 'w').write("%s\n" % version)
 
225
 
 
226
 
177
227
def get_cmdclass():
178
228
    """Return dict of commands to run from setup.py."""
179
229
 
250
300
        pass
251
301
 
252
302
    return cmdclass
 
303
 
 
304
 
 
305
def get_git_branchname():
 
306
    for branch in _run_shell_command("git branch --color=never").split("\n"):
 
307
        if branch.startswith('*'):
 
308
            _branch_name = branch.split()[1].strip()
 
309
    if _branch_name == "(no":
 
310
        _branch_name = "no-branch"
 
311
    return _branch_name
 
312
 
 
313
 
 
314
def get_pre_version(projectname, base_version):
 
315
    """Return a version which is based"""
 
316
    if os.path.isdir('.git'):
 
317
        current_tag = _get_git_current_tag()
 
318
        if current_tag is not None:
 
319
            version = current_tag
 
320
        else:
 
321
            branch_name = os.getenv('BRANCHNAME',
 
322
                                    os.getenv('GERRIT_REFNAME',
 
323
                                              get_git_branchname()))
 
324
            version_suffix = _get_git_next_version_suffix(branch_name)
 
325
            version = "%s~%s" % (base_version, version_suffix)
 
326
        write_versioninfo(projectname, version)
 
327
        return version.split('~')[0]
 
328
    else:
 
329
        version = read_versioninfo(projectname)
 
330
    return version.split('~')[0]
 
331
 
 
332
 
 
333
def get_post_version(projectname):
 
334
    """Return a version which is equal to the tag that's on the current
 
335
    revision if there is one, or tag plus number of additional revisions
 
336
    if the current revision has no tag."""
 
337
 
 
338
    if os.path.isdir('.git'):
 
339
        version = _get_git_post_version()
 
340
        write_versioninfo(projectname, version)
 
341
        return version
 
342
    return read_versioninfo(projectname)