setup.py
2.3 KB
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
96
import os
import sys
import re
from urlparse import urlsplit
from commands import getoutput
def run(s):
print(s)
if os.system(s) != 0:
sys.exit()
def url2filename(url):
t = urlsplit(url)
fullpath = t.path
t = os.path.split(t.path)
return t[-1]
def debfile2name(filename):
filename = os.path.split(filename)[-1]
t = filename.split('_')
return t[0]
def wget_install(url):
filename = url2filename(url)
if not os.path.exists(filename):
run('wget ' + url)
dpkg_install(filename)
def dpkg_install(filename):
name = debfile2name(filename)
if is_installed(name):
return True
run('dpkg -i ' + filename)
def apt_get_install(name):
if is_installed(name):
return True
command = 'apt-get -y install ' + name
run(command)
def is_installed(name):
return getoutput('dpkg -l | grep %s | grep ^ii' % name)
regex = re.compile(r'^Status: install ok installed')
for line in s.splitlines():
print([line])
match = regex.search(line)
if match:
return True
def error(s):
print(s)
sys.exit()
download_list = [
'http://vpn.opensipkd.com/oracle/client/oracle-instantclient11.2-basiclite_11.2.0.3.0-2_amd64.deb',
'http://vpn.opensipkd.com/oracle/client/oracle-instantclient11.2-devel_11.2.0.3.0-2_amd64.deb',
]
apt_get_list = ['build-essential', 'python-dev', 'python-pip', 'libaio1']
try:
import cx_Oracle
error('Modul cx_Oracle sudah terpasang.')
except ImportError:
pass
for name in apt_get_list:
apt_get_install(name)
for url in download_list:
wget_install(url)
oracle_home = '/usr/lib/oracle/11.2/client64/lib'
include_orig_dir = '/usr/include/oracle/11.2/client64'
sdk_dir = '/'.join([oracle_home, 'sdk'])
include_dir = '/'.join([sdk_dir, 'include'])
if not os.path.exists(sdk_dir):
os.mkdir(sdk_dir)
if not os.path.exists(include_dir):
os.symlink(include_orig_dir, include_dir)
shared_lib_conf = '/etc/ld.so.conf.d/oracle.conf'
if not os.path.exists(shared_lib_conf):
f = open(shared_lib_conf, 'w')
f.write(oracle_home)
f.close()
run('ldconfig')
run('export ORACLE_HOME="%s"; pip install cx-oracle' % oracle_home)
try:
import cx_Oracle
print('Modul cx_Oracle berhasil dipasang.')
except ImportError, err:
print(err)