2015-10-20 20:16:00 +02:00
|
|
|
#!/usr/bin/python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
import sys, os, shutil, re
|
|
|
|
|
2017-06-25 23:16:43 +02:00
|
|
|
def config_file(config, file_name, root_dir):
|
|
|
|
with open(file_name+'_pattern', 'r') as pattern_file, open(root_dir+'/'+file_name, 'w') as out_file:
|
|
|
|
for line in pattern_file:
|
|
|
|
for field, value in config.iteritems():
|
|
|
|
line = re.sub('@'+field+'@', value, line)
|
|
|
|
out_file.write(line)
|
|
|
|
|
2015-10-20 20:16:00 +02:00
|
|
|
root_dir = sys.argv[1]
|
|
|
|
|
|
|
|
if not os.path.exists(root_dir):
|
|
|
|
print "%s does not exist!" % root_dir
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
if not os.path.isdir(root_dir):
|
|
|
|
print "%s is not a directory!" % root_dir
|
|
|
|
sys.exit(1)
|
2017-02-21 09:33:27 +01:00
|
|
|
|
2015-10-20 20:16:00 +02:00
|
|
|
if len(os.listdir(root_dir))>0:
|
|
|
|
print "%s is not empty!" % root_dir
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
shutil.copytree('js', root_dir+'/js')
|
|
|
|
shutil.copytree('css', root_dir+'/css')
|
|
|
|
shutil.copytree('images', root_dir+'/images')
|
2015-10-21 09:24:23 +02:00
|
|
|
shutil.copy('favicon.ico', root_dir+'/favicon.ico')
|
2016-01-21 16:51:23 +01:00
|
|
|
|
|
|
|
|
2017-06-25 23:16:43 +02:00
|
|
|
config = dict()
|
2016-01-21 16:51:23 +01:00
|
|
|
with open('host.cfg', 'r') as host_file:
|
|
|
|
for line in host_file:
|
|
|
|
field, value = line.strip().split('@#@')
|
2017-06-25 23:16:43 +02:00
|
|
|
config[field] = value
|
|
|
|
|
|
|
|
config_file(config, 'concordia_gate.php', root_dir)
|
|
|
|
config_file(config, 'concordia_search.php', root_dir)
|
|
|
|
config_file(config, 'tm_info.php', root_dir)
|
|
|
|
config_file(config, 'tm_manager.php', root_dir)
|
2017-03-13 11:42:44 +01:00
|
|
|
|
2015-10-20 20:16:00 +02:00
|
|
|
|
2016-10-28 11:49:52 +02:00
|
|
|
versions_dir = 'versions_enabled'
|
2015-10-20 20:16:00 +02:00
|
|
|
|
|
|
|
versions = []
|
|
|
|
|
|
|
|
for version_file in os.listdir(versions_dir):
|
|
|
|
version = {'suggestions':[]}
|
|
|
|
with open(versions_dir+'/'+version_file) as v:
|
|
|
|
for line in v:
|
2017-02-21 09:33:27 +01:00
|
|
|
|
2015-10-20 20:16:00 +02:00
|
|
|
field, value = line.strip().split('@#@')
|
|
|
|
if field == 'suggestion':
|
|
|
|
version['suggestions'].append(value)
|
|
|
|
else:
|
|
|
|
version[field] = value
|
|
|
|
versions.append(version)
|
|
|
|
|
2017-02-21 09:33:27 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-01-21 16:51:23 +01:00
|
|
|
|
|
|
|
|
2015-10-20 20:16:00 +02:00
|
|
|
for version in versions:
|
|
|
|
version_dir = root_dir+'/'+version['dir']
|
|
|
|
os.mkdir(version_dir)
|
|
|
|
with open('index.html_pattern', 'r') as pattern_file:
|
|
|
|
with open(version_dir+'/index.html', 'w') as index_file:
|
|
|
|
for line in pattern_file:
|
|
|
|
for field, value in version.iteritems():
|
|
|
|
if field == 'suggestions':
|
|
|
|
suggestions_html = ''
|
|
|
|
for suggestion in value:
|
2015-10-21 09:24:23 +02:00
|
|
|
suggestions_html+='<li>'+suggestion+' <span class="suggestion" onclick="searchText(\''+suggestion+'\', '+version['tmid']+');">apply</span></li>'
|
2015-10-20 20:16:00 +02:00
|
|
|
line = re.sub('@suggestions@', suggestions_html, line)
|
|
|
|
else:
|
|
|
|
line = re.sub('@'+field+'@', value, line)
|
|
|
|
index_file.write(line)
|