aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony G. Basile <blueness@gentoo.org>2015-06-30 22:15:35 -0400
committerAnthony G. Basile <blueness@gentoo.org>2015-06-30 22:15:35 -0400
commit8885d6a5b9035f2eb0c02e697dc0bfb45c8b5a7f (patch)
tree165b052003e580934854a5e9da1182cde1312d62 /grs/Synchronize.py
downloadgrss-8885d6a5b9035f2eb0c02e697dc0bfb45c8b5a7f.tar.gz
grss-8885d6a5b9035f2eb0c02e697dc0bfb45c8b5a7f.tar.bz2
grss-8885d6a5b9035f2eb0c02e697dc0bfb45c8b5a7f.zip
Initial commit.
Diffstat (limited to 'grs/Synchronize.py')
-rw-r--r--grs/Synchronize.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/grs/Synchronize.py b/grs/Synchronize.py
new file mode 100644
index 0000000..1df8ce2
--- /dev/null
+++ b/grs/Synchronize.py
@@ -0,0 +1,37 @@
+#!/usr/bin/env python
+
+import os
+from grs.Constants import CONST
+from grs.Execute import Execute
+
+class Synchronize():
+ """ doc here
+ more doc
+ """
+
+ def __init__(self, remote_repo, branch, libdir = CONST.LIBDIR, logfile = CONST.LOGFILE):
+ self.remote_repo = remote_repo
+ self.branch = branch
+ self.local_repo = libdir
+ self.logfile = logfile
+
+ def sync(self):
+ if self.isgitdir():
+ cmd = 'git -C %s reset HEAD --hard' % self.local_repo
+ Execute(cmd, timeout=60, logfile=self.logfile)
+ cmd = 'git -C %s clean -f -x -d' % self.local_repo
+ Execute(cmd, timeout=60, logfile=self.logfile)
+ cmd = 'git -C %s pull' % self.local_repo
+ Execute(cmd, timeout=60, logfile=self.logfile)
+ cmd = 'git -C %s checkout %s' % (self.local_repo, self.branch)
+ Execute(cmd, timeout=60, logfile=self.logfile)
+ else:
+ cmd = 'git clone %s %s' % (self.remote_repo, self.local_repo)
+ Execute(cmd, timeout=60, logfile=self.logfile)
+ cmd = 'git -C %s checkout %s' % (self.local_repo, self.branch)
+ Execute(cmd, timeout=60, logfile=self.logfile)
+
+ def isgitdir(self):
+ git_configdir = os.path.join(self.local_repo, '.git')
+ git_configfile = os.path.join(git_configdir, 'config')
+ return os.path.isdir(git_configdir) and os.path.isfile(git_configfile)