-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathess.py
66 lines (53 loc) · 1.69 KB
/
ess.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
import os
import re
filenamelist=[]
for dpath,dname,filename in os.walk("/usr/lib/R/library"):
######
for filename in filename:
if filename == ("NAMESPACE"):
fpath = os.path.join(dpath,filename)
filenamelist.append(fpath)
## for dpath,dname,filename in os.walk("/usr/lib/R/library"):
## for filename in filename:
## r =open(os.path.join(dpath,filename))
## for line in r:
## print line
mer=[]
for file__ in filenamelist:
f = open(file__)
p1 = re.compile('export\(')
frag = 0
strfrag = 0
for line in f:
if line[0:7] == 'export(' and ")" not in line:
frag = 1
line = line.strip()
line = p1.sub("",line)
mer.append(line)
elif line[0:7] == 'export(' and ")" in line:
frag= 0
line = line.strip()
line = re.sub("\)",",",line)
line = p1.sub("",line)
mer.append(line)
elif frag == 1 and ")" not in line and "#" not in line:
line = line.strip()
mer.append(line)
elif frag == 1 and ")" in line and "#" not in line:
frag = 0
line = line.strip()
line = re.sub("\)",",",line)
mer.append(line)
elif frag == 1 and ")" not in line and "#" in line:
frag = 1
elif frag == 1 and ")" in line and "#" in line:
frag = 1
else:
frag = 0
out = "".join(mer)
out = re.sub(" ","",out)
out = re.sub('\"',"",out)
out = re.sub(",","\" \"",out)
out = re.sub("^""",'\"',out)
out = re.sub("$""",'\"',out)
print out