summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan S. Arnold <ryan.arnold@linaro.org>2016-08-20 14:53:56 -0500
committerRyan S. Arnold <ryan.arnold@linaro.org>2016-08-20 14:53:56 -0500
commita52c1b3a3721a5e7e922cf461b358364a4424643 (patch)
treeb60957378717be3531937687dc6e272d358de14f
parent897b858b24b10b83cbba63fb4c6506d916af5af3 (diff)
Replaced Series __format__ with a cleaner implementation and testcases.
-rw-r--r--linaropy/rn/linaroseries.py30
-rw-r--r--linaropy/rn/rngen.py4
-rw-r--r--linaropy/rn/rnseries.py22
-rw-r--r--linaropy/series.py544
-rw-r--r--linaropy/vers.py3
5 files changed, 518 insertions, 85 deletions
diff --git a/linaropy/rn/linaroseries.py b/linaropy/rn/linaroseries.py
index c92ad84..9344789 100644
--- a/linaropy/rn/linaroseries.py
+++ b/linaropy/rn/linaroseries.py
@@ -172,7 +172,7 @@ class TestLinaroSeries(unittest.TestCase):
def test_candidate_to_candidate(self):
candidate=LinaroSeries("candidate", package="GCC-5.3.1", date=datetime(2016,05,15), spin="1", rc="1")
candidate2=candidate.toNextCandidate()
- self.assertEqual(candidate2.getBranchname(), "releases/linaro-5.3-2016.05-1-rc2")
+ self.assertEqual(candidate2.branchname(), "releases/linaro-5.3-2016.05-1-rc2")
self.assertEqual(candidate2.seriestype, Series.series.index("candidate"))
self.assertEqual(candidate.date, candidate2.date)
@@ -182,14 +182,14 @@ class TestLinaroSeries(unittest.TestCase):
# Test where spin is None and needs to be incremented.
release=LinaroSeries("release", package="GCC-5.3.1", date=datetime(2016,05,15))
candidate=release.toNextCandidate()
- self.assertEqual(candidate.getBranchname(), "releases/linaro-5.3-2016.05-1-rc1")
+ self.assertEqual(candidate.branchname(), "releases/linaro-5.3-2016.05-1-rc1")
self.assertEqual(candidate.seriestype, Series.series.index("candidate"))
self.assertEqual(candidate.date, release.date)
# Now test where spin is already non-zero.
release2=LinaroSeries("release", package="GCC-5.3.1", date=datetime(2016,05,15), spin="1")
candidate2=release2.toNextCandidate()
- self.assertEqual(candidate2.getBranchname(), "releases/linaro-5.3-2016.05-2-rc1")
+ self.assertEqual(candidate2.branchname(), "releases/linaro-5.3-2016.05-2-rc1")
self.assertEqual(candidate2.seriestype, Series.series.index("candidate"))
#TODO test date and strict=True
@@ -197,7 +197,7 @@ class TestLinaroSeries(unittest.TestCase):
def test_snapshot_to_candidate(self):
snapshot=LinaroSeries("snapshot", package="GCC-5.3.1", date=datetime(2016,05,15), spin="6")
candidate=snapshot.toNextCandidate()
- self.assertEqual(candidate.getBranchname(), "releases/linaro-5.3-2016.06-rc1")
+ self.assertEqual(candidate.branchname(), "releases/linaro-5.3-2016.06-rc1")
self.assertEqual(candidate.seriestype, Series.series.index("candidate"))
self.assertNotEqual(candidate.date, snapshot.date)
# Verify that it's one month apart.
@@ -234,12 +234,12 @@ class TestLinaroSeries(unittest.TestCase):
def test_candidate_to_release(self):
candidate=LinaroSeries("candidate", package="GCC-5.3.1", date=datetime(2016,05,15), spin="1", rc="1")
release=candidate.toNextRelease()
- self.assertEqual(release.getBranchname(), "releases/linaro-5.3-2016.05-1")
+ self.assertEqual(release.branchname(), "releases/linaro-5.3-2016.05-1")
self.assertEqual(release.seriestype, Series.series.index("release"))
self.assertEqual(candidate.date, release.date)
release2=candidate.toNextRelease(strict=True)
- self.assertEqual(release2.getBranchname(), "releases/linaro-5.3-2016.05-1")
+ self.assertEqual(release2.branchname(), "releases/linaro-5.3-2016.05-1")
self.assertEqual(release2.date, candidate.date)
with self.assertRaises(ValueError):
@@ -248,7 +248,7 @@ class TestLinaroSeries(unittest.TestCase):
# If strict=False and the date is changed, go ahead and change it.
release4=candidate.toNextRelease(date=datetime.strptime("2016.06.15", "%Y.%m.%d"), strict=False)
- self.assertEqual(release4.getBranchname(), "releases/linaro-5.3-2016.06-1")
+ self.assertEqual(release4.branchname(), "releases/linaro-5.3-2016.06-1")
self.assertNotEqual(release4.date, release.date)
with self.assertRaises(TypeError):
@@ -287,16 +287,16 @@ class TestLinaroSeries(unittest.TestCase):
snapshot=LinaroSeries("snapshot", package="GCC-5.3.1", date=datetime(2016,05,15), spin="6")
snapshot2=snapshot.toNextSnapshot()
- self.assertEqual(snapshot2.getBranchname(), "snapshots/linaro-5.3-2016.05-7")
+ self.assertEqual(snapshot2.branchname(), "snapshots/linaro-5.3-2016.05-7")
self.assertEqual(snapshot2.seriestype, Series.series.index("snapshot"))
self.assertEqual(snapshot.date, snapshot2.date)
# Verify that the original hasn't changed. This verifies that a
# deepcopy is used on the toNext* functions.
- self.assertEqual(snapshot.getBranchname(), "snapshots/linaro-5.3-2016.05-6")
+ self.assertEqual(snapshot.branchname(), "snapshots/linaro-5.3-2016.05-6")
snapshot3=snapshot.toNextSnapshot(strict=True)
- self.assertEqual(snapshot3.getBranchname(), "snapshots/linaro-5.3-2016.05-7")
+ self.assertEqual(snapshot3.branchname(), "snapshots/linaro-5.3-2016.05-7")
self.assertEqual(snapshot3.seriestype, Series.series.index("snapshot"))
self.assertEqual(snapshot.date, snapshot3.date)
@@ -306,7 +306,7 @@ class TestLinaroSeries(unittest.TestCase):
# If strict=False and the date is changed, go ahead and change it.
snapshot5=snapshot.toNextSnapshot(date=datetime.strptime("2016.06.15", "%Y.%m.%d"), strict=False)
- self.assertEqual(snapshot5.getBranchname(), "snapshots/linaro-5.3-2016.06-7")
+ self.assertEqual(snapshot5.branchname(), "snapshots/linaro-5.3-2016.06-7")
self.assertNotEqual(snapshot5.date, snapshot.date)
# Verify that a date as a string generates an exception.
@@ -322,19 +322,19 @@ class TestLinaroSeries(unittest.TestCase):
def test_snapshot_toNext(self):
snapshot=LinaroSeries("snapshot", package="GCC-5.3.1", date=datetime(2016,05,15), spin="1")
- self.assertEqual(snapshot.getBranchname(), "snapshots/linaro-5.3-2016.05-1")
+ self.assertEqual(snapshot.branchname(), "snapshots/linaro-5.3-2016.05-1")
candidate=snapshot.toNext("candidate")
# A Snapshot -> Candidate traversal always results in spin being set to zero
# and the first release candidate being created.
- self.assertEqual(candidate.getBranchname(), "releases/linaro-5.3-2016.06-rc1")
+ self.assertEqual(candidate.branchname(), "releases/linaro-5.3-2016.06-rc1")
self.assertEqual(candidate.seriestype, Series.series.index("candidate"))
# Make sure toNext works with 'index' as well as the type string.
candidate2=snapshot.toNext(Series.series.index("candidate"))
# A Snapshot -> Candidate traversal always results in spin being set to zero
# and the first release candidate being created.
- self.assertEqual(candidate2.getBranchname(), "releases/linaro-5.3-2016.06-rc1")
+ self.assertEqual(candidate2.branchname(), "releases/linaro-5.3-2016.06-rc1")
self.assertEqual(candidate2.seriestype, Series.series.index("candidate"))
with self.assertRaises(TypeError):
@@ -343,7 +343,7 @@ class TestLinaroSeries(unittest.TestCase):
def test_toNext_incorrect_keys(self):
snapshot=LinaroSeries("snapshot", package="GCC-5.3.1", date=datetime(2016,05,15), spin="1")
- self.assertEqual(snapshot.getBranchname(), "snapshots/linaro-5.3-2016.05-1")
+ self.assertEqual(snapshot.branchname(), "snapshots/linaro-5.3-2016.05-1")
with self.assertRaises(KeyError):
candidate=snapshot.toNext("candidat")
candidate=snapshot.toNext("snapsho")
diff --git a/linaropy/rn/rngen.py b/linaropy/rn/rngen.py
index bfbb05b..96824e3 100644
--- a/linaropy/rn/rngen.py
+++ b/linaropy/rn/rngen.py
@@ -46,14 +46,14 @@ def rngen(rn_series, gccclone):
trackseries=rn_series.track_series
nextseries=rn_series.next_series
- print "toNext: " + nextseries.getBranchname()
+ print "toNext: " + nextseries.branchname()
print "toNext: " + format(nextseries, '%N/%d')
# TODO: What if 'track' is not a snapshot branch? To do this right we'd
# probably have to preserve basedon information in the release notes
# repository as a yaml file.
basedon='http://snapshots.linaro.org/components/toolchain/gcc-linaro/'
- basedon=basedon + trackseries.getDir()
+ basedon=basedon + trackseries.get_dir()
print "basedon: " + basedon
basis_url=basedon
diff --git a/linaropy/rn/rnseries.py b/linaropy/rn/rnseries.py
index 284e6d9..6d8a3c4 100644
--- a/linaropy/rn/rnseries.py
+++ b/linaropy/rn/rnseries.py
@@ -81,7 +81,7 @@ class RNSeries(object):
repository will be created.
"""
templ_branchname=self.next_series.shorttype()
- templ_branchname + templ_branchname + "_" + self.next_series.getDir()
+ templ_branchname + templ_branchname + "_" + self.next_series.get_dir()
if not self.rn_template:
logging.info("Creating the RNTemplate instance.")
self.rn_template=RNTemplate(
@@ -132,14 +132,14 @@ class RNSeries(object):
"The rn_template doesn't yet exist. Call"
" update_template_readmes() first.")
- remote_track=self.rn_clone.remote_branchname(self.track_series.getBranchname())
+ remote_track=self.rn_clone.remote_branchname(self.track_series.branchname())
if not self.rn_series:
- print("Looking for branch %s" % self.track_series.getBranchname())
+ print("Looking for branch %s" % self.track_series.branchname())
# The workdir for the first candidate series will be derived from
# the changes made to the master branch templates. The workdir for
# subsequent candidates and releases will be made based on the
# existing candidate or release branch.
- #if not self.rn_clone.branchexists(self.track_series.getBranchname()):
+ #if not self.rn_clone.branchexists(self.track_series.branchname()):
if not self.rn_clone.branchexists(remote_track):
logging.info(
"Creating RNSeries based on branch "
@@ -150,20 +150,20 @@ class RNSeries(object):
clone=self.rn_clone,
workdir=self.next_series.shorttype(),
track=self.rn_template.getbranch(),
- branchname=self.next_series.getBranchname())
+ branchname=self.next_series.branchname())
else:
logging.info(
"MARK Creating RNSeries based on branch "
+ remote_track)
- # + self.track_series.getBranchname())
+ # + self.track_series.branchname())
self.rn_series=Workdir(
proj=self.proj,
clone=self.rn_clone,
workdir=self.next_series.shorttype(),
track=remote_track,
- branchname=self.next_series.getBranchname())
- #track=self.track_series.getBranchname(),
+ branchname=self.next_series.branchname())
+ #track=self.track_series.branchname(),
logging.warning(
"If you updated the template README.textile.series file"
@@ -172,7 +172,7 @@ class RNSeries(object):
" Please make the changes to the series"
" README.textile.series file as well." %
remote_track)
- # self.track_series.getBranchname())
+ # self.track_series.branchname())
# TODO: Ask if the user would like to merge the changes in
# the template README.textile.series file instead of the
@@ -186,14 +186,14 @@ class RNSeries(object):
self.rn_series.edit(self._series)
return self.rn_series.commit(
- "Added NEWS items for %s." % self.next_series.getBranchname())
+ "Added NEWS items for %s." % self.next_series.branchname())
def push_readme_updates(self):
pass
# TODO: Don't forget to push template and workdir changes.
# self.rn_template.pushToBranch("origin/master")
# TODO: Should the workdir know where to push to?
- # self.rn_series.pushToBranch(self.next_series.getBranchname())
+ # self.rn_series.pushToBranch(self.next_series.branchname())
class TestSeriesRN(unittest.TestCase):
pass
diff --git a/linaropy/series.py b/linaropy/series.py
index cad1e31..16e70a5 100644
--- a/linaropy/series.py
+++ b/linaropy/series.py
@@ -3,6 +3,8 @@ import logging
import os
import uuid
import string
+from collections import OrderedDict
+import copy
from vers import Spin
from vers import Rc
@@ -132,60 +134,186 @@ class Series(object):
if self.seriestype == Series.series.index("candidate") and self.rc.val is 0:
raise TypeError('A candidate series must have an rc specified.')
- # namespace/vendor-package-version-YYYY.MM-spin-rc
- self.fmt = {
- '%N': self.getNamespace,
- '%L': self.serieslabel,
- '%P': self._getPackageName,
- '%p': self._getPackageNameLower,
- '%V': self._getVendor,
- '%v': self._getVendorLower,
- '%E': self._getVersion,
- '%D': self._getYYYYMM,
- '%d': self.getDir,
- '%S': self._getSpin,
- '%R': self._getRc,
- }
+ # We need an OrderedDict because we want to parse/capture -%X and .%X
+ # before %X and a regular dict won't guarantee that iterkeys returns in
+ # the inserted order.. This dict starts out empty and we'll populate it
+ # in the same way we will udpate it later. This is used for the
+ # __format__ function for quick formatting.
+ self.fmt=OrderedDict()
+ self.fmt['%N'] = None
+ self.fmt['-%L'] = None
+ self.fmt['.%L'] = None
+ self.fmt['%L'] = None
+ self.fmt['%P'] = None
+ self.fmt['%l'] = None
+ self.fmt['%V'] = None
+ self.fmt['%v'] = None
+ self.fmt['%E'] = None
+ self.fmt['%e'] = None
+ self.fmt['%M'] = None
+ self.fmt['%m'] = None
+ self.fmt['%p'] = None
+ self.fmt['%D'] = None
+ self.fmt['%h'] = None
+ self.fmt['%d'] = None
+ # Match and strip the key '-' as Spin might be empty.
+ self.fmt['-%S'] = None
+ # Match and strip the key '.' as Spin might be empty.
+ self.fmt['.%S'] = None
+ self.fmt['%S'] = None
+ # Match and strip the key '-' as Rc might be empty.
+ self.fmt['-%R'] = None
+ # Match and strip the key '.' as Rc might be empty.
+ self.fmt['.%R'] = None
+ self.fmt['%R'] = None
+
+ # Fill in the values.
+ for key in self.fmt.iterkeys():
+ self.update_fmtdict(key)
+
+ def update_fmtdict(self, key):
+ if key == '%N':
+ self.fmt['%N'] = self.get_namespace()
+ elif key == '-%L':
+ self.fmt['-%L'] = self.serieslabel()
+ return
+ elif key == '.%L':
+ # Only prepend '.' if there's actually a series label.
+ label = self.serieslabel()
+ self.fmt['.%L'] = string.replace(label,'-','.')
+ return
+ elif key == '%L':
+ self.fmt['%L'] = self.serieslabel().strip('-')
+ return
+ elif key == '%P':
+ self.fmt['%P'] = self.package.package
+ elif key == '%l':
+ self.fmt['%l'] = self.package.package.lower()
+ elif key == '%V':
+ self.fmt['%V'] = str(self.vendor)
+ elif key == '%v':
+ self.fmt['%v'] = self.vendor.lower()
+ elif key == '%E':
+ self.fmt['%E'] = self.package.version.strfversion("%M%m")
+ elif key == '%e':
+ self.fmt['%e'] = self.package.version.strfversion("%M%m%p")
+ elif key == '%M':
+ self.fmt['%M'] = self.package.version.strfversion("%M")
+ elif key == '%m':
+ self.fmt['%m'] = self.package.version.strfversion("%m")
+ elif key == '%p':
+ self.fmt['%p'] = self.package.version.strfversion("%p")
+ elif key == '%D':
+ self.fmt['%D'] = self.date.strftime("%Y.%m")
+ elif key == '%h':
+ self.fmt['%h'] = self.get_server()
+ elif key == '%d':
+ self.fmt['%d'] = self.get_dir()
+ elif key == '-%S':
+ # This will include the '-' if present.
+ self.fmt['-%S'] = str(self.spin)
+ elif key == '.%S':
+ spin=str(self.spin)
+ self.fmt['.%S'] = string.replace(spin,'-','.')
+ elif key == '%S':
+ self.fmt['%S'] = str(self.spin).strip('-')
+ elif key == '-%R':
+ # This will include the '-' is present.
+ self.fmt['-%R'] = str(self.rc)
+ elif key == '.%R':
+ rc=str(self.rc)
+ self.fmt['.%R'] = string.replace(rc,'-','.')
+ elif key == '%R':
+ self.fmt['%R'] = str(self.rc).strip('-')
+ else:
+ raise KeyError('Unknown format key.')
+ def __format__(self,format_spec):
+ """
+ Format an output string based on format spec.
- def _getPackageName(self):
- return self.package.package
+ This function will take a format spec which includes mixture of text to
+ be preserved as well as format designators which indicate series
+ information to be substituted in place. Take the following format_spec:
- def _getPackageNameLower(self):
- return self.package.lower()
+ "%V released this product"
- def _getVendor(self):
- return self.vendor.__str__()
+ This would be formatted as "Linaro released this product"
+
+ call using:
+
+ formattedstr=format(series_instance, 'string_with_delimiters')
- def _getVendorLower(self):
- return self.vendor.lower()
+ delimiters
+ ----------
- def _getVersion(self):
- return self.package.version.strfversion("%M%m")
+ %N : git repository branch namespace.
- def _getYYYYMM(self):
- return self.date.strftime("%Y.%m")
+ %L : series label
- def _getSpin(self):
- return str(self.spin).strip('-')
+ This is only valid for snapshots. Releases and candidates will
+ result in an empty string.
- def _getRc(self):
- return str(self.rc).strip('-')
+ Note: This is special. If -%L or .%L is in the format_spec and
+ there is no series label (for release and candidates) then the
+ leading '-' or '.' will be stripped as well.
+
+ %P : package name
- def __format__(self,format_spec):
+ %l : lowercase package name
+
+ %V : vendor
+
+ %v : lowercase vendor
+
+ %E : Version Major.Minor
+ Note: if Minor doen't exist the . delimiter won't be displayed.
+
+ %E : Version Major.Minor.Point
+ Note: if Minor or Point don't exist the . delimiters won't be
+ displayed.
+
+ %M : Version Major
+
+ %m : Version Minor
+ Note: if Minor doesn't exist the . delimiter won't be displayed.
+
+ %p : Version Point
+ Note: if Point doesn't exist the . delimiter won't be displayed.
+
+ %D : Series date in YYYY.MM format.
+
+ %h : snapshot or release server.
+
+ %d : Series dir representation.
+
+ %S : Spin number
+ Note: This is special. If -%S or .%S is in the format_spec and
+ there is no Spin then the leading '-' or '.' will be stripped as
+ well.
+
+ %R : Rc number
+ Note: This is special. If -%R or .%R is in the format_spec and
+ there is no Rc then the leading '-' or '.' will be stripped as
+ well.
+ """
ret=''
- # Iterate across the dictionary and for each key found and invoke the
- # function.
+ # Iterate across the dictionary and for each key found replace the key
+ # with the contents of the fmt dictionary.
ret=format_spec
for key in self.fmt.iterkeys():
- replac=self.fmt[key]()
- ret=string.replace(ret,key,replac)
+ if key in ret:
+ # Update the relevant keys everytime through because the user
+ # might have changed things.
+ self.update_fmtdict(key)
+ replac=self.fmt[key]
+ ret=string.replace(ret,key,replac)
return ret
def serieslabel(self):
# Only the 'snapshot-' is used in a label.
if self.seriestype == Series.series.index("snapshot"):
- return Series.series[self.seriestype] + u'-'
+ return u'-' + Series.series[self.seriestype]
else:
return u''
@@ -202,7 +330,7 @@ class Series(object):
return Series.series[self.seriestype] + "_" + self.uniqueid
def label(self):
- label=str(self.vendor) + u'-' + self.serieslabel() + str(self.package)
+ label=str(self.vendor) + self.serieslabel() + u'-' + str(self.package)
label=label + u'-' + self.date.strftime("%Y.%m")
label=label + str(self.spin) + str(self.rc)
return label
@@ -210,14 +338,20 @@ class Series(object):
def incrementMonth(self):
self.date = self.date + relativedelta(months=1)
- def getDir(self):
+ def get_dir(self):
dirstr=self.package.version.strfversion("%M%m")
dirstr=dirstr + u'-' + self.date.strftime("%Y.%m")
dirstr=dirstr + str(self.spin)
dirstr=dirstr + str(self.rc)
return dirstr
- def getNamespace(self):
+ def get_server(self):
+ namespace=u'snapshots'
+ if self.seriestype == Series.series.index("release"):
+ namespace=u'releases'
+ return namespace
+
+ def get_namespace(self):
namespace=u'releases'
if self.seriestype == Series.series.index("snapshot"):
namespace=u'snapshots'
@@ -225,7 +359,16 @@ class Series(object):
# TODO: Document what a conformant branch name looks like.
# Return a conformant branch name from the Series information.
- def getBranchname(self):
+ def branchname(self):
+ """
+ Return a branchname in the form of:
+
+ <namespace>/<vendor>-<package_version>-<date>-<spin>-<rc>
+
+ return value
+ ------------
+ string represensting the branch name.
+ """
branchname=u''
if self.seriestype == Series.series.index("snapshot"):
branchname=branchname + u'snapshots/'
@@ -282,7 +425,9 @@ def series_from_branchname(branch=None):
try:
seriesstr=branch.rsplit('/', 1)[1]
except IndexError:
- raise ValueError("string must delimit the namespace from the right branch with a '/' char, e.g., <namespace>/<package_name>-<package_version>")
+ raise ValueError(
+ "string must delimit the namespace from the right branch with a"
+ " '/' char, e.g., <namespace>/<vendor>-<package_version>")
# TODO: Are these necessary or did the previous cases cover it?
#if namespace == u'':
@@ -459,7 +604,7 @@ class TestSeries(unittest.TestCase):
def test_serieslabel_snapshot(self):
candidate=Series("snapshot", package="GCC-5.3.1")
- self.assertEqual(candidate.serieslabel(), "snapshot-")
+ self.assertEqual(candidate.serieslabel(), "-snapshot")
def test_empty_rc(self):
rc=Rc(7)
@@ -568,9 +713,9 @@ class TestSeries(unittest.TestCase):
def test_getbranchname(self):
candidate=Series("candidate", package="GCC-5.3.1", date=datetime(2016,05,15), spin="1", rc="1")
- self.assertEqual(candidate.getBranchname(), "releases/linaro-5.3-2016.05-1-rc1")
+ self.assertEqual(candidate.branchname(), "releases/linaro-5.3-2016.05-1-rc1")
release=Series("release", package="GCC-5.3.1", date=datetime(2016,05,15), spin="1", rc=None)
- self.assertEqual(release.getBranchname(), "releases/linaro-5.3-2016.05-1")
+ self.assertEqual(release.branchname(), "releases/linaro-5.3-2016.05-1")
def test_date_string(self):
candidate=Series("candidate", package="GCC-5.3.1", date="2016.05.27", spin="1", rc="1")
@@ -597,13 +742,13 @@ class TestSeries(unittest.TestCase):
def test_series_strict_false(self):
snapshot=Series("snapshot", package="GCC-5.3.1", date=datetime(2016,05,15), spin="6", rc="1", strict=False)
- self.assertEqual(snapshot.getBranchname(), "snapshots/linaro-5.3-2016.05-6-rc1")
+ self.assertEqual(snapshot.branchname(), "snapshots/linaro-5.3-2016.05-6-rc1")
release=Series("release", package="GCC-5.3.1", date=datetime(2016,05,15), spin="1", rc="1", strict=False)
- self.assertEqual(release.getBranchname(), "releases/linaro-5.3-2016.05-1-rc1")
+ self.assertEqual(release.branchname(), "releases/linaro-5.3-2016.05-1-rc1")
release=Series("release", package="GCC-5.3.1", date=datetime(2016,05,15), rc="1", strict=False)
- self.assertEqual(release.getBranchname(), "releases/linaro-5.3-2016.05-rc1")
+ self.assertEqual(release.branchname(), "releases/linaro-5.3-2016.05-rc1")
# These tests will verify that a branchname can be read, a series created,
# and then the same branch name recreated.
@@ -611,27 +756,27 @@ class TestSeries(unittest.TestCase):
branch2=u'snapshots/linaro-5.3-2016.05-6'
series2=series_from_branchname(branch=branch2)
- self.assertEqual(series2.getBranchname(),u'snapshots/linaro-5.3-2016.05-6')
+ self.assertEqual(series2.branchname(),u'snapshots/linaro-5.3-2016.05-6')
branch3=u'snapshots/linaro-5.3-2016.05'
series3=series_from_branchname(branch=branch3)
- self.assertEqual(series3.getBranchname(),u'snapshots/linaro-5.3-2016.05')
+ self.assertEqual(series3.branchname(),u'snapshots/linaro-5.3-2016.05')
branch4=u'releases/linaro-5.3-2016.05-6-rc1'
series4=series_from_branchname(branch=branch4)
- self.assertEqual(series4.getBranchname(),u'releases/linaro-5.3-2016.05-6-rc1')
+ self.assertEqual(series4.branchname(),u'releases/linaro-5.3-2016.05-6-rc1')
branch5=u'releases/linaro-5.3-2016.05-rc1'
series5=series_from_branchname(branch=branch5)
- self.assertEqual(series5.getBranchname(),u'releases/linaro-5.3-2016.05-rc1')
+ self.assertEqual(series5.branchname(),u'releases/linaro-5.3-2016.05-rc1')
branch6=u'releases/linaro-5.3-2016.05-6'
series6=series_from_branchname(branch=branch6)
- self.assertEqual(series6.getBranchname(),u'releases/linaro-5.3-2016.05-6')
+ self.assertEqual(series6.branchname(),u'releases/linaro-5.3-2016.05-6')
branch7=u'releases/linaro-5.3-2016.05'
series7=series_from_branchname(branch=branch7)
- self.assertEqual(series7.getBranchname(),u'releases/linaro-5.3-2016.05')
+ self.assertEqual(series7.branchname(),u'releases/linaro-5.3-2016.05')
# -rc1 is invalid with a snapshots namespace.
branch8=u'snapshots/linaro-5.3-2016.05-6-rc1'
@@ -697,7 +842,7 @@ class TestSeries(unittest.TestCase):
def test_snapshot_series_from_tag(self):
tag=u'linaro-snapshot-5.3-2016.05-6'
series=series_from_tag(tag=tag)
- self.assertEqual(series.getBranchname(),u'snapshots/linaro-5.3-2016.05-6')
+ self.assertEqual(series.branchname(),u'snapshots/linaro-5.3-2016.05-6')
def test_invalid_snapshot_series_from_tag(self):
# We can't have -rc1 on a snapshot.
@@ -708,12 +853,12 @@ class TestSeries(unittest.TestCase):
def test_candidate_series_from_tag(self):
tag=u'linaro-5.3-2016.05-6-rc1'
series=series_from_tag(tag=tag)
- self.assertEqual(series.getBranchname(),u'releases/linaro-5.3-2016.05-6-rc1')
+ self.assertEqual(series.branchname(),u'releases/linaro-5.3-2016.05-6-rc1')
def test_release_series_from_tag(self):
tag=u'linaro-5.3-2016.05-6'
series=series_from_tag(tag=tag)
- self.assertEqual(series.getBranchname(),u'releases/linaro-5.3-2016.05-6')
+ self.assertEqual(series.branchname(),u'releases/linaro-5.3-2016.05-6')
def test_series_from_tag_invalid_spin(self):
tag=u'linaro-5.3-2016.05-abc'
@@ -730,6 +875,293 @@ class TestSeries(unittest.TestCase):
with self.assertRaises(TypeError):
series=series_from_tag(tag=tag)
+class TestSeriesFormat(unittest.TestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ snaptag=u'linaro-snapshot-5.3-2016.05-6'
+ reltag=u'linaro-5.3-2016.05-6'
+ rctag=u'linaro-5.3-2016.05-6-rc1'
+ cls.snapseries=series_from_tag(tag=snaptag)
+ cls.relseries=series_from_tag(tag=reltag)
+ cls.rcseries=series_from_tag(tag=rctag)
+
+ def test_format_N_snap(self):
+ f=format(self.snapseries, '%N')
+ self.assertEquals(f,'snapshots')
+
+ def test_format_N_rel(self):
+ f=format(self.relseries, '%N')
+ self.assertEquals(f,'releases')
+
+ def test_format_N_rc(self):
+ f=format(self.rcseries, '%N')
+ self.assertEquals(f,'releases')
+
+ def test_format_dashL_snap(self):
+ f=format(self.snapseries, 'foo-%L-bar')
+ self.assertEquals(f,'foo-snapshot-bar')
+
+ def test_format_dashL_rel(self):
+ f=format(self.relseries, 'foo-%L-bar')
+ self.assertEquals(f,'foo-bar')
+
+ def test_format_dashL_rc(self):
+ f=format(self.rcseries, 'foo-%L-bar')
+ self.assertEquals(f,'foo-bar')
+
+ def test_format_dotL_snap(self):
+ f=format(self.snapseries, 'foo.%L.bar')
+ self.assertEquals(f,'foo.snapshot.bar')
+
+ def test_format_dotL_rel(self):
+ f=format(self.relseries, 'foo.%L.bar')
+ self.assertEquals(f,'foo.bar')
+
+ def test_format_dotL_rc(self):
+ f=format(self.rcseries, 'foo.%L.bar')
+ self.assertEquals(f,'foo.bar')
+
+ def test_format_L_snap(self):
+ f=format(self.snapseries, 'foo%Lbar')
+ self.assertEquals(f,'foosnapshotbar')
+
+ def test_format_L_rel(self):
+ f=format(self.relseries, 'foo%Lbar')
+ self.assertEquals(f,'foobar')
+
+ def test_format_L_rc(self):
+ f=format(self.rcseries, 'foo%Lbar')
+ self.assertEquals(f,'foobar')
+
+ def test_format_dashP(self):
+ f=format(self.snapseries, 'foo-%P-bar')
+ self.assertEquals(f,'foo-GCC-bar')
+
+ def test_format_dotP(self):
+ f=format(self.snapseries, 'foo.%P.bar')
+ self.assertEquals(f,'foo.GCC.bar')
+
+ def test_format_P(self):
+ f=format(self.snapseries, 'foo%Pbar')
+ self.assertEquals(f,'fooGCCbar')
+
+ def test_format_dashl(self):
+ f=format(self.snapseries, 'foo-%l-bar')
+ self.assertEquals(f,'foo-gcc-bar')
+
+ def test_format_dotl(self):
+ f=format(self.snapseries, 'foo.%l.bar')
+ self.assertEquals(f,'foo.gcc.bar')
+
+ def test_format_l(self):
+ f=format(self.snapseries, 'foo%lbar')
+ self.assertEquals(f,'foogccbar')
+
+ def test_format_V(self):
+ f=format(self.snapseries, 'foo.%V.bar')
+ self.assertEquals(f,'foo.Linaro.bar')
+
+ def test_format_v(self):
+ f=format(self.snapseries, 'foo.%v.bar')
+ self.assertEquals(f,'foo.linaro.bar')
+
+ def test_format_E(self):
+ f=format(self.snapseries, 'gcc-%E')
+ self.assertEquals(f,'gcc-5.3')
+
+ # This shouldn't show a trailing - after the minor because of a point.
+ def test_format_E_with_fabricated_minor(self):
+ minorseries=copy.deepcopy(self.snapseries)
+ minorseries.package.version.point=9
+ f=format(minorseries, 'gcc-%E')
+ self.assertEquals(f,'gcc-5.3')
+
+ def test_format_e(self):
+ f=format(self.snapseries, 'gcc-%e')
+ self.assertEquals(f,'gcc-5.3')
+
+ def test_format_e_fabricate_minor(self):
+ minorseries=copy.deepcopy(self.snapseries)
+ minorseries.package.version.point=9
+ f=format(minorseries, 'gcc-%e')
+ self.assertEquals(f,'gcc-5.3.9')
+
+ def test_format_M(self):
+ f=format(self.snapseries, 'gcc-%M')
+ self.assertEquals(f,'gcc-5')
+
+ def test_format_m(self):
+ f=format(self.snapseries, 'gcc-X.%m')
+ self.assertEquals(f,'gcc-X.3')
+
+ def test_format_p(self):
+ f=format(self.snapseries, 'gcc-X.Y.%p')
+ self.assertEquals(f,'gcc-X.Y.')
+
+ def test_format_p_fabricate_minor(self):
+ minorseries=copy.deepcopy(self.snapseries)
+ minorseries.package.version.point=9
+ f=format(minorseries, 'gcc-X.Y.%p')
+ self.assertEquals(f,'gcc-X.Y.9')
+
+ def test_format_D(self):
+ f=format(self.snapseries, 'foo-%D-bar')
+ self.assertEquals(f,'foo-2016.05-bar')
+
+ def test_format_snap_h(self):
+ f=format(self.snapseries, 'http://%h.')
+ self.assertEquals(f,'http://snapshots.')
+
+ def test_format_release_h(self):
+ f=format(self.relseries, 'http://%h.')
+ self.assertEquals(f,'http://releases.')
+
+ def test_format_snap_h(self):
+ f=format(self.snapseries, 'http://%h.')
+ self.assertEquals(f,'http://snapshots.')
+
+ def test_format_snap_d(self):
+ f=format(
+ self.snapseries,
+ 'http://%h.linaro.org/components/toolchain/binaries/%d')
+ self.assertEquals(
+ f,
+ 'http://snapshots.linaro.org/components/'
+ 'toolchain/binaries/5.3-2016.05-6')
+
+ def test_format_rel_d(self):
+ f=format(
+ self.relseries,
+ 'http://%h.linaro.org/components/toolchain/binaries/%d')
+ self.assertEquals(
+ f,
+ 'http://releases.linaro.org/components/'
+ 'toolchain/binaries/5.3-2016.05-6')
+
+ def test_format_rc_d(self):
+ f=format(
+ self.rcseries,
+ 'http://%h.linaro.org/components/toolchain/binaries/%d')
+ self.assertEquals(
+ f,
+ 'http://snapshots.linaro.org/components/'
+ 'toolchain/binaries/5.3-2016.05-6-rc1')
+
+ def test_format_snap_d(self):
+ f=format(
+ self.snapseries,
+ 'http://%h.linaro.org/components/toolchain/binaries/%d')
+ self.assertEquals(
+ f,
+ 'http://snapshots.linaro.org/components/'
+ 'toolchain/binaries/5.3-2016.05-6')
+
+ def test_format_rel_d(self):
+ f=format(
+ self.relseries,
+ 'http://%h.linaro.org/components/toolchain/binaries/%d')
+ self.assertEquals(
+ f,
+ 'http://releases.linaro.org/components/'
+ 'toolchain/binaries/5.3-2016.05-6')
+
+ def test_format_rc_d(self):
+ f=format(
+ self.rcseries,
+ 'http://%h.linaro.org/components/toolchain/binaries/%d')
+ self.assertEquals(
+ f,
+ 'http://snapshots.linaro.org/components/'
+ 'toolchain/binaries/5.3-2016.05-6-rc1')
+
+ def test_format_snap_d(self):
+ f=format(
+ self.snapseries,
+ 'http://%h.linaro.org/components/toolchain/binaries/%d')
+ self.assertEquals(
+ f,
+ 'http://snapshots.linaro.org/components/'
+ 'toolchain/binaries/5.3-2016.05-6')
+
+ def test_format_rel_d(self):
+ f=format(
+ self.relseries,
+ 'http://%h.linaro.org/components/toolchain/binaries/%d')
+ self.assertEquals(
+ f,
+ 'http://releases.linaro.org/components/'
+ 'toolchain/binaries/5.3-2016.05-6')
+
+ def test_format_rc_d(self):
+ f=format(
+ self.rcseries,
+ 'http://%h.linaro.org/components/toolchain/binaries/%d')
+ self.assertEquals(
+ f,
+ 'http://snapshots.linaro.org/components/'
+ 'toolchain/binaries/5.3-2016.05-6-rc1')
+
+ def test_format_dashS(self):
+ f=format(self.snapseries, 'foo-%S-bar')
+ self.assertEquals(f,'foo-6-bar')
+
+ def test_format_dashS_no_spin(self):
+ nospinseries=copy.deepcopy(self.snapseries)
+ nospinseries.spin=Spin()
+ f=format(nospinseries, 'foo-%S-bar')
+ self.assertEquals(f,'foo-bar')
+
+ def test_format_dotS(self):
+ f=format(self.snapseries, 'foo.%S.bar')
+ self.assertEquals(f,'foo.6.bar')
+
+ def test_format_dotS_no_spin(self):
+ nospinseries=copy.deepcopy(self.snapseries)
+ nospinseries.spin=Spin()
+ f=format(nospinseries, 'foo.%S.bar')
+ self.assertEquals(f,'foo.bar')
+
+ def test_format_S(self):
+ f=format(self.snapseries, 'foo%Sbar')
+ self.assertEquals(f,'foo6bar')
+
+ def test_format_S_no_spin(self):
+ nospinseries=copy.deepcopy(self.snapseries)
+ nospinseries.spin=Spin()
+ f=format(nospinseries, 'foo%Sbar')
+ self.assertEquals(f,'foobar')
+
+ def test_format_dashR(self):
+ f=format(self.rcseries, '2016.05-6-%R')
+ self.assertEquals(f,'2016.05-6-rc1')
+
+ def test_format_dashR_fabricate_norc(self):
+ norcseries=copy.deepcopy(self.rcseries)
+ norcseries.rc=Rc()
+ f=format(norcseries, '2016.05-6-%R')
+ self.assertEquals(f,'2016.05-6')
+
+ def test_format_dotR(self):
+ f=format(self.rcseries, '2016.05-6.%R')
+ self.assertEquals(f,'2016.05-6.rc1')
+
+ def test_format_dotR_fabricate_norc(self):
+ norcseries=copy.deepcopy(self.rcseries)
+ norcseries.rc=Rc()
+ f=format(norcseries, '2016.05-6.%R')
+ self.assertEquals(f,'2016.05-6')
+
+ def test_format_R(self):
+ f=format(self.rcseries, '2016.05-6-%R')
+ self.assertEquals(f,'2016.05-6-rc1')
+
+ def test_format_R_fabricate_norc(self):
+ norcseries=copy.deepcopy(self.rcseries)
+ norcseries.rc=Rc()
+ f=format(norcseries, '2016.05-6#%R')
+ self.assertEquals(f,'2016.05-6#')
+
if __name__ == '__main__':
#logging.basicConfig(level="INFO")
unittest.main()
diff --git a/linaropy/vers.py b/linaropy/vers.py
index 2804692..7e8c2f1 100644
--- a/linaropy/vers.py
+++ b/linaropy/vers.py
@@ -92,7 +92,8 @@ class Version(object):
elif tok == 'm':
vers=vers + str(self.minor)
elif tok == 'p':
- vers=vers + str(self.point)
+ if self.point:
+ vers=vers + str(self.point)
if numtoks > 0:
vers=vers + delimiter
numtoks=numtoks-1