Download:
child 156:c19330ec9795
parent 154:e9b7e35f97bb
155:79dbe7a162d5
Anton Shestakov <av6@dwimlabs.net>, Mon, 18 Jul 2016 14:02:28 +0800
checker: take commit to update to as an optional argument

1 файлов изменено, 25 вставок(+), 7 удалений(-) [+]
checker.py file | annotate | diff | comparison | revisions
--- a/checker.py Sun Jul 17 23:42:38 2016 +0800
+++ b/checker.py Mon Jul 18 14:02:28 2016 +0800
@@ -75,13 +75,21 @@
def git_clone(url, dest):
- return run(['git', 'clone', '--depth', '1', url, dest])
+ return run(['git', 'clone', url, dest])
def hg_clone(url, dest):
return run(['hg', 'clone', url, dest])
+def git_checkout(commit):
+ return run(['git', 'checkout', commit])
+
+
+def hg_update(commit):
+ return run(['hg', 'update', commit])
+
+
def git_status():
return run(['git', 'status'])
@@ -131,7 +139,7 @@
return files
-def execute(tmp, config):
+def execute(tmp, config, args):
if not prevalidate(config):
return False
@@ -153,6 +161,14 @@
print('$ cd {}'.format(source))
os.chdir(source)
+ if args.commit is not None:
+ if config['scm'] == 'git':
+ if not git_checkout(args.commit):
+ return False
+ elif config['scm'] == 'hg':
+ if not hg_update(args.commit):
+ return False
+
if config['scm'] == 'git':
if not git_status():
return False
@@ -228,11 +244,11 @@
return True
-def wrapper(config):
+def wrapper(config, args):
print('# C&O job started: {}'.format(timestamp()))
tmp = mkdtemp(prefix='candolint.')
- if not execute(tmp, config):
+ if not execute(tmp, config, args):
print('# C&O job failed')
print('# C&O task: cleanup')
@@ -248,12 +264,14 @@
def main():
parser = ArgumentParser()
- helptext = 'project configuration file (YAML)'
- parser.add_argument('config', type=FileType('r'), help=helptext)
+ parser.add_argument(
+ 'config', type=FileType('r'),
+ help='project configuration file (YAML)')
+ parser.add_argument('commit', nargs='?', help='commit to update to')
args = parser.parse_args()
config = yaml.safe_load(args.config)
try:
- wrapper(config)
+ wrapper(config, args)
except:
bad_exit()
raise