class Deployment(object):
"""Represents a deployment of an autoinstall; i.e. a concrete
directory in web_scripts that has .scripts-version in it."""
- def __init__(self, location, version):
+ def __init__(self, location, log=None, version=None):
+ """ `location` Location of the deployment
+ `version` ApplicationVersion of the app (this is cached info)
+ `log` DeployLog of the app"""
# XXX: This constructor should change
self.location = location
- self.version = version
+ self._version = version
+ self._log = log
+ # Maybe should be an accessor
self.application = version.application
@staticmethod
def parse(line):
else:
raise DeploymentParseError
try:
- return Deployment(location, applications[app].getVersion(version))
+ return Deployment(location, version=applications[app].getVersion(version))
except KeyError:
raise NoSuchApplication
@staticmethod
"""Creates a deployment from a directory"""
version_file = os.path.join(dir, '.scripts-version')
# needs deployment log
+ def getLog(self):
+ if not self._log:
+ # XXX: Load the deployment log
+ raise NotImplemented
+ return self._log
+ def getVersion(self):
+ """Returns the distutils Version of the deployment"""
+ return self.getAppVersion().version
+ def getAppVersion(self, force = False):
+ """Returns the ApplicationVersion of the deployment"""
+ if self._version and not force: return self._version
+ else: return self.getLog()[-1].version
+ # XXX: This is summary specific code
def count(self):
"""Simple method which registers the deployment as a +1 on the
appropriate version. No further inspection is done."""
- self.version.count(self)
+ self.getAppVersion().count(self)
return True
def count_exists(self, file):
"""Checks if the codebase has a certain file/directory in it."""
if os.path.exists(self.location + "/" + file):
- self.version.count_exists(self, file)
+ self.getAppVersion().count_exists(self, file)
return True
return False
ret.append("%d users have %s" % (c,f))
return "\n".join(ret)
-class DeployLog(object):
+class DeployLog(list):
+ # As per #python; if you decide to start overloading magic methods,
+ # we should remove this subclass
"""Equivalent to .scripts-version: a series of DeployRevisions."""
def __init__(self, revs = []):
"""`revs` List of DeployRevision objects"""
- self.revs = revs
+ # pass to list
+ list.__init__(self, revs)
@staticmethod
def load(file):
"""Loads a scripts version file and parses it into
i += 1
if i: revs.append(rev)
return DeployLog(revs)
+ def __repr__(self):
+ return '<DeployLog %s>' % list.__repr__(self)
class DeployRevision(object):
"""A single entry in the .scripts-version file. Contains who deployed