-
Notifications
You must be signed in to change notification settings - Fork 298
/
update-ips.py
executable file
·94 lines (75 loc) · 2.87 KB
/
update-ips.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env python
# Francesco Conti <[email protected]>
#
# Copyright (C) 2016 ETH Zurich, University of Bologna.
# All rights reserved.
import sys,os,subprocess,re
devnull = open(os.devnull, 'wb')
def execute(cmd, silent=False):
if silent:
stdout = devnull
else:
stdout = None
return subprocess.call(cmd.split(), stdout=stdout)
def execute_out(cmd, silent=False):
p = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE)
out, err = p.communicate()
return out
def find_server():
stdout = execute_out("git remote -v")
stdout = stdout.split('\n')
for line in stdout:
if "origin" in line:
tmp = line.split(' ')
tmp = tmp[0].split('\t')
remote = tmp[1]
if "https://" in remote:
# first remove the https, we'll put it back later
remote = remote[8:]
# now we have to remove the pulpino.git suffix and figure out the group
tmp = remote.split('/', 2)
server = "https://%s" % (tmp[0])
group = tmp[1]
remote = "%s/%s" % (server, group)
else:
# now we have to remove the pulpino.git suffix and figure out the group
remote = remote.rsplit('/', 1)[0]
tmp = remote[::-1]
tmp = re.split(r'[:/]', tmp, 1)
server = tmp[1][::-1]
group = tmp[0][::-1]
return [server, group, remote]
print tcolors.ERROR + "ERROR: could not find remote server." + tcolors.ENDC
sys.exit(1)
if len(sys.argv) > 1:
server = sys.argv[1]
group = "pulp-open"
if "http" in server:
remote = "%s/%s" % (server, group)
else:
remote = "%s:%s" % (server, group)
if not vars().has_key('server'):
[server, group, remote] = find_server()
print "Using remote git server %s, remote is %s" % (server, remote)
# download IPApproX tools in ./ipstools and import them
if os.path.exists("ipstools") and os.path.isdir("ipstools"):
cwd = os.getcwd()
os.chdir("ipstools")
execute("git pull origin verilator-pulpino", silent=True)
os.chdir(cwd)
import ipstools
else:
# try to find the ipstools repository
if "http" in remote:
if execute("git clone %s/IPApproX.git ipstools -b verilator-pulpino" % (remote)) != 0:
execute("git clone %s/pulp-tools/IPApproX.git ipstools -b verilator-pulpino" % (server))
else:
if execute("git clone %s/IPApproX.git ipstools -b verilator-pulpino" % (remote)) != 0:
execute("git clone %s:pulp-tools/IPApproX.git ipstools -b verilator-pulpino" % (server))
import ipstools
# creates an IPApproX database
ipdb = ipstools.IPDatabase(ips_dir="./ips", skip_scripts=True)
# updates the IPs from the git repo
ipdb.update_ips(remote = remote)
# launch generate-ips.py
execute("./generate-scripts.py")