raise NotImplementedError()
def is_empty(self):
- return False
+ return True
class RandomFileList(BaseFileList):
return self.last_image
def is_empty(self):
- return len(self.list) > 0
+ return len(self.list) == 0
class AllRandomFileList(BaseFileList):
pickle.dump(obj = self, file = fd, protocol = 2)
debug("Cache successfully stored")
except Exception, e:
- warning("Exception while storing cache: '%s'" % e)
+ warning("Storing cache: %s" % e)
def load_cache(self, filename, rescanPaths = False):
debug('Attempting to load cache from "%s"' % filename)
else:
debug("Ignoring cache, path lists do not match")
except Exception, e:
- warning("Exception while loading cache: '%s'" % e)
+ warning("Loading cache: %s" % e)
def get_current_image(self):
return self.list[self.imagePointer]
return imageName
def is_empty(self):
- return self.list
+ return len(self.list) == 0
class FolderRandomFileList(BaseFileList):
"""A file list that will pick a file randomly within a directory. Each
return os.path.join(directory, filename)
def is_empty(self):
- return len(self.directories.values())
+ return len(self.directories.values()) == 0
class Cycler(object):
def init(self, options, paths):
- self.filelist = self.find_files(options, paths)
- if not self.filelist.is_empty():
- error("No images were found. Exiting...")
- sys.exit(1)
-
- debug("Initialising wallchanger")
- wallchanger.init(options.background_colour, options.permanent)
self.cycle_time = options.cycle_time
+ self.history_filename = options.history_filename
- self.task = None
- self.cmd_next()
+ debug("Initialising wallchanger")
+ wallchanger.init(options.background_colour, options.permanent)
- def find_files(self, options, paths):
+ debug("Initialising file list")
if options.all_random:
- filelist = AllRandomFileList()
+ self.filelist = AllRandomFileList()
elif options.folder_random:
- filelist = FolderRandomFileList()
+ self.filelist = FolderRandomFileList()
else:
- filelist = RandomFileList()
+ self.filelist = RandomFileList()
for path in paths:
- filelist.add_path(path)
+ self.filelist.add_path(path)
- if filelist.load_cache(options.history_filename):
+ if self.filelist.load_cache(self.history_filename):
debug("Loaded cache successfully")
else:
debug("Could not load cache")
- filelist.scan_paths()
+ self.filelist.scan_paths()
+
+ if self.filelist.is_empty():
+ error("No images were found. Exiting...")
+ sys.exit(1)
+
+ self.task = None
+ self.cmd_next()
+
+ def finish(self):
+ self.filelist.store_cache(self.history_filename)
+
+ def find_files(self, options, paths):
return filelist
def cmd_reset(self):
if self.task is not None:
self.task.cancel()
self.task = None
+
+ def cmd_exit(self):
+ asyncsched.exit()
class Server(asynchat.async_chat):
def __init__(self, cycler, conn, addr):
def do_server(options, paths):
try:
+ cycler = Cycler()
+ listener = Listener(options.socket_filename, cycler)
+ # Initialisation of Cycler delayed so we grab the socket quickly
+ cycler.init(options, paths)
try:
- cycler = Cycler()
- listener = Listener(options.socket_filename, cycler)
- # Initialisation of Cycler delayed so we grab the socket quickly
- cycler.init(options, paths)
asyncsched.loop()
except KeyboardInterrupt:
print
+ cycler.finish()
finally:
# Make sure that the socket is cleaned up
try: