return fileinput.input([vs])
return fileinput.input([vs + "/" + f for f in os.listdir(vs)])
+def parse_install_lines(show, options, yield_errors = False):
+ if not show: show = applications()
+ show = frozenset(show)
+ for line in getInstallLines(options.versions_path):
+ # construction
+ try:
+ d = Deployment.parse(line)
+ name = d.application.name
+ except deploy.NoSuchApplication as e:
+ if yield_errors:
+ yield e
+ continue
+ except deploy.Error:
+ # we consider this a worse error
+ logging.warning("Error with '%s'" % line.rstrip())
+ continue
+ # filter
+ if name + "-" + str(d.version) in show or name in show:
+ pass
+ else:
+ continue
+ # yield
+ yield d
+
## -- Model Objects --
class Deployment(object):
`version` ApplicationVersion of the app (this is cached info)
`log` DeployLog of the app"""
self.location = location
- self._version = version
+ self._app_version = version
self._log = log
+ self._read_cache = {}
+ def read(self, file, force = False):
+ """Reads a file's contents and stuffs it in a cache"""
+ if force or file not in self._read_cache:
+ f = open(os.path.join(self.location, file))
+ self._read_cache[file] = f.read()
+ f.close()
+ return self._read_cache[file]
+ def extract(self):
+ return self.application.extract(self)
+ def updateVersion(self, version=None):
+ """`version` Version string to update to, or leave out to simply
+ force the creation of .scripts/version file"""
+ if not version:
+ version = str(self.version)
+ else:
+ self._app_version = self.application.makeVersion(version)
+ f = open(os.path.join(self.scripts_dir, 'version'), 'w')
+ f.write(self.application.name + '-' + version + "\n")
+ f.close()
+ @property
+ def scripts_dir(self):
+ return os.path.join(self.location, '.scripts')
@property
def version_file(self):
return os.path.join(self.location, '.scripts-version')
@property
def app_version(self, force = False):
"""Returns the ApplicationVersion of the deployment"""
- if self._version and not force: return self._version
+ if self._app_version and not force: return self._app_version
else: return self.log[-1].version
@staticmethod
def parse(line):
def __init__(self, name):
self.name = name
self.versions = {}
+ self._extractors = {}
@property
def repository(self):
"""Returns the Git repository that would contain this application."""
if version not in self.versions:
self.versions[version] = ApplicationVersion(distutils.version.LooseVersion(version), self)
return self.versions[version]
+ def extract(self, deployment):
+ """Extracts wizard variables from a deployment."""
+ result = {}
+ for k,extractor in self.extractors.items():
+ result[k] = extractor(deployment)
+ return result
+ @property
+ def extractors(self):
+ return {}
@staticmethod
def make(name):
"""Makes an application, but uses the correct subtype if available."""