Commits

Cédric Bonhomme committed 1a7f865 Draft

Detect type of repo.

  • Participants
  • Parent commits aeb7358

Comments (0)

Files changed (1)

     def __init__(self, url, local_url, username):
         """
         """
-        self.repo = hgsync.HgSync(url, local_url, username)
-        #self.repo.clone()
-
-        self.in_from = ""
+        if type_repo == "hg":
+            self.repo = hgsync.HgSync(url, local_url, username)
+            #self.repo.clone()
+            self.in_from = ""
 
     def process_IN_CREATE(self, event):
         """
             self.in_from = ""
 
 
+def start_watcher(type_repo, username, password, url, local_url):
+    """
+    Start a watcher. This function is called in a separate thread.
+    """
+    wm = pyinotify.WatchManager()
+    notifier = pyinotify.Notifier(wm, PTmp(type_repo, "https://" + username + ":" + password + "@" + url, local_url, username))
+    wdd = wm.add_watch((local_url) , mask, rec=True, auto_add=True, exclude_filter=excl)
+    while True:
+        try:
+            notifier.process_events()
+            if notifier.check_events():
+                notifier.read_events()
+        except KeyboardInterrupt:
+            notifier.stop()
+            break
 
 
 if __name__ == "__main__":
     password = config.get('repo', 'password')
 
 
-    wm = pyinotify.WatchManager()
-    notifier = pyinotify.Notifier(wm, PTmp("https://" + username + ":" + password + "@" + url, local_url, username))
-
-    wdd = wm.add_watch((local_url) , mask, rec=True, auto_add=True, exclude_filter=excl)
-
-
-    while True:
-        try:
-            notifier.process_events()
-            if notifier.check_events():
-                notifier.read_events()
-        except KeyboardInterrupt:
-            notifier.stop()
-            break
+    # Launch a new thread for the repository to watch
+    thread = threading.Thread(None, start_watcher, None, (username, password, url, local_url))
+    thread = threading.Thread(None, start_watcher, None, (type_repo, username, password, url, local_url))
+    #thread.setDaemon(True)
+    thread.start()