rename runProgram
authorJames Bunton <jamesbunton@delx.net.au>
Sat, 12 May 2012 23:57:31 +0000 (09:57 +1000)
committerJames Bunton <jamesbunton@delx.net.au>
Sat, 12 May 2012 23:57:31 +0000 (09:57 +1000)
wallchanger.py

index 4ee3b08..b5cf6a1 100755 (executable)
@@ -71,21 +71,16 @@ class BaseChanger(object):
                self.permanent = permanent
                self.convert = convert
 
-               try:
+       try:
+               def _exec_cmd(self, cmd):
                        import subprocess
-               except ImportError:
-                       self._runProgram = self._runProgram_command
-               else:
-                       self._runProgram = self._runProgram_subprocess
-
-       def _runProgram_subprocess(self, cmd):
-               import subprocess
-               return subprocess.Popen(cmd, stdout=sys.stdout, stderr=sys.stderr, stdin=None).wait()
+                       return subprocess.Popen(cmd, stdout=sys.stdout, stderr=sys.stderr, stdin=None).wait()
 
-       # A simple implementation of subprocess for python2.4
-       def _runProgram_command(self, cmd):
-               """Runs a program given in cmd"""
-               return os.spawnvp(os.P_WAIT, cmd[0], cmd)
+       except ImportError:
+               # A simple implementation of subprocess for python2.4
+               def _exec_cmd(self, cmd):
+                       """Runs a program given in cmd"""
+                       return os.spawnvp(os.P_WAIT, cmd[0], cmd)
 
        def set_image(self, filename):
                raise NotImplementedError()
@@ -130,7 +125,7 @@ class WMakerChanger(BaseChanger):
                output_name = os.path.join(self._ConvertedWallpaperLocation, '%s.png' % time.time())
                cmd = ["convert", '-resize', '1280', '-gravity', 'Center', '-crop', '1280x800+0+0', file, output_name]
                logging.debug("""Convert command: '"%s"'""", '" "'.join(cmd))
-               return output_name, self._runProgram(cmd)
+               return output_name, self._exec_cmd(cmd)
 
        def set_image(self, file):
                if self.convert:
@@ -149,7 +144,7 @@ class WMakerChanger(BaseChanger):
                        cmd += ["-u"] # update the wmaker database
                cmd += [file]
                logging.debug('''WMaker bgset command: "'%s'"''', "' '".join(cmd))
-               return not self._runProgram(cmd)
+               return not self._exec_cmd(cmd)
 
 class OSXChanger(BaseChanger):
        name = "Mac OS X"
@@ -256,14 +251,14 @@ class GnomeChanger(BaseChanger):
        def set_image(self, file):
                cmd = ['gconftool-2', '--type', 'string', '--set', '/desktop/gnome/background/picture_filename', file]
                logging.debug(cmd)
-               return not self._runProgram(cmd)
+               return not self._exec_cmd(cmd)
 
 class UnityChanger(BaseChanger):
        name = "Unity"
        def set_image(self, file):
                cmd = ['gsettings', 'set', 'org.gnome.desktop.background', 'picture-uri', 'file://'+file]
                logging.debug(cmd)
-               return not self._runProgram(cmd)
+               return not self._exec_cmd(cmd)
 
 class KDEChanger(BaseChanger):
        name = "KDE"
@@ -279,7 +274,7 @@ class KDEChanger(BaseChanger):
                cmds.append(['dcop', 'kdesktop', 'KBackgroundIface', 'configure'])
                for cmd in cmds:
                        logging.debug(cmd)
-                       if self._runProgram(cmd) != 0:
+                       if self._exec_cmd(cmd) != 0:
                                return False
 
                return True