|
31
|
1 |
""" |
|
32
|
2 |
Call this like ``python fassembler/create_python_env.py``; it will |
|
|
3 |
refresh the blinkster-boot.py script |
|
|
4 |
|
|
|
5 |
-prerequisite: |
|
|
6 |
|
|
|
7 |
- virtualenv |
|
|
8 |
- distribute |
|
|
9 |
- psycopg2 requires the PostgreSQL libpq libraries and the pg_config utility |
|
|
10 |
|
|
33
|
11 |
- virtualenv --distribute --no-site-packages venv |
|
32
|
12 |
|
|
31
|
13 |
""" |
|
|
14 |
import os |
|
|
15 |
import subprocess |
|
|
16 |
import re |
|
|
17 |
|
|
|
18 |
here = os.path.dirname(os.path.abspath(__file__)) |
|
|
19 |
base_dir = os.path.dirname(here) |
|
|
20 |
script_name = os.path.join(base_dir, 'blinkster-boot.py') |
|
|
21 |
|
|
|
22 |
import virtualenv |
|
|
23 |
|
|
|
24 |
# things to install |
|
33
|
25 |
# - psycopg2 -> pip |
|
|
26 |
# - PIL -> pip |
|
|
27 |
# - pyxml -> pip |
|
|
28 |
# - 4Suite-xml - easy_install ftp://ftp.4suite.org/pub/4Suite/4Suite-XML-1.0.2.tar.bz2 |
|
|
29 |
# - pylucene - script |
|
|
30 |
|
|
31
|
31 |
|
|
|
32 |
|
|
|
33 |
EXTRA_TEXT = """ |
|
|
34 |
|
|
|
35 |
import shutil |
|
32
|
36 |
import tarfile |
|
|
37 |
import urllib |
|
31
|
38 |
|
|
33
|
39 |
4SUITE_XML_URL = 'ftp://ftp.4suite.org/pub/4Suite/4Suite-XML-1.0.2.tar.bz2' |
|
|
40 |
PY_LUCENE_URL = 'http://apache.crihan.fr/dist/lucene/pylucene/pylucene-3.0.1-1-src.tar.gz' |
|
|
41 |
|
|
31
|
42 |
def extend_parser(parser): |
|
33
|
43 |
pass |
|
31
|
44 |
|
|
|
45 |
def adjust_options(options, args): |
|
|
46 |
if not args: |
|
|
47 |
return # caller will raise error |
|
|
48 |
|
|
|
49 |
# We're actually going to build the venv in a subdirectory |
|
|
50 |
base_dir = args[0] |
|
32
|
51 |
if len(args) > 1: |
|
|
52 |
venv_name = args[1] |
|
|
53 |
else: |
|
|
54 |
venv_name = "blinkster" |
|
|
55 |
|
|
|
56 |
args[0] = join(base_dir, venv_name) |
|
31
|
57 |
|
|
33
|
58 |
|
|
31
|
59 |
def after_install(options, home_dir): |
|
|
60 |
base_dir = os.path.dirname(home_dir) |
|
|
61 |
src_dir = join(home_dir, 'src') |
|
32
|
62 |
tmp_dir = join(home_dir, 'tmp') |
|
|
63 |
ensure_dir(src_dir) |
|
|
64 |
ensure_dir(tmp_dir) |
|
|
65 |
#logger.indent += 2 |
|
31
|
66 |
try: |
|
33
|
67 |
call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), ,'-E '+ os.path.abspath(home_dir), 'psycopg2', 'pil', 'pyxml'], |
|
32
|
68 |
cwd=os.path.abspath(tmp_dir), |
|
|
69 |
filter_stdout=filter_python_develop, |
|
|
70 |
show_stdout=False) |
|
33
|
71 |
call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'easy_install')), 4SUITE_XML_URL], |
|
32
|
72 |
cwd=os.path.abspath(tmp_dir), |
|
31
|
73 |
filter_stdout=filter_python_develop, |
|
|
74 |
show_stdout=False) |
|
32
|
75 |
|
|
33
|
76 |
#get pylucene |
|
|
77 |
pylucene_src = os.path.join(src_dir,"pylucene.tar.gz") |
|
|
78 |
urllib.urlretrieve(PY_LUCENE_URL, pylucene_src) |
|
|
79 |
tf = tarfile.open(pylucene_src,'r:gz') |
|
|
80 |
tf.extractall(os.path.join(src_dir,"pylucene")) |
|
|
81 |
tf.close() |
|
|
82 |
#install jcc |
|
|
83 |
call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'python')), 'setup.py', 'install'], |
|
|
84 |
cwd=os.path.abspath(os.path.join(src_dir,"pylucene","pylucene-3.0.1-1","jcc")), |
|
|
85 |
filter_stdout=filter_python_develop, |
|
|
86 |
show_stdout=False) |
|
|
87 |
#install pylucene |
|
|
88 |
#modify makefile |
|
|
89 |
#PREFIX_PYTHON=os.path.abspath(fassembler_dir) |
|
|
90 |
#ANT=ant |
|
|
91 |
#PYTHON=$(PREFIX_PYTHON)/bin/python |
|
|
92 |
#osx 10.5 10.6 32-64 bit |
|
|
93 |
#JCC=$(PYTHON) -m jcc.__main__ --shared --arch x86_64 --arch i386 |
|
|
94 |
#NUM_FILES=2 |
|
|
95 |
|
|
|
96 |
#linux |
|
|
97 |
#JCC=$(PYTHON) -m jcc --shared |
|
|
98 |
#NUM_FILES=2 |
|
|
99 |
|
|
|
100 |
# windows |
|
|
101 |
#JCC=$(PYTHON) -m jcc --shared |
|
|
102 |
#NUM_FILES=3 |
|
|
103 |
|
|
|
104 |
|
|
|
105 |
#install pylucene |
|
32
|
106 |
#delete src |
|
|
107 |
#call_subprocess([os.path.abspath(join(home_dir, 'bin', 'python')), 'setup.py', 'develop'], |
|
|
108 |
# cwd=os.path.abspath(fassembler_dir), |
|
|
109 |
# filter_stdout=filter_python_develop, |
|
|
110 |
# show_stdout=False) |
|
31
|
111 |
finally: |
|
33
|
112 |
#logger.indent -= 2 |
|
31
|
113 |
script_dir = join(base_dir, 'bin') |
|
|
114 |
logger.notify('Run "%s Package" to install new packages that provide builds' |
|
32
|
115 |
% join(script_dir, 'easy_install')) |
|
31
|
116 |
|
|
32
|
117 |
def ensure_dir(dir): |
|
31
|
118 |
if not os.path.exists(dir): |
|
|
119 |
logger.info('Creating directory %s' % dir) |
|
|
120 |
os.makedirs(dir) |
|
|
121 |
|
|
|
122 |
def filter_python_develop(line): |
|
|
123 |
if not line.strip(): |
|
|
124 |
return Logger.DEBUG |
|
|
125 |
for prefix in ['Searching for', 'Reading ', 'Best match: ', 'Processing ', |
|
|
126 |
'Moving ', 'Adding ', 'running ', 'writing ', 'Creating ', |
|
|
127 |
'creating ', 'Copying ']: |
|
|
128 |
if line.startswith(prefix): |
|
|
129 |
return Logger.DEBUG |
|
|
130 |
return Logger.NOTIFY |
|
|
131 |
""" |
|
|
132 |
|
|
|
133 |
def main(): |
|
33
|
134 |
python_version = ".".join(map(str,sys.version_info[0:2])) |
|
|
135 |
text = virtualenv.create_bootstrap_script(EXTRA_TEXT, python_version=python_version) |
|
31
|
136 |
if os.path.exists(script_name): |
|
|
137 |
f = open(script_name) |
|
|
138 |
cur_text = f.read() |
|
|
139 |
f.close() |
|
|
140 |
else: |
|
|
141 |
cur_text = '' |
|
|
142 |
print 'Updating %s' % script_name |
|
|
143 |
if cur_text == 'text': |
|
|
144 |
print 'No update' |
|
|
145 |
else: |
|
|
146 |
print 'Script changed; updating...' |
|
|
147 |
f = open(script_name, 'w') |
|
|
148 |
f.write(text) |
|
|
149 |
f.close() |
|
|
150 |
|
|
|
151 |
if __name__ == '__main__': |
|
|
152 |
main() |
|
|
153 |
|