X-Git-Url: https://code.delx.au/bg-scripts/blobdiff_plain/b9fbe7ae464bd55ce910929bb678f440c72cb121..37a55b03716139bdc88b0cd444e8b0eabab6669d:/randombg.py diff --git a/randombg.py b/randombg.py index a259e1e..fff408f 100755 --- a/randombg.py +++ b/randombg.py @@ -40,6 +40,7 @@ class BaseFileList(object): """Base file list implementation""" def __init__(self): self.paths = [] + self.favourites = [] def add_path(self, path): self.paths.append(path) @@ -48,7 +49,7 @@ class BaseFileList(object): try: logging.debug("Attempting to store cache") 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: warning("Storing cache: %s" % e) @@ -77,6 +78,10 @@ class BaseFileList(object): 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() @@ -166,7 +171,7 @@ class AllRandomFileList(BaseFileList): 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") @@ -240,7 +245,7 @@ class FolderRandomFileList(BaseFileList): class Cycler(object): - def init(self, options, paths): + def init(self, options, paths, oneshot=False): self.cycle_time = options.cycle_time self.history_filename = options.history_filename @@ -269,7 +274,10 @@ class Cycler(object): sys.exit(1) self.task = None - self.cmd_reload() + if oneshot: + self.cmd_next() + else: + self.cmd_reload() def finish(self): self.filelist.store_cache(self.history_filename) @@ -288,6 +296,7 @@ class Cycler(object): self.task.cancel() self.task = asyncsched.schedule(self.cycle_time, next) logging.debug("Reset timer for %s seconds" % self.cycle_time) + self.filelist.store_cache(self.history_filename) def cmd_reload(self): image = self.filelist.get_current_image() @@ -315,6 +324,9 @@ class Cycler(object): 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) @@ -388,7 +400,7 @@ def do_client(options, args): def do_oneshot(options, paths): cycler = Cycler() - cycler.init(options, paths) + cycler.init(options, paths, oneshot=True) def build_parser(): parser = OptionParser(version="%prog " + VERSION, @@ -441,11 +453,11 @@ def main(): if options.oneshot: do_oneshot(options, args) - - if os.path.exists(options.socket_filename): - do_client(options, args) else: - do_server(options, args) + if os.path.exists(options.socket_filename): + do_client(options, args) + else: + do_server(options, args) if __name__ == "__main__":