-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildbinpkg.py
executable file
·91 lines (72 loc) · 2.64 KB
/
buildbinpkg.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
#!/usr/bin/env python
import os
import sys
import subprocess
import shutil
import buildsrcdist
import platform
def getRVersion():
txt = subprocess.check_output([ "R", "--version" ], stderr = subprocess.STDOUT)
fullVersion = txt.splitlines()[0].split()[2]
versionNumbers = map(int,fullVersion.split("."))
return "{}.{}".format(*versionNumbers)
def getPackageFileName(logFileName):
with open(logFileName, "rt") as f:
l = f.readline()
while l:
l = l.strip()
print(l)
if l.startswith("packaged installation of"):
s = " as "
idx = l.find(s)
if idx >= 0:
idx += 4
while not l[idx].isalpha():
idx += 1
startPos = idx
endPos = len(l)-1
while not l[endPos].isalpha():
endPos -= 1
return l[startPos:endPos+1]
l = f.readline()
def main():
Rversion = getRVersion()
print("R {}".format(Rversion))
instDir = sys.argv[1]
startDir = os.getcwd()
os.mkdir(instDir)
curDir = os.getcwd()
os.chdir(instDir)
instDir = os.getcwd()
tmpLibDir = os.path.join(instDir, "tmpLibDir")
os.mkdir(tmpLibDir)
Rexe = buildsrcdist.getRCommand();
os.chdir(startDir)
tmpSrcDir, srcPackName = buildsrcdist.createSourcePackage(Rexe)
os.chdir(instDir)
print tmpSrcDir, srcPackName
logFileName = "rlogfile"
try:
with open(logFileName, "wt") as logfile:
subprocess.call([ Rexe, "CMD", "INSTALL", os.path.join(tmpSrcDir, srcPackName), "--build", "-l", tmpLibDir ],
stdout=logfile, stderr=logfile)
finally:
shutil.rmtree(tmpSrcDir)
pkgFile = getPackageFileName(logFileName)
os.remove(logFileName)
print("Package name is %s" % pkgFile)
if platform.system() == "Windows": # Windows
os.makedirs("bin/windows/contrib/{}/".format(Rversion))
shutil.move(pkgFile, "bin/windows/contrib/{}/".format(Rversion))
elif platform.system() == "Darwin": # OS X
os.makedirs("bin/macosx/mavericks/contrib/{}/".format(Rversion))
#os.makedirs("bin/macosx/contrib/3.0/")
#os.makedirs("bin/macosx/contrib/3.1/")
#shutil.copy(pkgFile, "bin/macosx/contrib/3.0/")
#shutil.copy(pkgFile, "bin/macosx/contrib/3.1/")
shutil.move(pkgFile, "bin/macosx/mavericks/contrib/{}/".format(Rversion))
else:
print("Unknown platform, not creating directory structure")
shutil.rmtree(tmpLibDir)
if __name__ == "__main__":
main()