]> code.delx.au - bg-scripts/blobdiff - bin/randombg.py
RandomBG: Added oneshot option.
[bg-scripts] / bin / randombg.py
index d9fe0a0f08f4a235c08eacf9a18ed41546cfac9e..99933fea4fd9879b1c532b98181a413a0b79606e 100755 (executable)
@@ -162,13 +162,16 @@ class FolderRandomFileList(BaseFileList):
        def __init__(self):
                self.directories = {}
        
+       def scan_paths(self):
+               pass
+       
        def add_path(self, path):
                debug('Added path "%s" to the list' % path)
                for dirpath, dirs, filenames in os.walk(path):
                        debug('Scanning "%s" for images' % dirpath)
                        if self.directories.has_key(dirpath):
                                continue
-                       filenames = filter_images(filenames)
+                       filenames = list(filter_images(filenames))
                        if len(filenames):
                                self.directories[dirpath] = filenames
                                debug('Adding "%s" to "%s"' % (filenames, dirpath))
@@ -187,7 +190,7 @@ class FolderRandomFileList(BaseFileList):
 
 
 class Cycler(object):
-       def __init__(self, options, paths):
+       def init(self, options, paths):
                self.filelist = self.find_files(options, paths)
                if not self.filelist.is_empty():
                        error("No images were found. Exiting...")
@@ -295,8 +298,10 @@ class Listener(asyncore.dispatcher):
 def do_server(options, paths):
        try:
                try:
-                       cycler = Cycler(options, paths)
+                       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
@@ -319,6 +324,9 @@ def do_client(options, args):
                        time.sleep(options.cycle_time)
        sock.close()
 
+def do_oneshot(options, paths):
+       cycler = Cycler()
+       cycler.init(options, paths)
 
 def build_parser():
        parser = OptionParser(version="%prog " + VERSION, 
@@ -340,6 +348,9 @@ def build_parser():
        parser.add_option("--all-random",
                action="store_true", dest="all_random", default=False,
                help="Make sure that all images have been displayed before repeating an image")
+       parser.add_option("-1", "--oneshot",
+               action="store_true", dest="oneshot", default=False,
+               help="Set one random image and terminate immediately.")
        parser.add_option("--folder-random",
                action="store_true", dest="folder_random", default=False,
                help="Give each folder an equal chance of having an image selected from it")
@@ -360,10 +371,11 @@ def main():
 
        if options.verbose == 1:
                logging.getLogger().setLevel(logging.INFO)
-               print "INFO"
        elif options.verbose >= 2:
                logging.getLogger().setLevel(logging.DEBUG)
-               print "DEBUG"
+       
+       if options.oneshot:
+               do_oneshot(options, args)
 
        if os.path.exists(options.socket_filename):
                do_client(options, args)