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:
import asyncsched
import wallchanger
except ImportError, e:
- logging.critical("Missing libraries! Exiting...")
+ logging.critical("Missing libraries! Exiting...", exc_info=1)
sys.exit(1)
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)
# 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")
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()
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:
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"
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"
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