Commits

Martin Geisler committed 5e6cfb9

shelltest: move static methods out of class

Comments (0)

Files changed (1)

 if not os.path.isdir(CACHEDIR):
     os.mkdir(CACHEDIR)
 
+
+def tar_path(state):
+    return os.path.join(CACHEDIR, "%s.tar.gz" % state)
+
+def json_path(state):
+    return os.path.join(CACHEDIR, "%s.json" % state)
+
+def load_state(state):
+    fp = open(json_path(state))
+    tmpdir, cwd, formatted = json.load(fp)
+    fp.close()
+    return tmpdir, cwd, formatted
+
+def load_snapshot(state, target):
+    tarball = tarfile.open(tar_path(state))
+    tarball.extractall(target)
+
+def save_snapshot(state):
+    tarball = tarfile.open(tar_path(state), "w:gz")
+    tarball.add(TMPDIR, '.')
+    tarball.close()
+
+def save_state(state, formatted):
+    fp = open(json_path(state), 'w')
+    json.dump([TMPDIR, CWD, formatted], fp, indent=2)
+    fp.close()
+
 @atexit.register
 def cleanup():
     if TMPDIR is not None and os.path.isdir(TMPDIR):
 
         return result
 
-    def tar_path(self, state):
-        return os.path.join(CACHEDIR, "%s.tar.gz" % state)
-
-    def json_path(self, state):
-        return os.path.join(CACHEDIR, "%s.json" % state)
-
-    def load_state(self, state):
-        fp = open(self.json_path(state))
-        tmpdir, cwd, formatted = json.load(fp)
-        fp.close()
-        return tmpdir, cwd, formatted
-
-    def load_snapshot(self, state, target):
-        tarball = tarfile.open(self.tar_path(state))
-        tarball.extractall(target)
-
-    def save_snapshot(self, state):
-        tarball = tarfile.open(self.tar_path(state), "w:gz")
-        tarball.add(TMPDIR, '.')
-        tarball.close()
-
-    def save_state(self, state, formatted):
-        fp = open(self.json_path(state), 'w')
-        json.dump([TMPDIR, CWD, formatted], fp, indent=2)
-        fp.close()
     def run(self):
         global TMPDIR, CWD, HASH, REPLAYING
 
 
         formatted = []
         if REPLAYING:
-            if "no-cache" not in self.options and os.path.exists(self.json_path(HASH)):
-                TMPDIR, CWD, formatted = self.load_state(HASH)
+            if "no-cache" not in self.options and os.path.exists(json_path(HASH)):
+                TMPDIR, CWD, formatted = load_state(HASH)
             else:
                 REPLAYING = False
                 if TMPDIR is None:
                 if old != "":
                     # We will have saved a snapshot for the previous
                     # hash value
-                    self.load_snapshot(old, TMPDIR)
+                    load_snapshot(old, TMPDIR)
 
         if not REPLAYING:
             try:
                 formatted = self.execute(list(self.content), name)
-                self.save_snapshot(HASH)
-                self.save_state(HASH, formatted)
+                save_snapshot(HASH)
+                save_state(HASH, formatted)
             except ChangedOutputError, e:
                 cmd = nodes.literal_block(e.command, e.command)
                 par = nodes.paragraph("", "the output changed:")