]> code.delx.au - bg-scripts/blobdiff - bin/randombg.py
RandomBG: Make server grab socket faster.
[bg-scripts] / bin / randombg.py
index d9fe0a0f08f4a235c08eacf9a18ed41546cfac9e..f47d684b7fa04357a570bdb9baeda4d9651b1c73 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
@@ -360,10 +365,8 @@ 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 os.path.exists(options.socket_filename):
                do_client(options, args)