-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoelib.py
95 lines (85 loc) · 2.7 KB
/
oelib.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
95
#!/usr/bin/env python
# -------------------------------------------------------------------
# Helper functions for dist.py and make.py
# -------------------------------------------------------------------
# Copyright (C) 2007 OpenEngine.dk (See AUTHORS)
#
# This program is free software; It is covered by the GNU General
# Public License version 2 or any later version.
# See the GNU General Public License for more details (see LICENSE).
#--------------------------------------------------------------------
import string, sys, platform, subprocess, os, os.path as path
import urllib.request, urllib.parse, urllib.error, urllib.request, urllib.error, urllib.parse, zipfile, tarfile
import errno
def deleteFolder(folder):
'''
Deletes a folder at the path of folder
'''
if system("win"):
execute("rmdir /S /Q %s" % folder)
else:
execute("rm -r %s" % folder)
def mkdirp(path):
try:
os.makedirs(path)
except OSError as exc: # Python >2.5
if exc.errno == errno.EEXIST and os.path.isdir(path):
pass
else:
raise
def createFolders():
mkdirp('dependencies')
mkdirp('extensions')
mkdirp('libraries')
mkdirp('projects')
class ExecError(Exception):
"Exception thrown if execute(cmd) exited with error code != 0"
def printCommands(cmds):
print(("\n".join([f.__doc__.strip() for f,c in cmds])))
def execute(cmd):
'''
Execute system command
'''
proc = subprocess.Popen(cmd, shell=True)
proc.wait()
if proc.returncode != 0:
raise ExecError("%s exited with error code %i\n"
% (cmd, proc.returncode))
def error(err):
'''
Print error message, and exit
'''
print(err)
sys.exit(1)
def system(name):
'''
Returns true if name==any, or if name matches the system platform.
'''
if name == "any":
return True
if sys.platform.startswith("linux") and name.startswith("linux"):
if name == "linux64":
return platform.machine() == "x86_64"
elif name == "linux32":
return platform.machine() != "x86_64"
else:
return True
else:
return sys.platform.startswith(name)
def cores():
'''
Returns the number of CPUs in the system
Source: http://pyprocessing.berlios.de/
'''
try:
count = 0
if system("linux"):
count = os.sysconf('SC_NPROCESSORS_ONLN')
elif system("darwin"):
count = int(os.popen('sysctl -n hw.ncpu').read())
elif system("win"):
count = int(os.environ['NUMBER_OF_PROCESSORS'])
return max(count, 1)
# if an error occurs simply return one
except Exception: pass
return 1