-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathinstall.py
68 lines (52 loc) · 2.13 KB
/
install.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
import platform
import shutil
import os
import re
OS_VERSION = platform.system()
OS_BITS = platform.architecture()[0]
LIB_NLPIR = 'libNLPIR.so' if OS_VERSION == 'Linux' else 'NLPIR.dll'
SCRIPT_SUFFIX = '.sh' if OS_VERSION == 'Linux' else '.bat'
def is_swig_installed():
for cmdpath in os.environ['PATH'].split(':'):
if os.path.isdir(cmdpath) and 'swig' in os.listdir(cmdpath):
return True
def check_installers():
swig_pattern = re.compile(r'^swig-(?P<swig_version>[\d\.]+)')
pcre_pattern = re.compile(r'^pcre-(?P<pcre_version>[\d\.]+)')
for f in os.listdir('dependences'):
if swig_pattern.match(f):
swig_version = swig_pattern.match(f).groups('swig_version')[0][0:-1]
elif pcre_pattern.match(f):
pcre_version = pcre_pattern.match(f).groups('pcre_version')[0][0:-1]
if swig_version is None:
raise 'swig tarball not found!'
elif pcre_version is None:
raise 'pcre tarball not found!'
def install_swig():
if OS_VERSION == 'Windows':
# TODO Add swig installation scripts in Windows.
print 'SWIG should be installed manually in Windows'
return
os.system(os.path.join('scripts', 'install_swig' + SCRIPT_SUFFIX))
def install_nlpir():
print 'Generate NLPIR wrapper.'
os.system('swig -c++ -python NLPIR.interface')
lib_dir = os.path.join(os.curdir, 'lib', ('linux' if OS_VERSION == 'Linux' else 'win') + OS_BITS.replace('bit', ''))
if OS_VERSION == 'Linux':
lib_target = os.path.join('/usr', 'lib')
elif OS_VERSION == 'Windows':
lib_target = os.path.join(os.environ['SYSTEMROOT'], 'system32')
pass
print 'Copy %s to %s' % (LIB_NLPIR, lib_target)
shutil.copy(os.path.join(lib_dir, LIB_NLPIR), os.path.join(lib_target, LIB_NLPIR))
print 'Install PyNLPIR.'
os.system('python setup.py build_ext --inplace')
os.system('python setup.py install')
if __name__ == '__main__':
if not is_swig_installed():
check_installers()
install_swig()
if is_swig_installed():
install_nlpir()
else:
print 'Make sure that SWIG have been installed already.'