@@ 38,7 38,7 @@ class HgSync(object):
"""
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 @@ class HgSync(object):
# 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 @@ class HgSync(object):
"""
"""
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 @@ class HgSync(object):
"""
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 @@ class HgSync(object):
"""
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 @@ class HgSync(object):
"""
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 @@ class HgSync(object):
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)
@@ 29,6 29,7 @@
import os
import pyinotify
+import threading
import ConfigParser
import hgsync
@@ 47,11 48,11 @@ class PTmp(pyinotify.ProcessEvent):
"""
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 @@ class PTmp(pyinotify.ProcessEvent):
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 @@ if __name__ == "__main__":
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 @@ if __name__ == "__main__":
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