Browse files

fixing scripts and adding gitignore

  • Loading branch information...
1 parent e9e7326 commit 798ee0c1400c8d1e1d1196647e62393a07b295b6 Tom Howe committed Jan 24, 2012
Showing with 22 additions and 8 deletions.
  1. +3 −0 .gitignore
  2. +6 −1 reposync/sync.py
  3. +6 −2 scripts/repomonitor
  4. +4 −2 scripts/reposync
  5. +3 −3 setup.py
View
3 .gitignore
@@ -0,0 +1,3 @@
+build
+*egg*
+*.pyc
View
7 reposync/sync.py
@@ -22,6 +22,7 @@
import logging
import optparse
+import os
import sched
import signal
from subprocess import Popen, PIPE, check_call
@@ -43,14 +44,17 @@ class GitUpdater(object):
check.
"""
- def __init__(self, interval, branch, callback):
+ def __init__(self, path, interval, branch, callback):
self.interval = interval
self.branch = branch
self.callback = callback
+ self.path = path
scheduler.enter(interval, 1, self.update_from_git, ())
def update_from_git(self):
check_call(['git', 'fetch'])
+ current_path = os.getcwd()
+ os.chdir(self.path)
current_ref = Popen(['git', 'symbolic-ref', 'HEAD'], stdout=PIPE).communicate()[0].strip()
if current_ref != 'refs/heads/{0}'.format(self.branch):
log.info('Repository is currently on: {0}. Switching to: refs/heads/{1}'.format(current_ref, self.branch))
@@ -70,6 +74,7 @@ def update_from_git(self):
log.info(result)
else:
log.debug("No updates to retrieve")
+ os.chdir(current_path)
scheduler.enter(self.interval, 1, self.update_from_git, ())
def start(self):
View
8 scripts/repomonitor
@@ -3,15 +3,19 @@
from __future__ import absolute_import
import optparse
+import sys
from reposync.fs_monitor import *
if __name__ == '__main__':
parser = optparse.OptionParser()
- parser.add_option('-r', '--repos', action="store", destination="repos", help="Repository roots to monitor")
+ parser.add_option('-r', '--repos', action="store", dest="repos", help="Repository roots to monitor")
parser.add_option('-v', '--verbose', action="store_true", dest="verbose", default=False, help="More output")
parser.add_option('-V', '--wicked-verbose', action='store_true', dest="wicked_verbose", default=False, help="Wicked more output")
options, remainder = parser.parse_args()
+ if options.repos is None:
+ print("You must specify at least one repository to monitor")
+ sys.exit(1)
log_level = logging.WARNING
if options.verbose and options.wicked_verbose:
print('Dude, do you want more output or wicked more output (Please use either -v or -V, not both)')
@@ -21,5 +25,5 @@ if __name__ == '__main__':
if options.wicked_verbose:
log_level = logging.DEBUG
logging.basicConfig(level=log_level, format="%(levelname)s - %(asctime)s (%(name)s:%(funcName)s): %(msg)s")
- monitor = FileSystemMonitor('/tmp/foo')
+ monitor = FileSystemMonitor(options.repos.split(','))
monitor.start()
View
6 scripts/reposync
@@ -4,17 +4,19 @@ from __future__ import absolute_import
import optparse
import logging
+import os
from reposync.sync import *
if __name__ == "__main__":
parser = optparse.OptionParser()
parser.add_option('-i', '--interval', action="store", dest="interval", default=5, type="int", help="Interval to check git")
+ parser.add_option('-d', '--directory', action="store", dest="directory", default=os.path.abspath(','), help="Directory to sync.")
parser.add_option('-b', '--branch', action="store", dest="branch", default="integration", help="Which branch should be checked")
parser.add_option('-c', '--callback', action="store", dest="callback", default=None, help="Script to be called upon changes")
parser.add_option('-v', '--verbose', action="store_true", dest="verbose", default=False, help="More output")
parser.add_option('-V', '--wicked-verbose', action='store_true', dest="wicked_verbose", default=False, help="Wicked more output")
- options, remainder = parser.parse_args();
+ options, remainder = parser.parse_args()
log_level = logging.WARNING
if options.verbose and options.wicked_verbose:
print('Dude, do you want more output or wicked more output (Please use either -v or -V, not both)')
@@ -25,5 +27,5 @@ if __name__ == "__main__":
log_level = logging.DEBUG
logging.basicConfig(level=log_level, format="%(levelname)s - %(asctime)s (%(name)s:%(funcName)s): %(msg)s")
signal.signal(signal.SIGINT, kill_handler)
- updater = GitUpdater(options.interval, options.branch, options.callback)
+ updater = GitUpdater(options.directory, options.interval, options.branch, options.callback)
updater.start()
View
6 setup.py
@@ -1,10 +1,10 @@
-from distutils.core import setup
+from setuptools import setup, find_packages
setup(name='reposync',
version='1.0a',
author='Tom Howe',
author_email='turtlebender@gmail.com',
- packages='reposync'
+ packages=['.'],
install_requires=[ 'pyinotify' ],
- scripts=[ 'reposync/reposync', 'reposync/repomonitor' ]
+ scripts=[ 'scripts/reposync', 'scripts/repomonitor' ]
)

0 comments on commit 798ee0c

Please sign in to comment.