Commits

Cédric Bonhomme committed 1f7a829 Draft

Minor bugfixes.

Comments (0)

Files changed (4)

balloon.cfg-sample

 [repo-1]
 type = hg
+name = test-balloon
 local_url = /home/cedric/balloon/test-balloon
 url = bitbucket.org/cedricbonhomme/test-balloon
 username = cedricbonhomme
-password = ***
-[repo-2]
-type = git
-local_url = /home/cedric/balloon/test-balloon-git
-url = bitbucket.org/cedricbonhomme/test-balloon-git
-username = cedricbonhomme
 password = ***
 # These regexps are matched against submitted paths with re.match().
 
 # Put only one pattern by line.
-^/home/cedric/balloon/test-balloon/\.hg
-^/home/cedric/balloon/test-balloon/\.hg/.*
-^/home/cedric/balloon/test-balloon/hg\-check.*
+^/home/cedric/python/balloon/test-balloon/\.hg
+^/home/cedric/python/balloon/test-balloon/\.hg/.*
+^/home/cedric/python/balloon/test-balloon/hg\-check.*
 
 
 # Examples:
     """
     The class is responsible of the synchronization of a Mercurial repository.
     """
-    def __init__(self, repository_url, local_url, username):
+    def __init__(self, repository_name, repository_url, local_url, username):
         """
         """
         self.repository_name = repository_name
         # Clone the remote repository.
         self.clone()
 
+        self.initialize()
+
         # Create a new thread which will periodically pull changes:
         thread_pull = threading.Thread(None, self.pull_loop, None)
         # Start the new thread:
         """
         """
         self.locker.acquire()
-        commands.commit(self.repo.ui, self.repo)
         commands.commit(self.repo.ui, self.repo, user=self.username , message=message, addremove=True)
         self.nb_commit += 1
         self.locker.release()
         """
         Add new_file to the list of tracked files.
         """
+        print "add", new_file
         commands.add(self.repo.ui, self.repo, new_file)
         self.commit("Added " + new_file)
 
         """
         Remove a file.
         """
+        print file_to_remove
         commands.remove(self.repo.ui, file_to_remove)
         self.commit("Removed " + file_to_remove)
 
         """
         Push changes every n commits in order to avoid to avoid a heavy use of the network.
         """
+        time.sleep(2)
         while True:
             time.sleep(1)
             if self.nb_commit == 5:
-                commands.push(self.repo.ui, repo)
+                commands.push(self.repo.ui, self.repo)
                 self.nb_commit = 0
 
     def push(self):
         """
         Push changes and set the number of commits to zero.
         """
-        commands.push(self.repo.ui, repo)
+        commands.push(self.repo.ui, self.repo)
         self.nb_commit = 0
 
     def pull_loop(self):
         Pull from the remote repository.
         """
         while True:
-            commands.push(self.repo.ui, repo)
-            commands.update(self.repo.ui, repo)
+            commands.push(self.repo.ui, self.repo)
+            commands.update(self.repo.ui, self.repo)
             time.sleep(240)
 
 
 
 import os
 import pyinotify
+import threading
 import ConfigParser
 
 import hgsync
     """
     This class represent a watcher for the local repository.
     """
-    def __init__(self, type_repo, url, local_url, username):
+    def __init__(self, repository_name, type_repo, url, local_url, username):
         """
         """
         if type_repo == "hg":
-            self.repo = hgsync.HgSync(url, local_url, username)
+            self.repo = hgsync.HgSync(repository_name, url, local_url, username)
             #self.repo.clone()
             self.in_from = ""
 
             self.in_from = ""
 
 
-def start_watcher(type_repo, username, password, url, local_url):
+def start_watcher(repository_name, 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))
+    notifier = pyinotify.Notifier(wm, PTmp(repository_name, 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:
         pass
 
     for repository in config.sections():
+        repository_name = config.get(repository, 'name')
         type_repo = config.get(repository, 'type')
         local_url = config.get(repository, 'local_url')
         url = config.get(repository, 'url')
         password = config.get(repository, 'password')
 
         # Launch a new thread for the repository to watch
-        thread = threading.Thread(None, start_watcher, None, (type_repo, username, password, url, local_url))
+        thread = threading.Thread(None, start_watcher, None, (repository_name,type_repo, username, password, url, local_url))
         #thread.setDaemon(True)
         thread.start()