configure 7.02 KB
Newer Older
huet's avatar
huet committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#! /usr/bin/python

setup_dir="SETUP"
makefile_path="Makefile"
config_path="SETUP/config.txt"
config_link_path="SETUP/config"
config_version_path="SETUP/version.txt"
meta_makefile_path="SETUP/MMakefile"
site_entry_page_path="SITE/site_entry_page"
sitepage_en_path="SITE/index.en.html"
sitepage_fr_path="SITE/index.fr.html"
faq_page_path="SITE/faq.html"
faq_page_en_path="SITE/faq.en.html"
faq_page_fr_path="SITE/faq.fr.html"
portal_page_path="SITE/portal.html"
portal_page_en_path="SITE/portal.en.html"
portal_page_fr_path="SITE/portal.fr.html"
xml_entry_page_path="SITE/xml_entry_page"
xmlpage_path="SITE/xml.html"
goldendict_entry_path="SITE/goldendict_entry_page"
goldendict_path="SITE/goldendict.html"
meta_docintro_path="DOC/docintro"
docintro_path="DOC/docintro.tex"
makefile_keys=["TEMPLATE","PLATFORM","TRANSLIT","LEXICON","DISPLAY","WARN",
25
               "SERVERHOST","SERVERPUBLICDIR","SKTDIRURL",
26 27
               "SKTRESOURCES","CGIBINURL","CGIDIR","CGIEXT","MOUSEACTION",
               "ZENDIR"]
28
# deprecated "SCLURL","SCLINSTALLDIR","TEMPAREA","OUTPUTFONT","SERVERPROTOCOL"
29
counter_keys=["CAPTION"]
huet's avatar
huet committed
30 31 32 33 34 35 36 37 38
version_keys=["VERSION","DATE"]
TEMPLATE='#'
WARN='# WARNING - Produced from MMakefile by configure - Do not edit manually'

import sys,re,shutil,os,os.path,subprocess

def verif_config():
    if not os.path.exists(config_link_path):
        print "Error : symbolic link", config_link_path  ,"is missing"
39
        print "Please first create a symbolic link to your xxx_config.txt file."
huet's avatar
huet committed
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 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
        print """You can find examples of different configurations in
SETUP/CONFIGS directory."""
        exit(1)

def generate(config_path):
    # CONFIG FILE
    config = open (config_path,'r')
    config_content = config.read()
    config.close()
    config_pattern="([A-Z]*)='([^']*)'"
    items = {}
    items["TEMPLATE"]=TEMPLATE
    items["WARN"]=WARN
    for item in re.finditer(config_pattern, config_content):
        items[item.group(1)] = item.group(2)
    config_version = open (config_version_path, 'r')
    config_version_content = config_version.read()
    config_version.close()
    for item in re.finditer(config_pattern, config_version_content):
        items[item.group(1)] = item.group(2)    

    # MAKEFILE
    meta_makefile = open(meta_makefile_path)
    meta_makefile_content = meta_makefile.read()
    meta_makefile.close()
    for key in makefile_keys:
        meta_makefile_content = meta_makefile_content.replace('#'+key,items[key])
    meta_makefile_content = meta_makefile_content.replace('#SKTINSTALLDIR',os.getcwd()+"/")
    for key in version_keys:
        meta_makefile_content = meta_makefile_content.replace('#'+key,items[key])
    makefile = open(makefile_path,'w')
    makefile.write(meta_makefile_content)
    makefile.close()
    print makefile_path, "generated"

    # INDEX PAGE
    site_entry_page = open(site_entry_page_path,'r')
    site_entry_page_content = site_entry_page.read()
    site_entry_page.close()
    for key in counter_keys:
        site_entry_page_content = site_entry_page_content.replace('#'+key,items[key])
    for key in version_keys:
        site_entry_page_content = site_entry_page_content.replace('#'+key,items[key])

    # ENGLISH INDEX PAGE
    sitepage_en = open(sitepage_en_path,'w')
    sitepage_en_content = site_entry_page_content.replace('#LANG','en')   
    sitepage_en.write(sitepage_en_content)
    sitepage_en.close()
    print sitepage_en_path, "(en) generated"
    
    # FRENCH INDEX PAGE
    sitepage_fr = open(sitepage_fr_path,'w')
    sitepage_fr_content =  site_entry_page_content.replace('#LANG','fr')   
    sitepage_fr.write(sitepage_fr_content)
    sitepage_fr.close()
    print sitepage_fr_path, "(fr) generated"
    
    # FAQ PAGE
    faq_page = open(faq_page_path,'r')
    faq_page_content = faq_page.read()
    faq_page.close()

    # ENGLISH FAQ PAGE
    faq_page_en = open(faq_page_en_path,'w')
    faq_page_en_content = faq_page_content.replace('#LANG','en')   
    faq_page_en.write(faq_page_en_content)
    faq_page_en.close()
    print faq_page_en_path, "(en) generated"
    
    # FRENCH FAQ PAGE
    faq_page_fr = open(faq_page_fr_path,'w')
    faq_page_fr_content = faq_page_content.replace('#LANG','fr')   
    faq_page_fr.write(faq_page_fr_content)
    faq_page_fr.close()
    print faq_page_fr_path, "(fr) generated"
    
    # PORTAL PAGE
    portal_page = open(portal_page_path,'r')
    portal_page_content = portal_page.read()
    portal_page.close()

    # ENGLISH PORTAL PAGE
    portal_page_en = open(portal_page_en_path,'w')
    portal_page_en_content = portal_page_content.replace('#LANG','en')   
    portal_page_en.write(portal_page_en_content)
    portal_page_en.close()
    print portal_page_en_path, "(en) generated"
    
    # FRENCH PORTAL PAGE
    portal_page_fr = open(portal_page_fr_path,'w')
    portal_page_fr_content = portal_page_content.replace('#LANG','fr')   
    portal_page_fr.write(portal_page_fr_content)
    portal_page_fr.close()
    print portal_page_fr_path, "(fr) generated"
    
