Download:
child 122:357d231b6f76
parent 120:21ef016ac29d
121:2ec2aa867f76
Anton Shestakov <av6@dwimlabs.net>, Thu, 07 Jul 2016 14:08:01 +0800
checker: move hg calls to separate functions, check config['scm']

1 файлов изменено, 43 вставок(+), 19 удалений(-) [+]
checker.py file | annotate | diff | comparison | revisions
--- a/checker.py Thu Jul 07 13:58:38 2016 +0800
+++ b/checker.py Thu Jul 07 14:08:01 2016 +0800
@@ -80,6 +80,35 @@
return ok
+def hg_clone(url, dest):
+ return run(['hg', 'clone', url, dest])
+
+
+def hg_summary():
+ return run(['hg', 'sum'])
+
+
+def hg_log():
+ template = (r'# C&O commit: {rev}:{node}\n'
+ r'# C&O commit branch: {branch}\n'
+ r'# C&O commit date: {date|isodatesec}\n'
+ r'# C&O commit author: {author|person}\n'
+ r'# C&O commit message: {desc|firstline}\n')
+ return run(['hg', 'log', '-r', '.', '-T', template], silent=True)
+
+
+def hg_files(include, exclude):
+ cmd = ['hg', 'files']
+ for pat in include:
+ cmd.extend(('-I', pat))
+ for pat in exclude:
+ cmd.extend(('-X', pat))
+ files = run(cmd, silent=True, get_output=True, ignore_codes=(1,))
+ if files is not False:
+ files = files.splitlines()
+ return files
+
+
def execute(tmp, config):
if not prevalidate(config):
return False
@@ -89,24 +118,23 @@
print('# C&O task: clone')
print('# C&O project URL: {}'.format(config['url']))
- os.environ['HGPLAIN'] = '1'
+ if config['scm'] == 'hg':
+ os.environ['HGPLAIN'] = '1'
- if not run(['hg', 'clone', config['url'], source]):
- return False
+ if config['scm'] == 'hg':
+ if not hg_clone(config['url'], source):
+ return False
print('$ cd {}'.format(source))
os.chdir(source)
- if not run(['hg', 'sum']):
- return False
+ if config['scm'] == 'hg':
+ if not hg_summary():
+ return False
- template = (r'# C&O commit: {rev}:{node}\n'
- r'# C&O commit branch: {branch}\n'
- r'# C&O commit date: {date|isodatesec}\n'
- r'# C&O commit author: {author|person}\n'
- r'# C&O commit message: {desc|firstline}\n')
- if not run(['hg', 'log', '-r', '.', '-T', template], silent=True):
- return False
+ if config['scm'] == 'hg':
+ if not hg_log():
+ return False
print('# C&O task: setup')
@@ -146,18 +174,14 @@
if linter['name'] not in linter_config:
continue
- cmd = ['hg', 'files']
- for pat in linter['include']:
- cmd.extend(('-I', pat))
- for pat in linter.get('exclude', []):
- cmd.extend(('-X', pat))
- files = run(cmd, silent=True, get_output=True, ignore_codes=(1,))
+ if config['scm'] == 'hg':
+ files = hg_files(linter['include'], linter.get('exclude', []))
if files is False:
return False
lc = linter_config[linter['name']]
- for f in files.splitlines():
+ for f in files:
cmd = lc['exec']
flags = lc.get('flags', []) + linter.get('flags', [])
pf = lc.get('post_flags', []) + linter.get('post_flags', [])