Permalink
Browse files

Pull in latest openstack-common changes and fix a minor PEP8 issue.

Latest openstack-common commit: d887090b5a31672e4a12f302b3818e2b0933bef0

Change-Id: I5a4ffb043ab24f8618a8285112c0c5992ea129e7
  • Loading branch information...
1 parent e8c22cd commit 2f7b032910cce500f09a5d2a257595d573bdb116 @jk0 jk0 committed Oct 25, 2012
Showing with 73 additions and 49 deletions.
  1. +2 −1 .mailmap
  2. +55 −42 novaclient/openstack/common/setup.py
  3. +16 −5 novaclient/openstack/common/timeutils.py
  4. +0 −1 tests/test_auth_plugins.py
View
@@ -6,7 +6,8 @@ Chris Behrens <cbehrens+github@codestud.com> comstud <cbehrens+github@codestud.c
<dprince@redhat.com> <dan.prince@rackspace.com>
Johannes Erdfelt <johannes.erdfelt@rackspace.com> jerdfelt <johannes@erdfelt.com>
<johannes.erdfelt@rackspace.com> <johannes@erdfelt.com>
-<josh@jk0.org> <jkearney@nova.(none)>
+<josh.kearney@pistoncloud.com> <josh@jk0.org>
+<josh.kearney@pistoncloud.com> <jkearney@nova.(none)>
<sandy@darksecretsoftware.com> <sandy.walsh@rackspace.com>
<sandy@darksecretsoftware.com> <sandy@sandywalsh.com>
Andy Smith <github@anarkystic.com> termie <github@anarkystic.com>
@@ -31,13 +31,13 @@
def parse_mailmap(mailmap='.mailmap'):
mapping = {}
if os.path.exists(mailmap):
- fp = open(mailmap, 'r')
- for l in fp:
- l = l.strip()
- if not l.startswith('#') and ' ' in l:
- canonical_email, alias = ['%s>' % x.strip() for x in
- l.split('>')][:2]
- mapping[alias] = canonical_email
+ with open(mailmap, 'r') as fp:
+ for l in fp:
+ l = l.strip()
+ if not l.startswith('#') and ' ' in l:
+ canonical_email, alias = [x for x in l.split(' ')
+ if x.startswith('<')]
+ mapping[alias] = canonical_email
return mapping
@@ -52,10 +52,10 @@ def canonicalize_emails(changelog, mapping):
# Get requirements from the first file that exists
def get_reqs_from_files(requirements_files):
- reqs_in = []
for requirements_file in requirements_files:
if os.path.exists(requirements_file):
- return open(requirements_file, 'r').read().split('\n')
+ with open(requirements_file, 'r') as fil:
+ return fil.read().split('\n')
return []
@@ -117,12 +117,8 @@ def write_requirements():
def _run_shell_command(cmd):
- if os.name == 'nt':
- output = subprocess.Popen(["cmd.exe", "/C", cmd],
- stdout=subprocess.PIPE)
- else:
- output = subprocess.Popen(["/bin/sh", "-c", cmd],
- stdout=subprocess.PIPE)
+ output = subprocess.Popen(["/bin/sh", "-c", cmd],
+ stdout=subprocess.PIPE)
out = output.communicate()
if len(out) == 0:
return None
@@ -143,8 +139,14 @@ def _get_git_next_version_suffix(branch_name):
if not milestonever:
milestonever = ""
post_version = _get_git_post_version()
- revno = post_version.split(".")[-1]
- return "%s~%s.%s%s" % (milestonever, datestamp, revno_prefix, revno)
+ # post version should look like:
+ # 0.1.1.4.gcc9e28a
+ # where the bit after the last . is the short sha, and the bit between
+ # the last and second to last is the revno count
+ (revno, sha) = post_version.split(".")[-2:]
+ first_half = "%s~%s" % (milestonever, datestamp)
+ second_half = "%s%s.%s" % (revno_prefix, revno, sha)
+ return ".".join((first_half, second_half))
def _get_git_current_tag():
@@ -166,39 +168,48 @@ def _get_git_post_version():
cmd = "git --no-pager log --oneline"
out = _run_shell_command(cmd)
revno = len(out.split("\n"))
+ sha = _run_shell_command("git describe --always")
else:
tag_infos = tag_info.split("-")
base_version = "-".join(tag_infos[:-2])
- revno = tag_infos[-2]
- return "%s.%s" % (base_version, revno)
+ (revno, sha) = tag_infos[-2:]
+ return "%s.%s.%s" % (base_version, revno, sha)
def write_git_changelog():
"""Write a changelog based on the git changelog."""
- if os.path.isdir('.git'):
- git_log_cmd = 'git log --stat'
- changelog = _run_shell_command(git_log_cmd)
- mailmap = parse_mailmap()
- with open("ChangeLog", "w") as changelog_file:
- changelog_file.write(canonicalize_emails(changelog, mailmap))
+ new_changelog = 'ChangeLog'
+ if not os.getenv('SKIP_WRITE_GIT_CHANGELOG'):
+ if os.path.isdir('.git'):
+ git_log_cmd = 'git log --stat'
+ changelog = _run_shell_command(git_log_cmd)
+ mailmap = parse_mailmap()
+ with open(new_changelog, "w") as changelog_file:
+ changelog_file.write(canonicalize_emails(changelog, mailmap))
+ else:
+ open(new_changelog, 'w').close()
def generate_authors():
"""Create AUTHORS file using git commits."""
- jenkins_email = 'jenkins@review.openstack.org'
+ jenkins_email = 'jenkins@review.(openstack|stackforge).org'
old_authors = 'AUTHORS.in'
new_authors = 'AUTHORS'
- if os.path.isdir('.git'):
- # don't include jenkins email address in AUTHORS file
- git_log_cmd = ("git log --format='%aN <%aE>' | sort -u | "
- "grep -v " + jenkins_email)
- changelog = _run_shell_command(git_log_cmd)
- mailmap = parse_mailmap()
- with open(new_authors, 'w') as new_authors_fh:
- new_authors_fh.write(canonicalize_emails(changelog, mailmap))
- if os.path.exists(old_authors):
- with open(old_authors, "r") as old_authors_fh:
- new_authors_fh.write('\n' + old_authors_fh.read())
+ if not os.getenv('SKIP_GENERATE_AUTHORS'):
+ if os.path.isdir('.git'):
+ # don't include jenkins email address in AUTHORS file
+ git_log_cmd = ("git log --format='%aN <%aE>' | sort -u | "
+ "egrep -v '" + jenkins_email + "'")
+ changelog = _run_shell_command(git_log_cmd)
+ mailmap = parse_mailmap()
+ with open(new_authors, 'w') as new_authors_fh:
+ new_authors_fh.write(canonicalize_emails(changelog, mailmap))
+ if os.path.exists(old_authors):
+ with open(old_authors, "r") as old_authors_fh:
+ new_authors_fh.write('\n' + old_authors_fh.read())
+ else:
+ open(new_authors, 'w').close()
+
_rst_template = """%(heading)s
%(underline)s
@@ -212,7 +223,7 @@ def generate_authors():
def read_versioninfo(project):
"""Read the versioninfo file. If it doesn't exist, we're in a github
- zipball, and there's really know way to know what version we really
+ zipball, and there's really no way to know what version we really
are, but that should be ok, because the utility of that should be
just about nil if this code path is in use in the first place."""
versioninfo_path = os.path.join(project, 'versioninfo')
@@ -226,7 +237,8 @@ def read_versioninfo(project):
def write_versioninfo(project, version):
"""Write a simple file containing the version of the package."""
- open(os.path.join(project, 'versioninfo'), 'w').write("%s\n" % version)
+ with open(os.path.join(project, 'versioninfo'), 'w') as fil:
+ fil.write("%s\n" % version)
def get_cmdclass():
@@ -317,7 +329,8 @@ def get_git_branchname():
def get_pre_version(projectname, base_version):
- """Return a version which is based"""
+ """Return a version which is leading up to a version that will
+ be released in the future."""
if os.path.isdir('.git'):
current_tag = _get_git_current_tag()
if current_tag is not None:
@@ -329,10 +342,10 @@ def get_pre_version(projectname, base_version):
version_suffix = _get_git_next_version_suffix(branch_name)
version = "%s~%s" % (base_version, version_suffix)
write_versioninfo(projectname, version)
- return version.split('~')[0]
+ return version
else:
version = read_versioninfo(projectname)
- return version.split('~')[0]
+ return version
def get_post_version(projectname):
@@ -62,16 +62,23 @@ def parse_strtime(timestr, fmt=PERFECT_TIME_FORMAT):
def normalize_time(timestamp):
- """Normalize time in arbitrary timezone to UTC"""
+ """Normalize time in arbitrary timezone to UTC naive object"""
offset = timestamp.utcoffset()
- return timestamp.replace(tzinfo=None) - offset if offset else timestamp
+ if offset is None:
+ return timestamp
+ return timestamp.replace(tzinfo=None) - offset
def is_older_than(before, seconds):
"""Return True if before is older than seconds."""
return utcnow() - before > datetime.timedelta(seconds=seconds)
+def is_newer_than(after, seconds):
+ """Return True if after is newer than seconds."""
+ return after - utcnow() > datetime.timedelta(seconds=seconds)
+
+
def utcnow_ts():
"""Timestamp version of our utcnow function."""
return calendar.timegm(utcnow().timetuple())
@@ -121,6 +128,10 @@ def marshall_now(now=None):
def unmarshall_time(tyme):
"""Unmarshall a datetime dict."""
- return datetime.datetime(day=tyme['day'], month=tyme['month'],
- year=tyme['year'], hour=tyme['hour'], minute=tyme['minute'],
- second=tyme['second'], microsecond=tyme['microsecond'])
+ return datetime.datetime(day=tyme['day'],
+ month=tyme['month'],
+ year=tyme['year'],
+ hour=tyme['hour'],
+ minute=tyme['minute'],
+ second=tyme['second'],
+ microsecond=tyme['microsecond'])
@@ -180,4 +180,3 @@ def test_auth_call():
no_cache=True)
test_auth_call()
-

0 comments on commit 2f7b032

Please sign in to comment.