Skip to content

Commit 2f7b032

Browse files
committed
Pull in latest openstack-common changes and fix a minor PEP8 issue.
Latest openstack-common commit: d887090b5a31672e4a12f302b3818e2b0933bef0 Change-Id: I5a4ffb043ab24f8618a8285112c0c5992ea129e7
1 parent e8c22cd commit 2f7b032

4 files changed

Lines changed: 73 additions & 49 deletions

File tree

.mailmap

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ Chris Behrens <cbehrens+github@codestud.com> comstud <cbehrens+github@codestud.c
66
<dprince@redhat.com> <dan.prince@rackspace.com>
77
Johannes Erdfelt <johannes.erdfelt@rackspace.com> jerdfelt <johannes@erdfelt.com>
88
<johannes.erdfelt@rackspace.com> <johannes@erdfelt.com>
9-
<josh@jk0.org> <jkearney@nova.(none)>
9+
<josh.kearney@pistoncloud.com> <josh@jk0.org>
10+
<josh.kearney@pistoncloud.com> <jkearney@nova.(none)>
1011
<sandy@darksecretsoftware.com> <sandy.walsh@rackspace.com>
1112
<sandy@darksecretsoftware.com> <sandy@sandywalsh.com>
1213
Andy Smith <github@anarkystic.com> termie <github@anarkystic.com>

novaclient/openstack/common/setup.py

Lines changed: 55 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@
3131
def parse_mailmap(mailmap='.mailmap'):
3232
mapping = {}
3333
if os.path.exists(mailmap):
34-
fp = open(mailmap, 'r')
35-
for l in fp:
36-
l = l.strip()
37-
if not l.startswith('#') and ' ' in l:
38-
canonical_email, alias = ['%s>' % x.strip() for x in
39-
l.split('>')][:2]
40-
mapping[alias] = canonical_email
34+
with open(mailmap, 'r') as fp:
35+
for l in fp:
36+
l = l.strip()
37+
if not l.startswith('#') and ' ' in l:
38+
canonical_email, alias = [x for x in l.split(' ')
39+
if x.startswith('<')]
40+
mapping[alias] = canonical_email
4141
return mapping
4242

4343

@@ -52,10 +52,10 @@ def canonicalize_emails(changelog, mapping):
5252

5353
# Get requirements from the first file that exists
5454
def get_reqs_from_files(requirements_files):
55-
reqs_in = []
5655
for requirements_file in requirements_files:
5756
if os.path.exists(requirements_file):
58-
return open(requirements_file, 'r').read().split('\n')
57+
with open(requirements_file, 'r') as fil:
58+
return fil.read().split('\n')
5959
return []
6060

6161

@@ -117,12 +117,8 @@ def write_requirements():
117117

118118

119119
def _run_shell_command(cmd):
120-
if os.name == 'nt':
121-
output = subprocess.Popen(["cmd.exe", "/C", cmd],
122-
stdout=subprocess.PIPE)
123-
else:
124-
output = subprocess.Popen(["/bin/sh", "-c", cmd],
125-
stdout=subprocess.PIPE)
120+
output = subprocess.Popen(["/bin/sh", "-c", cmd],
121+
stdout=subprocess.PIPE)
126122
out = output.communicate()
127123
if len(out) == 0:
128124
return None
@@ -143,8 +139,14 @@ def _get_git_next_version_suffix(branch_name):
143139
if not milestonever:
144140
milestonever = ""
145141
post_version = _get_git_post_version()
146-
revno = post_version.split(".")[-1]
147-
return "%s~%s.%s%s" % (milestonever, datestamp, revno_prefix, revno)
142+
# post version should look like:
143+
# 0.1.1.4.gcc9e28a
144+
# where the bit after the last . is the short sha, and the bit between
145+
# the last and second to last is the revno count
146+
(revno, sha) = post_version.split(".")[-2:]
147+
first_half = "%s~%s" % (milestonever, datestamp)
148+
second_half = "%s%s.%s" % (revno_prefix, revno, sha)
149+
return ".".join((first_half, second_half))
148150

149151

150152
def _get_git_current_tag():
@@ -166,39 +168,48 @@ def _get_git_post_version():
166168
cmd = "git --no-pager log --oneline"
167169
out = _run_shell_command(cmd)
168170
revno = len(out.split("\n"))
171+
sha = _run_shell_command("git describe --always")
169172
else:
170173
tag_infos = tag_info.split("-")
171174
base_version = "-".join(tag_infos[:-2])
172-
revno = tag_infos[-2]
173-
return "%s.%s" % (base_version, revno)
175+
(revno, sha) = tag_infos[-2:]
176+
return "%s.%s.%s" % (base_version, revno, sha)
174177

175178

176179
def write_git_changelog():
177180
"""Write a changelog based on the git changelog."""
178-
if os.path.isdir('.git'):
179-
git_log_cmd = 'git log --stat'
180-
changelog = _run_shell_command(git_log_cmd)
181-
mailmap = parse_mailmap()
182-
with open("ChangeLog", "w") as changelog_file:
183-
changelog_file.write(canonicalize_emails(changelog, mailmap))
181+
new_changelog = 'ChangeLog'
182+
if not os.getenv('SKIP_WRITE_GIT_CHANGELOG'):
183+
if os.path.isdir('.git'):
184+
git_log_cmd = 'git log --stat'
185+
changelog = _run_shell_command(git_log_cmd)
186+
mailmap = parse_mailmap()
187+
with open(new_changelog, "w") as changelog_file:
188+
changelog_file.write(canonicalize_emails(changelog, mailmap))
189+
else:
190+
open(new_changelog, 'w').close()
184191

