-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmoss.py
41 lines (36 loc) · 1.18 KB
/
moss.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
'''
Python moss driver.
Currently only supports checking against a directory, and in theory, base file support,
however, base files are not supported at this time.
'''
import subprocess
import os
#Run a command on the shell and return the results as a string.
def _run_command(command):
p = subprocess.Popen(command,
stdout=subprocess.PIPE,
shell=True)
return reduce(lambda x,y: x+y, iter(p.stdout.readline, b''))
#Languages and their file extensions
EXTENSIONS = {
'python': 'py',
'java': 'java',
'scheme': 'sch',
'lisp': 'lisp',
'c': 'c',
'cc': 'cc',
}
'''
Sends a file to moss for examination.
Returns the result URL generated by moss.
USAGE:
get_results('python', 'py', 'path/to/files')
'''
def get_results(language, directory, base_file=None):
if base_file is not None:
cmd = 'perl moss -l %s -d %s/%s/*/*.%s -b %s' % (language, directory, language, EXTENSIONS[language], base_file)
else:
cmd = 'perl moss -l %s -d %s/%s/*/*.%s' % (language, directory, language, EXTENSIONS[language])
results_url = _run_command(cmd).split('\n')[-2]
print cmd
return results_url