|
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 |
|
|
|
11 |
|
|
31
|
12 |
""" |
|
|
13 |
import os |
|
|
14 |
import subprocess |
|
|
15 |
import re |
|
|
16 |
|
|
|
17 |
here = os.path.dirname(os.path.abspath(__file__)) |
|
|
18 |
base_dir = os.path.dirname(here) |
|
|
19 |
script_name = os.path.join(base_dir, 'blinkster-boot.py') |
|
|
20 |
|
|
|
21 |
import virtualenv |
|
|
22 |
|
|
|
23 |
# things to install |
|
|
24 |
# - psycopg2 |
|
|
25 |
# - PIL |
|
|
26 |
# - pylucene |
|
|
27 |
# - pyxml |
|
|
28 |
# - 4Suite-xml |
|
|
29 |
|
|
|
30 |
|
|
|
31 |
EXTRA_TEXT = """ |
|
|
32 |
|
|
|
33 |
import shutil |
|
32
|
34 |
import tarfile |
|
|
35 |
import urllib |
|
31
|
36 |
|
|
|
37 |
def extend_parser(parser): |
|
|
38 |
parser.add_option( |
|
|
39 |
'--svn', |
|
|
40 |
metavar='DIR_OR_URL', |
|
|
41 |
dest='fassembler_svn', |
|
|
42 |
default=FASS_SVN_LOCATION, |
|
|
43 |
help='Location of a svn directory or URL to use for the installation of fassembler') |
|
|
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 |
|
|
|
58 |
def after_install(options, home_dir): |
|
|
59 |
base_dir = os.path.dirname(home_dir) |
|
|
60 |
src_dir = join(home_dir, 'src') |
|
32
|
61 |
tmp_dir = join(home_dir, 'tmp') |
|
|
62 |
ensure_dir(src_dir) |
|
|
63 |
ensure_dir(tmp_dir) |
|
|
64 |
#logger.indent += 2 |
|
31
|
65 |
try: |
|
32
|
66 |
call_subprocess([os.path.abspath(join(home_dir, 'bin', 'easy_install')), 'psycopg2'], |
|
|
67 |
cwd=os.path.abspath(tmp_dir), |
|
|
68 |
filter_stdout=filter_python_develop, |
|
|
69 |
show_stdout=False) |
|
|
70 |
call_subprocess([os.path.abspath(join(home_dir, 'bin', 'easy_install')), 'pyxml'], |
|
|
71 |
cwd=os.path.abspath(tmp_dir), |
|
|
72 |
filter_stdout=filter_python_develop, |
|
|
73 |
show_stdout=False) |
|
|
74 |
call_subprocess([os.path.abspath(join(home_dir, 'bin', 'easy_install')), '4suite-xml'], |
|
|
75 |
cwd=os.path.abspath(tmp_dir), |
|
31
|
76 |
filter_stdout=filter_python_develop, |
|
|
77 |
show_stdout=False) |
|
32
|
78 |
call_subprocess([os.path.abspath(join(home_dir, 'bin', 'easy_install')), 'pil'], |
|
|
79 |
cwd=os.path.abspath(tmp_dir), |
|
|
80 |
filter_stdout=filter_python_develop, |
|
|
81 |
show_stdout=False) |
|
|
82 |
call_subprocess([os.path.abspath(join(home_dir, 'bin', 'easy_install')), 'pil'], |
|
|
83 |
cwd=os.path.abspath(tmp_dir), |
|
31
|
84 |
filter_stdout=filter_python_develop, |
|
|
85 |
show_stdout=False) |
|
32
|
86 |
|
|
|
87 |
#get pylucene |
|
|
88 |
#cd jcc |
|
|
89 |
#install jcc |
|
|
90 |
#cd pylucene |
|
|
91 |
#instqll pylucene |
|
|
92 |
#delete src |
|
|
93 |
#call_subprocess([os.path.abspath(join(home_dir, 'bin', 'python')), 'setup.py', 'develop'], |
|
|
94 |
# cwd=os.path.abspath(fassembler_dir), |
|
|
95 |
# filter_stdout=filter_python_develop, |
|
|
96 |
# show_stdout=False) |
|
31
|
97 |
finally: |
|
|
98 |
logger.indent -= 2 |
|
|
99 |
script_dir = join(base_dir, 'bin') |
|
|
100 |
logger.notify('Run "%s Package" to install new packages that provide builds' |
|
32
|
101 |
% join(script_dir, 'easy_install')) |
|
31
|
102 |
|
|
32
|
103 |
def ensure_dir(dir): |
|
31
|
104 |
if not os.path.exists(dir): |
|
|
105 |
logger.info('Creating directory %s' % dir) |
|
|
106 |
os.makedirs(dir) |
|
|
107 |
|
|
|
108 |
def filter_python_develop(line): |
|
|
109 |
if not line.strip(): |
|
|
110 |
return Logger.DEBUG |
|
|
111 |
for prefix in ['Searching for', 'Reading ', 'Best match: ', 'Processing ', |
|
|
112 |
'Moving ', 'Adding ', 'running ', 'writing ', 'Creating ', |
|
|
113 |
'creating ', 'Copying ']: |
|
|
114 |
if line.startswith(prefix): |
|
|
115 |
return Logger.DEBUG |
|
|
116 |
return Logger.NOTIFY |
|
|
117 |
""" |
|
|
118 |
|
|
|
119 |
def main(): |
|
|
120 |
text = virtualenv.create_bootstrap_script(EXTRA_TEXT, python_version='2.4') |
|
|
121 |
if os.path.exists(script_name): |
|
|
122 |
f = open(script_name) |
|
|
123 |
cur_text = f.read() |
|
|
124 |
f.close() |
|
|
125 |
else: |
|
|
126 |
cur_text = '' |
|
|
127 |
print 'Updating %s' % script_name |
|
|
128 |
if cur_text == 'text': |
|
|
129 |
print 'No update' |
|
|
130 |
else: |
|
|
131 |
print 'Script changed; updating...' |
|
|
132 |
f = open(script_name, 'w') |
|
|
133 |
f.write(text) |
|
|
134 |
f.close() |
|
|
135 |
|
|
|
136 |
if __name__ == '__main__': |
|
|
137 |
main() |
|
|
138 |
|