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)
"""Base file list implementation"""
def __init__(self):
self.paths = []
+ self.favourites = []
def add_path(self, path):
self.paths.append(path)
def store_cache(self, filename):
try:
- debug("Attempting to store cache")
+ logging.debug("Attempting to store cache")
fd = open(filename, 'wb')
- pickle.dump(obj = self, file = fd, protocol = 2)
- debug("Cache successfully stored")
+ pickle.dump(self, fd, 2)
+ logging.debug("Cache successfully stored")
except Exception, e:
warning("Storing cache: %s" % e)
def load_cache(self, filename):
try:
- debug("Attempting to load cache from: %s" % filename)
+ logging.debug("Attempting to load cache from: %s" % filename)
self.paths.sort()
fd = open(filename, 'rb')
return True
except Exception, e:
- warning("Loading cache: %s" % e)
+ logging.warning("Loading cache: %s" % e)
return False
+ def add_to_favourites(self):
+ '''Adds the current image to the list of favourites'''
+ self.favourites.append(self.get_current_image())
+
def scan_paths(self):
raise NotImplementedError()
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)
if self.paths == tmp.paths:
logging.debug("Path lists match, copying properties")
# Overwrite this object with the other
- for attr in ('list', 'imagePointer'):
+ for attr in ('list', 'imagePointer', 'favourites'):
setattr(self, attr, getattr(tmp, attr))
else:
logging.debug("Ignoring cache, path lists do not match")
def cmd_exit(self):
asyncsched.exit()
+ def cmd_favourite(self):
+ self.filelist.add_to_favourites()
+
class Server(asynchat.async_chat):
def __init__(self, cycler, conn, addr):
asynchat.async_chat.__init__(self, conn=conn)