Initial port to python3
[htsworkflow.git] / htsworkflow / automation / spoolwatcher.py
index e226234d6d392f67cd774cb436dc9660ad22e71b..ce08be7eddd0ae55328ab32abddb51bf203f07d2 100644 (file)
@@ -35,7 +35,7 @@ class WatcherEvent(object):
            complete = "(completed)"
         else:
            complete = ""
-        return u"<WatchEvent: %s %s %s>" % (time.ctime(self.time), self.event_root, complete)
+        return "<WatchEvent: %s %s %s>" % (time.ctime(self.time), self.event_root, complete)
 
 class Handler(pyinotify.ProcessEvent):
     def __init__(self, watchmanager, bot, completion_files=None):
@@ -72,7 +72,7 @@ class Handler(pyinotify.ProcessEvent):
 
                     # if we've already seen an event in this directory (AKA runfolder)
                     # keep track if its already hit the "completed" flag
-                    if watch_path_events.has_key(target):
+                    if target in watch_path_events:
                        run_already_complete = watch_path_events[target].complete
 
                     watch_path_events[target] = WatcherEvent(target)
@@ -205,7 +205,7 @@ class SpoolWatcher(rpc.XmlRpcBot):
                 mounts.append(w)
                 self.mounts_to_watches[mount_location] = mounts
 
-            self.log.info(u"Watching:"+unicode(w))
+            self.log.info("Watching:"+str(w))
             self.wdds.append(self.wm.add_watch(w, mask, rec=True, auto_add=True))
 
     def unmount_watch(self, event_path):
@@ -213,8 +213,8 @@ class SpoolWatcher(rpc.XmlRpcBot):
         # the list getting shorter
         for i in range(len(self.wdds),0, -1):
             wdd = self.wdds[i]
-            self.log.info(u'unmounting: '+unicode(wdd.items()))
-            self.wm.rm_watch(wdd.values())
+            self.log.info('unmounting: '+str(list(wdd.items())))
+            self.wm.rm_watch(list(wdd.values()))
             del self.wdds[i]
         self.mounted = False
 
@@ -238,11 +238,11 @@ class SpoolWatcher(rpc.XmlRpcBot):
             self.notifier.read_events()
             # should we do something?
         # has something happened?
-        for watchdir, last_events in self.handler.last_event.items():
-            for last_event_dir, last_event_detail in last_events.items():
+        for watchdir, last_events in list(self.handler.last_event.items()):
+            for last_event_dir, last_event_detail in list(last_events.items()):
                 time_delta = time.time() - last_event_detail.time
                 if time_delta > self.write_timeout:
-                    LOGGER.info("timeout: %s" % (unicode(last_event_detail),))
+                    LOGGER.info("timeout: %s" % (str(last_event_detail),))
                     copy_url = self.make_copy_url(watchdir, last_event_dir)
                     self.startCopy(copy_url)
                     if last_event_detail.complete:
@@ -250,7 +250,7 @@ class SpoolWatcher(rpc.XmlRpcBot):
 
                     self.handler.last_event[watchdir] = {}
         # handle unmounted filesystems
-        for mount_point, was_mounted in self.mounted_points.items():
+        for mount_point, was_mounted in list(self.mounted_points.items()):
             if not was_mounted and mount.is_mounted(mount_point):
                 # we've been remounted. Huzzah!
                 # restart the watch
@@ -266,21 +266,21 @@ class SpoolWatcher(rpc.XmlRpcBot):
         """
         Parse xmpp chat messages
         """
-        help = u"I can send [copy] message, or squencer [finished]"
-        if re.match(u"help", msg):
+        help = "I can send [copy] message, or squencer [finished]"
+        if re.match("help", msg):
             reply = help
         elif re.match("copy", msg):
             self.startCopy(msg)
-            reply = u"sent copy message"
-        elif re.match(u"finished", msg):
+            reply = "sent copy message"
+        elif re.match("finished", msg):
             words = msg.split()
             if len(words) == 2:
                 self.sequencingFinished(words[1])
-                reply = u"sending sequencing finished for %s" % (words[1])
+                reply = "sending sequencing finished for %s" % (words[1])
             else:
-                reply = u"need runfolder name"
+                reply = "need runfolder name"
         else:
-            reply = u"I didn't understand '%s'" %(msg)
+            reply = "I didn't understand '%s'" %(msg)
         return reply
 
     def run(self):