]> code.delx.au - bg-scripts/commitdiff
Added support for python2.3
authorGreg Darke <greg@tsukasa.net.au>
Mon, 21 Jul 2008 02:29:54 +0000 (12:29 +1000)
committerGreg Darke <greg@tsukasa.net.au>
Mon, 21 Jul 2008 02:29:54 +0000 (12:29 +1000)
randombg.py
wallchanger.py

index 3deac9cdec948147cc46670d0ca55f0ba3b19da0..bb2936b29bee4c72ab1436eb29c75a81b17e6854 100755 (executable)
@@ -7,7 +7,12 @@ import asyncore, asynchat, socket
 import os, os.path, random, sys, time
 from optparse import OptionParser
 import logging
-logging.basicConfig(format="%(levelname)s: %(message)s")
+try:
+       logging.basicConfig(format="%(levelname)s: %(message)s")
+except TypeError:
+# Python 2.3's logging.basicConfig does not support parameters
+       logging.basicConfig()
+
 try:
        import cPickle as pickle
 except ImportError:
@@ -18,7 +23,7 @@ try:
        import asyncsched
        import wallchanger
 except ImportError, e:
-       logging.critical("Missing libraries! Exiting...")
+       logging.critical("Missing libraries! Exiting...", exc_info=1)
        sys.exit(1)
 
 
@@ -147,7 +152,7 @@ class AllRandomFileList(BaseFileList):
        def store_cache(self, filename):
                try:
                        fd = open(filename, 'wb')
-                       pickle.dump(obj = self, file = fd, protocol = 2)
+                       pickle.dump(self, fd, 2)
                        logging.debug("Cache successfully stored")
                except Exception, e:
                        logging.warning("Storing cache", exc_info=1)
index 5982621bff25d95a22003b2898501e68677a35dd..b48775ebfb590a489472117f330a29d119e3f227 100755 (executable)
@@ -4,7 +4,7 @@
 # Licensed for distribution under the GPL version 2, check COPYING for details
 # This is a cross platform/cross window manager way to change your wallpaper
 
-import commands, sys, os, os.path, subprocess, time
+import commands, sys, os, os.path, time
 import logging
 
 __all__ = ("init", "set_image")
@@ -59,6 +59,22 @@ class BaseChanger(object):
                self.permanent = permanent
                self.convert = convert
 
+               try:
+                       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()
+
+       # 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)
+
        def set_image(self, filename):
                raise NotImplementedError()
 
@@ -81,7 +97,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, subprocess.Popen(cmd, stdout=sys.stdout, stderr=sys.stderr, stdin=None).wait()
+               return output_name, self._runProgram(cmd)
 
        def set_image(self, file):
                if self.convert:
@@ -100,7 +116,7 @@ class WMakerChanger(BaseChanger):
                        cmd += ["-u"] # update the wmaker database
                cmd += [file]
                logging.debug('''WMaker bgset command: "'%s'"''', "' '".join(cmd))
-               return not subprocess.Popen(cmd, stdout=sys.stdout, stderr=sys.stderr, stdin=None).wait()
+               return not self._runProgram(cmd)
 
 class OSXChanger(BaseChanger):
        name = "Mac OS X"
@@ -167,7 +183,7 @@ 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 subprocess.Popen(cmd, stdout=sys.stdout, stderr=sys.stderr, stdin=None).wait()
+               return not self._runProgram(cmd)
 
 class KDEChanger(BaseChanger):
        name = "KDE"
@@ -183,7 +199,7 @@ class KDEChanger(BaseChanger):
                cmds.append(['dcop', 'kdesktop', 'KBackgroundIface', 'configure'])
                for cmd in cmds:
                        logging.debug(cmd)
-                       if subprocess.Popen(cmd, stdout=sys.stdout, stderr=sys.stderr, stdin=None).wait() != 0:
+                       if self._runProgram(cmd) != 0:
                                return False
 
                return True