]> scripts.mit.edu Git - wizard.git/blobdiff - wizard/deploy.py
Move a bunch of summary items to full class commands.
[wizard.git] / wizard / deploy.py
index b6d6f6648630c2455d703a6974079175097d8fe0..e6f591872a38378797c89508605a4c33be9c7016 100644 (file)
@@ -15,6 +15,30 @@ def getInstallLines(vs):
         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):
@@ -25,8 +49,31 @@ 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')
@@ -45,7 +92,7 @@ class Deployment(object):
     @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):
@@ -65,6 +112,7 @@ class Application(object):
     def __init__(self, name):
         self.name = name
         self.versions = {}
+        self._extractors = {}
     @property
     def repository(self):
         """Returns the Git repository that would contain this application."""
@@ -76,6 +124,15 @@ class Application(object):
         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."""