summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYvan Roux <yvan.roux@linaro.org>2017-11-07 17:08:44 +0100
committerYvan Roux <yvan.roux@linaro.org>2017-11-10 10:56:16 +0100
commitd435a2533589b320e05a690fcf5622f1604f3b87 (patch)
tree5d7dc6e1c84d2d02e7466d7c931b2c4974f5a979
parent3ec0deb880c9b0c61bc3b5196c9c1a47ae81d018 (diff)
Move to Python3 #2
Rework code w/r to strings/bytes, encoding/decoding and removal of trailing newline needs, given that: * sh.RunningCommand objects can be used as strings * sh.RunningCommand.stdout type is 'bytes' * Python3 strings are always unicode Change-Id: Id7968dcba36bf96cbb5c8f407e20c4ea1443cd02
-rw-r--r--linaropy/git/gitrepo.py27
-rw-r--r--linaropy/rn/rngen.py6
2 files changed, 12 insertions, 21 deletions
diff --git a/linaropy/git/gitrepo.py b/linaropy/git/gitrepo.py
index 78fcefb..a1f5bd9 100644
--- a/linaropy/git/gitrepo.py
+++ b/linaropy/git/gitrepo.py
@@ -68,11 +68,9 @@ class GitRepo(object):
def getbranch(self):
try:
with cd(self.repodir):
- branch = git("rev-parse", "--abbrev-ref",
- "HEAD").stdout.rstrip()
+ return git("rev-parse", "--abbrev-ref", "HEAD").rstrip()
except ErrorReturnCode:
raise EnvironmentError("Unable to get the current branch")
- return str(branch, 'utf-8')
# TODO make this a bit more sophisticated because the user might not be
# using 'origin' as their remote name.
@@ -90,14 +88,13 @@ class GitRepo(object):
stashid = ""
try:
- self.prevbranch = git(
- "rev-parse", "--abbrev-ref", "HEAD").stdout.rstrip()
+ self.prevbranch = git("rev-parse", "--abbrev-ref", "HEAD")
except ErrorReturnCode:
raise EnvironmentError("Unable to get the current branch")
try:
# TODO: do we want to do a blanket git add *?
- stashid = git("stash", "create").stdout.rstrip()
+ stashid = git("stash", "create")
# If there's no stash then there's no reason to save.
if stashid:
git("stash", "save")
@@ -113,7 +110,7 @@ class GitRepo(object):
except ErrorReturnCode:
try:
# if it doesn't exist we need to checkout a new branch
- git("checkout", "-b", branch, track).stdout.rstrip()
+ git("checkout", "-b", branch, track)
except ErrorReturnCode as exc:
raise EnvironmentError(
"Unable to checkout -b %s %s" % (branch, track))
@@ -187,9 +184,10 @@ class GitRepo(object):
try:
with cd(self.repodir):
if oneline:
- print(git("log", "--oneline", "-n %d" % numcommits))
+ print(git("--no-pager", "log", "--oneline", "-n %d" %
+ numcommits))
else:
- print(git("log", "-n %d" % numcommits))
+ print(git("--no-pager", "log", "-n %d" % numcommits))
except ErrorReturnCode:
raise EnvironmentError("Unable to git log -n %d" % numcommits)
@@ -199,11 +197,10 @@ class GitRepo(object):
try:
with cd(self.repodir):
if versus is not None:
- return git("rev-list", "%s..%s" % (versus,
- branch)).stdout.rstrip()
+ return git("rev-list", "%s..%s" % (versus, branch)).rstrip()
else:
return git("rev-list", branch, "--max-count=%d" %
- numcommits).stdout.rstrip()
+ numcommits).rstrip()
except ErrorReturnCode as exc:
raise EnvironmentError("Unable to git rev-list because: %s" %
(numcommits, str(exc)))
@@ -264,9 +261,8 @@ class TestGitRepo(unittest.TestCase):
# Helper function used in some of the tests (e.g. for delete_branch). We
# use this instead of the equivalent GitRepo::getbranch so we can test
# different GitRepo functionality independently.
- branch = str(git("rev-parse", "--abbrev-ref", "HEAD"))
# git rev-parse returns a trailing newline that we must get rid of
- return branch[:-1]
+ return git("rev-parse", "--abbrev-ref", "HEAD").rstrip()
# This class is only used to test the GitRepo functions since, as an,
# abstract-baseclass, GitRepo doesn't define repodir, and we need an
@@ -321,8 +317,7 @@ class TestGitRepo(unittest.TestCase):
def test_getbranch(self):
with cd(self.dgr.repodir):
try:
- git("checkout", "-b", "master_test",
- "origin/master").stdout.rstrip()
+ git("checkout", "-b", "master_test", "origin/master")
except ErrorReturnCode as exc:
raise EnvironmentError(
"Unable to checkout -b %s %s" % (branch, track))
diff --git a/linaropy/rn/rngen.py b/linaropy/rn/rngen.py
index 7daae9e..90a44f6 100644
--- a/linaropy/rn/rngen.py
+++ b/linaropy/rn/rngen.py
@@ -135,7 +135,7 @@ def rngen(rn_series, gccclone, history):
# Verify that the basis url is actually valid, otherwise the release notes
# will contain erroneous information.
- url = urllib2
+ url = urllib
try:
ret = urllib.request.urlopen(basis_url)
except url.URLError as e:
@@ -226,8 +226,6 @@ def rngen(rn_series, gccclone, history):
major=ver['major'],
minor=ver['minor'])
- source_textile_rendering = source_textile_rendering.encode('utf-8')
-
out_source = '' + outfile
out_binary = 'Linaro-' + outfile
@@ -269,7 +267,6 @@ def rngen(rn_series, gccclone, history):
stab_maint=stab_maint,
snap_rc_release=release_type)
- binary_textile_rendering = binary_textile_rendering.encode('utf-8')
try:
with open(out_binary + '.textile', 'w') as f:
f.write(binary_textile_rendering)
@@ -308,7 +305,6 @@ def rngen(rn_series, gccclone, history):
stab_maint=stab_maint,
snap_rc_release=release_type)
- announce_rendering = announce_rendering.encode('utf-8')
announce_file = 'announce-' + out_binary + '.txt'
try:
with open(announce_file, 'w') as f: