Skip to content

Commit f076da9

Browse files
author
Tom Howe
committed
Updates for supporting reposync script
1 parent 118e5c2 commit f076da9

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

README.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
Syncs a git repo with a local file system, optionally calling
2-
a callback.
2+
a callback. Now includes script for pushing and pulling changes
3+
in a single script called reposync.

reposync/fs_monitor.py

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def my_init(self, monitor):
1717
def process_IN_CLOSE_WRITE(self, event):
1818
if pattern.search(event.pathname) is not None:
1919
return
20+
log.info("event: {0}".format(event))
2021
log.info("adding and committing: {0}".format(event.pathname))
2122
git_add = Popen(['git', 'add', event.pathname], cwd=event.path, stdout=PIPE, stderr=PIPE)
2223
git_add_result = git_add.communicate()

reposync/sync.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,15 @@ def __init__(self, repos, interval, branch, callback):
4949
self.branch = branch
5050
self.callback = callback
5151
self.repos = repos
52+
for repo in self.repos:
53+
log.info("Monitoring remote repo for: {0}".format(repo))
5254
scheduler.enter(interval, 1, self.update_from_git, ())
5355

5456
def update_from_git(self):
5557
check_call(['git', 'fetch'])
5658
current_path = os.getcwd()
57-
for repo in repos:
58-
os.chdir(self.path)
59+
for repo in self.repos:
60+
os.chdir(repo)
5961
current_ref = Popen(['git', 'symbolic-ref', 'HEAD'], stdout=PIPE).communicate()[0].strip()
6062
if current_ref != 'refs/heads/{0}'.format(self.branch):
6163
log.info('Repository is currently on: {0}. Switching to: refs/heads/{1}'.format(current_ref, self.branch))
@@ -67,7 +69,7 @@ def update_from_git(self):
6769
remote_hash = p2.communicate()[0].strip()
6870
log.debug('Repo: {0}. Local hash: {1}. Remote hash: {2}'.format(repo, local_hash, remote_hash))
6971
if local_hash != remote_hash:
70-
log.info('Updating local repository: {0} to: {1}'.format(repo, remote_hash))
72+
log.info('Updating local repository: {0} to: {1}'.format(repo, remote_hash))
7173
check_call(['git', 'pull', 'origin', self.branch])
7274
if self.callback is not None:
7375
log.info('Calling callback for {0}'.format(repo))
@@ -81,6 +83,15 @@ def update_from_git(self):
8183
def start(self):
8284
scheduler.run()
8385

86+
def stop(self):
87+
if not scheduler.empty:
88+
for event in scheduler.queue:
89+
try:
90+
scheduler.cancel(event)
91+
except ValueError:
92+
log.debug('Job beat us to the shutdown punch: {0}'.format(event))
93+
94+
8495
def kill_handler(signal, frame):
8596
log.info('Shutting Down')
8697
if not scheduler.empty:

setup.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from setuptools import setup, find_packages
22

33
setup(name='reposync',
4-
version='1.0a',
4+
version='1.0a1',
55
author='Tom Howe',
66
author_email='[email protected]',
7-
packages=['.'],
7+
packages=['reposync'],
88
install_requires=[ 'pyinotify' ],
9-
scripts=[ 'scripts/repopush', 'scripts/repopull' ]
9+
scripts=[ 'scripts/reposync', 'scripts/repopush', 'scripts/repopull' ]
1010
)

0 commit comments

Comments
 (0)