-
Notifications
You must be signed in to change notification settings - Fork 0
/
moss.py
40 lines (28 loc) · 898 Bytes
/
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
import mosspy
import re
import yaml
import logging
try:
from urllib.request import urlopen
except ImportError:
a = 5
# from urllib2 import urlopen
def get_score(original_file, refactored_file):
with open("config.yml", 'r') as f:
config = yaml.load(f)
userid = config['moss_user_id']
m = MossClient(userid, "python")
m.addFile(original_file)
m.addFile(refactored_file)
url = m.send()
logging.debug('Report URL: {}'.format(url))
return m.parse_score(url)
class MossClient(mosspy.Moss):
def parse_score(self, url):
response = urlopen(url)
content = response.read()
p = re.compile('\([0-9]+%\)')
scores = [int(score[1:-2]) for score in p.findall(str(content))]
assert len(scores) == 2
# simply use refactored file's match score with regard to original file
return scores[1]