/
utils.py
34 lines (25 loc) · 933 Bytes
/
utils.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
#!/usr/bin/python
import json
import subprocess
import unicodedata
def execute(cmd):
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
p.wait()
return (p.stdout.readlines(), p.returncode)
def runcmd(cmd):
obj = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, shell=True)
(stdout, stderr) = obj.communicate()
returncode = obj.returncode
return stdout
def get_patchset_info(review):
out, exit = execute('ssh -i ~/.ssh/id_gerrit review.openstack.org gerrit '
'query %s --patch-sets --format JSON' % review)
data = json.loads(out[0])
return data
def Normalize(value):
normalized = unicodedata.normalize('NFKD', unicode(value))
normalized = normalized.encode('ascii', 'replace')
normalized.replace('\r', '')
normalized.replace('\n', ' ')
return str(normalized)