185192

186193
def generate_authors():
187194
"""Create AUTHORS file using git commits."""
188-
jenkins_email = 'jenkins@review.openstack.org'
195+
jenkins_email = 'jenkins@review.(openstack|stackforge).org'
189196
old_authors = 'AUTHORS.in'
190197
new_authors = 'AUTHORS'
191-
if os.path.isdir('.git'):
192-
# don't include jenkins email address in AUTHORS file
193-
git_log_cmd = ("git log --format='%aN <%aE>' | sort -u | "
194-
"grep -v " + jenkins_email)
195-
changelog = _run_shell_command(git_log_cmd)
196-
mailmap = parse_mailmap()
197-
with open(new_authors, 'w') as new_authors_fh:
198-
new_authors_fh.write(canonicalize_emails(changelog, mailmap))
199-
if os.path.exists(old_authors):
200-
with open(old_authors, "r") as old_authors_fh:
201-
new_authors_fh.write('\n' + old_authors_fh.read())
198+
if not os.getenv('SKIP_GENERATE_AUTHORS'):
199+
if os.path.isdir('.git'):
200+
# don't include jenkins email address in AUTHORS file
201+
git_log_cmd = ("git log --format='%aN <%aE>' | sort -u | "
202+
"egrep -v '" + jenkins_email + "'")
203+
changelog = _run_shell_command(git_log_cmd)
204+
mailmap = parse_mailmap()
205+
with open(new_authors, 'w') as new_authors_fh:
206+
new_authors_fh.write(canonicalize_emails(changelog, mailmap))
207+
if os.path.exists(old_authors):
208+
with open(old_authors, "r") as old_authors_fh:
209+
new_authors_fh.write('\n' + old_authors_fh.read())
210+
else:
211+
open(new_authors, 'w').close()
212+
202213

203214
_rst_template = """%(heading)s
204215
%(underline)s
@@ -212,7 +223,7 @@ def generate_authors():
212223

213224
def read_versioninfo(project):
214225
"""Read the versioninfo file. If it doesn't exist, we're in a github
215-
zipball, and there's really know way to know what version we really
226+
zipball, and there's really no way to know what version we really
216227
are, but that should be ok, because the utility of that should be
217228
just about nil if this code path is in use in the first place."""
218229
versioninfo_path = os.path.join(project, 'versioninfo')
@@ -226,7 +237,8 @@ def read_versioninfo(project):
226237

227238
def write_versioninfo(project, version):
228239
"""Write a simple file containing the version of the package."""
229-
open(os.path.join(project, 'versioninfo'), 'w').write("%s\n" % version)
240+
with open(os.path.join(project, 'versioninfo'), 'w') as fil:
241+
fil.write("%s\n" % version)
230242

231243

232244
def get_cmdclass():
@@ -317,7 +329,8 @@ def get_git_branchname():
317329

318330

319331
def get_pre_version(projectname, base_version):
320-
"""Return a version which is based"""
332+
"""Return a version which is leading up to a version that will
333+
be released in the future."""
321334
if os.path.isdir('.git'):
322335
current_tag = _get_git_current_tag()
323336
if current_tag is not None:
@@ -329,10 +342,10 @@ def get_pre_version(projectname, base_version):
329342
version_suffix = _get_git_next_version_suffix(branch_name)
330343
version = "%s~%s" % (base_version, version_suffix)
331344
write_versioninfo(projectname, version)
332-
return version.split('~')[0]
345+
return version
333346
else:
334347
version = read_versioninfo(projectname)
335-
return version.split('~')[0]
348+
return version
336349

337350

338351
def get_post_version(projectname):

novaclient/openstack/common/timeutils.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,23 @@ def parse_strtime(timestr, fmt=PERFECT_TIME_FORMAT):
6262

6363

6464
def normalize_time(timestamp):
65-
"""Normalize time in arbitrary timezone to UTC"""
65+
"""Normalize time in arbitrary timezone to UTC naive object"""
6666
offset = timestamp.utcoffset()
67-
return timestamp.replace(tzinfo=None) - offset if offset else timestamp
67+
if offset is None:
68+
return timestamp
69+
return timestamp.replace(tzinfo=None) - offset
6870

6971

7072
def is_older_than(before, seconds):
7173
"""Return True if before is older than seconds."""
7274
return utcnow() - before > datetime.timedelta(seconds=seconds)
7375

7476

77+
def is_newer_than(after, seconds):
78+
"""Return True if after is newer than seconds."""
79+
return after - utcnow() > datetime.timedelta(seconds=seconds)
80+
81+
7582
def utcnow_ts():
7683
"""Timestamp version of our utcnow function."""
7784
return calendar.timegm(utcnow().timetuple())
@@ -121,6 +128,10 @@ def marshall_now(now=None):
121128

122129
def unmarshall_time(tyme):
123130
"""Unmarshall a datetime dict."""
124-
return datetime.datetime(day=tyme['day'], month=tyme['month'],
125-
year=tyme['year'], hour=tyme['hour'], minute=tyme['minute'],
126-
second=tyme['second'], microsecond=tyme['microsecond'])
131+
return datetime.datetime(day=tyme['day'],
132+
month=tyme['month'],
133+
year=tyme['year'],
134+
hour=tyme['hour'],
135+
minute=tyme['minute'],
136+
second=tyme['second'],
137+
microsecond=tyme['microsecond'])

tests/test_auth_plugins.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,3 @@ def test_auth_call():
180180
no_cache=True)
181181

182182
test_auth_call()
183-

0 commit comments

Comments
 (0)