136
    # XML - obsolete, now managed by Resources
huet's avatar
huet committed
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
    xml_entry_page = open(xml_entry_page_path,'r')
    xml_entry_page_content = xml_entry_page.read()
    xml_entry_page.close()
    for key in version_keys:
        xml_entry_page_content = xml_entry_page_content.replace('#'+key,items[key])
    xmlpage = open(xmlpage_path,'w')
    xmlpage.write(xml_entry_page_content)
    xmlpage.close()
    print xmlpage_path, "generated"
    
    # GOLDEN DICT
    golden_entry_page = open(goldendict_entry_path,'r')
    golden_page_content = golden_entry_page.read()
    golden_entry_page.close()
    for key in version_keys:
        golden_page_content = golden_page_content.replace('#'+key,items[key])
    golden_page = open(goldendict_path,'w')
    golden_page.write(golden_page_content)
    golden_page.close()
    print goldendict_path, "generated"
    
    # TEX
    if os.path.exists(meta_docintro_path):
        meta_docintro = open(meta_docintro_path,'r')
        meta_docintro_content = meta_docintro.read()
        meta_docintro.close()
        for key in version_keys:
            meta_docintro_content = meta_docintro_content.replace('#'+key,items[key])
        docintro = open(docintro_path,'w')
        docintro.write(meta_docintro_content)
        docintro.close()
        print docintro_path, "generated"

def clean(): # lacks "SETUP/config.version.py" 
    if os.path.exists(makefile_path):
        os.remove(makefile_path)
        print makefile_path, "removed"
    if os.path.exists(sitepage_en_path):
        os.remove(sitepage_en_path)
        print sitepage_en_path, "removed"
    if os.path.exists(sitepage_fr_path):
        os.remove(sitepage_fr_path)
        print sitepage_fr_path, "removed"
    subprocess.call(["SETUP/config.version.py", "clean"])

# MAIN
verif_config()
if len(sys.argv) == 1:
    if os.path.exists(config_link_path):
        generate(config_link_path)
    else:
        generate(config_path)
    retcode = subprocess.call(["make", "configuration"])
elif sys.argv[1] == "light":
    if os.path.exists(config_link_path):
        generate(config_link_path)
    else:
        generate(config_path)
elif sys.argv[1] == "clean":
    clean()