# HG changeset patch # User cedricbonhomme # Date 1338208762 -7200 # Mon May 28 14:39:22 2012 +0200 # Node ID 1f7a829e215806faa27010b9233421bc4c66aa24 # Parent fa26fa1c32e3a188d29a0389afe8e715900bd11d Minor bugfixes. diff --git a/balloon.cfg-sample b/balloon.cfg-sample --- a/balloon.cfg-sample +++ b/balloon.cfg-sample @@ -1,12 +1,7 @@ [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 = *** \ No newline at end of file diff --git a/exclude.lst b/exclude.lst --- a/exclude.lst +++ b/exclude.lst @@ -4,9 +4,9 @@ # 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: diff --git a/hgsync.py b/hgsync.py --- a/hgsync.py +++ b/hgsync.py @@ -38,7 +38,7 @@ """ 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 @@ -53,6 +53,8 @@ # 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: @@ -84,7 +86,6 @@ """ """ 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() @@ -93,6 +94,7 @@ """ 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) @@ -106,6 +108,7 @@ """ Remove a file. """ + print file_to_remove commands.remove(self.repo.ui, file_to_remove) self.commit("Removed " + file_to_remove) @@ -121,17 +124,18 @@ """ 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): @@ -139,8 +143,8 @@ 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) diff --git a/watcher.py b/watcher.py --- a/watcher.py +++ b/watcher.py @@ -29,6 +29,7 @@ import os import pyinotify +import threading import ConfigParser import hgsync @@ -47,11 +48,11 @@ """ 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 = "" @@ -97,12 +98,14 @@ 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: @@ -124,6 +127,7 @@ 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') @@ -131,6 +135,6 @@ 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() \ No newline at end of file