Replace Popen calls with util.run_command
authorRalf Ertzinger <ralf@skytale.net>
Fri, 21 Feb 2014 19:08:18 +0000 (20:08 +0100)
committerRalf Ertzinger <ralf@skytale.net>
Fri, 21 Feb 2014 19:08:18 +0000 (20:08 +0100)
usr/share/time-slider/lib/time_slider/smf.py
usr/share/time-slider/lib/time_slider/zfs.py

index bdefada..5c64109 100644 (file)
@@ -120,25 +120,25 @@ class SMFInstance(Exception):
 
     def refresh_service(self):
         cmd = [SVCADMCMD, "refresh", self.instanceName]
-        p = subprocess.Popen(cmd, close_fds=True)
+        util.run_command(cmd)
 
     def disable_service (self):
         if self.svcstate == "disabled":
             return
         cmd = [SVCADMCMD, "disable", self.instanceName]
-        p = subprocess.Popen(cmd, close_fds=True)
+        util.run_command(cmd)
         self.svcstate = self.get_service_state()
 
     def enable_service (self):
         if (self.svcstate == "online" or self.svcstate == "degraded"):
             return
         cmd = [SVCADMCMD, "enable", self.instanceName]
-        p = subprocess.Popen(cmd, close_fds=True)
+        util.run_command(cmd)
         self.svcstate = self.get_service_state()
 
     def mark_maintenance (self):
         cmd = [SVCADMCMD, "mark", "maintenance", self.instanceName]
-        subprocess.Popen(cmd, close_fds=True)
+        util.run_command(cmd)
 
     def __str__(self):
         ret = "SMF Instance:\n" +\
index 4db0574..3efa9ca 100644 (file)
@@ -229,12 +229,7 @@ class Datasets(Exception):
             cmd = [ZFSCMD, "list", "-H", "-t", "filesystem", \
                    "-o", "name,mountpoint", "-s", "name"]
             try:
-                p = subprocess.Popen(cmd,
-                                     stdout=subprocess.PIPE,
-                                     stderr=subprocess.PIPE,
-                                     close_fds=True)
-                outdata,errdata = p.communicate()
-                err = p.wait()
+                outdata,errdata = util.run_command(cmd, True)
             except OSError, message:
                 raise RuntimeError, "%s subprocess error:\n %s" % \
                                     (cmd, str(message))
@@ -274,19 +269,11 @@ class Datasets(Exception):
             cmd = [ZFSCMD, "list", "-H", "-t", "volume", \
                    "-o", "name", "-s", "name"]
             try:
-                p = subprocess.Popen(cmd,
-                                     stdout=subprocess.PIPE,
-                                     stderr=subprocess.PIPE,
-                                     close_fds=True)
-                outdata,errdata = p.communicate()
-                err = p.wait()
-            except OSError, message:
-                raise RuntimeError, "%s subprocess error:\n %s" % \
-                                    (cmd, str(message))
-            if err != 0:
+                outdata,errdata = util.run_command(cmd, True)
+            except RuntimeError, message:
                 Datasets._volumeslock.release()
-                raise RuntimeError, '%s failed with exit code %d\n%s' % \
-                                    (str(cmd), err, errdata)
+                raise RuntimeError, str(message)
+
             for line in outdata.rstrip().split('\n'):
                 Datasets.volumes.append(line.rstrip())
         Datasets._volumeslock.release()
@@ -319,20 +306,10 @@ class Datasets(Exception):
             snaps = []
             cmd = [ZFSCMD, "get", "-H", "-p", "-o", "value,name", "creation"]
             try:
-                p = subprocess.Popen(cmd,
-                                     stdout=subprocess.PIPE,
-                                     stderr=subprocess.PIPE,
-                                     close_fds=True)
-                outdata,errdata = p.communicate()
-                err= p.wait()
-            except OSError, message:
+                outdata,errdata = util.run_command(cmd, True)
+            except RuntimeError, message:
                 Datasets.snapshotslock.release()
-                raise RuntimeError, "%s subprocess error:\n %s" % \
-                                    (cmd, str(message))
-            if err != 0:
-                Datasets.snapshotslock.release()
-                raise RuntimeError, '%s failed with exit code %d\n%s' % \
-                                    (str(cmd), err, errdata)
+                raise RuntimeError, str(message)
             for dataset in outdata.rstrip().split('\n'):
                 if re.search("@", dataset):
                     insort(snaps, dataset.split())
@@ -626,18 +603,9 @@ class ReadableDataset:
         # simple zfs get command on the snapshot
         cmd = [ZFSCMD, "get", "-H", "-o", "name", "type", self.name]
         try:
-            p = subprocess.Popen(cmd,
-                                 stdout=subprocess.PIPE,
-                                 stderr=subprocess.PIPE,
-                                 close_fds=True)
-            outdata,errdata = p.communicate()
-            err = p.wait()
-        except OSError, message:
-            raise RuntimeError, "%s subprocess error:\n %s" % \
-                            (command, str(message))
-        if err != 0:
-            # Doesn't exist
-            return False
+            outdata,errdata = util.run_command(cmd)
+        except RuntimeError, message:
+            raise RuntimeError, str(message)
 
         result = outdata.rstrip()
         if result == self.name: