X-Git-Url: https://git.camperquake.de/gitweb.cgi?p=time-slider.git;a=blobdiff_plain;f=usr%2Fshare%2Ftime-slider%2Flib%2Ftime_slider%2Fzfs.py;h=3efa9cabcdbe15178649134119d1ade4d96f4026;hp=b35e58dfef07f36ac2ce8e17e7dfb0c541942539;hb=a05de207f2bae9d8131568dae5a5838a885cc3c1;hpb=d021224696e8524cab857c27370e33aeaf024130 diff --git a/usr/share/time-slider/lib/time_slider/zfs.py b/usr/share/time-slider/lib/time_slider/zfs.py old mode 100755 new mode 100644 index b35e58d..3efa9ca --- a/usr/share/time-slider/lib/time_slider/zfs.py +++ b/usr/share/time-slider/lib/time_slider/zfs.py @@ -1,4 +1,4 @@ -#!/usr/bin/python2.6 +#!/usr/bin/python2 # # CDDL HEADER START # @@ -132,6 +132,9 @@ class Datasets(Exception): if excludedchild == False: # We want recursive list sorted in alphabetical order # so insert instead of append to the list. + # Also, remove all children from the recursive + # list, as they are covered by the parent + recursive = [x for x in recursive if x not in children] recursive.insert(0, datasetname) for datasetname in recursive: @@ -226,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)) @@ -271,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() @@ -316,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()) @@ -623,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: @@ -656,11 +627,11 @@ class ReadableDataset: return outdata.rstrip() def set_user_property(self, prop, value): - cmd = [PFCMD, ZFSCMD, "set", "%s=%s" % (prop, value), self.name] + cmd = [ZFSCMD, "set", "%s=%s" % (prop, value), self.name] outdata,errdata = util.run_command(cmd) def unset_user_property(self, prop): - cmd = [PFCMD, ZFSCMD, "inherit", prop, self.name] + cmd = [ZFSCMD, "inherit", prop, self.name] outdata,errdata = util.run_command(cmd) class Snapshot(ReadableDataset): @@ -737,9 +708,9 @@ class Snapshot(ReadableDataset): if self.exists() == False: return if deferred == False: - cmd = [PFCMD, ZFSCMD, "destroy", self.name] + cmd = [ZFSCMD, "destroy", self.name] else: - cmd = [PFCMD, ZFSCMD, "destroy", "-d", self.name] + cmd = [ZFSCMD, "destroy", "-d", self.name] outdata,errdata = util.run_command(cmd) # Clear the global snapshot cache so that a rescan will be @@ -755,7 +726,7 @@ class Snapshot(ReadableDataset): if self.exists() == False: return - cmd = [PFCMD, ZFSCMD, "hold", tag, self.name] + cmd = [ZFSCMD, "hold", tag, self.name] outdata,errdata = util.run_command(cmd) def holds(self): @@ -785,7 +756,7 @@ class Snapshot(ReadableDataset): if self.exists() == False: return - cmd = [PFCMD, ZFSCMD, "release", tag, self.name] + cmd = [ZFSCMD, "release", tag, self.name] outdata,errdata = util.run_command(cmd) # Releasing the snapshot might cause it get automatically @@ -852,7 +823,7 @@ class ReadWritableDataset(ReadableDataset): Recursively snapshot childfren of this dataset. Default = False """ - cmd = [PFCMD, ZFSCMD, "snapshot"] + cmd = [ZFSCMD, "snapshot"] if recursive == True: cmd.append("-r") cmd.append("%s@%s" % (self.name, snaplabel))