Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 import os
00023 import os.path
00024 import sys
00025 from shutil import rmtree
00026 from shutil import copytree
00027 from shutil import copy
00028
00029
00030 from wikidot.fetch import fetchwikidot
00031 import wikidot.structure
00032 import qthelp
00033
00034 complete_language_map = {
00035 'en':'http://aseba.wikidot.com/en:asebausermanual',
00036 'fr':'http://aseba.wikidot.com/fr:asebausermanual',
00037 'de':'http://aseba.wikidot.com/de:asebausermanual',
00038 'es':'http://aseba.wikidot.com/es:asebausermanual'
00039 }
00040 language_map = complete_language_map.copy()
00041 OUTPUT_DIR = 'doc'
00042 QHP_FILE = './aseba-doc.qhp'
00043 CSS_FILE = './css/aseba.css'
00044 STUDIO_PATH = '../../studio/'
00045 STRUCTURE_CACHE = 'structure.cache'
00046
00047
00048 if len(sys.argv) == 2:
00049 lang = sys.argv[1]
00050 url = None
00051 try:
00052 url = language_map[lang]
00053 except KeyError:
00054 print >> sys.stderr, "The language ", lang, " is not valid"
00055 exit(1)
00056 else:
00057
00058 language_map.clear()
00059 language_map[lang] = url
00060
00061
00062 if len(sys.argv) == 2:
00063
00064 lang = sys.argv[1]
00065 print >> sys.stderr, "Performing a partial update"
00066 files = os.listdir(OUTPUT_DIR)
00067 for f in files:
00068 if f.find(lang + '_') == 0:
00069 os.remove(os.path.join(OUTPUT_DIR, f))
00070 else:
00071
00072 print >> sys.stderr, "Performing a complete update"
00073 rmtree(OUTPUT_DIR, True)
00074 os.mkdir(OUTPUT_DIR)
00075
00076
00077 try:
00078 os.remove(QHP_FILE)
00079 except OSError:
00080
00081 pass
00082
00083
00084 try:
00085 cache = open(STRUCTURE_CACHE, 'rb')
00086 wikidot.structure.unserialize(cache)
00087 except IOError:
00088 pass
00089
00090
00091 available_languages = language_map.keys()
00092 for lang in available_languages:
00093 print >> sys.stderr, "\n*** Getting doc for language ", lang, " ***"
00094
00095 output = OUTPUT_DIR + '_' + lang
00096 rmtree(output, True)
00097
00098 wikidot.structure.add_language(lang)
00099 wikidot.structure.set_current_language(lang)
00100
00101 fetchwikidot(language_map[lang], output)
00102
00103 copy(CSS_FILE, output)
00104
00105
00106 listing = os.listdir(output)
00107 for y in listing:
00108 copy(os.path.join(output, y), os.path.join(OUTPUT_DIR, y))
00109
00110
00111 cache = open(STRUCTURE_CACHE, 'wb')
00112 wikidot.structure.serialize(cache)
00113
00114
00115
00116 output_directories = list()
00117 available_languages = list()
00118 for lang in complete_language_map.keys():
00119 f = OUTPUT_DIR + '_' + lang
00120 if os.path.isdir(f):
00121 output_directories.append(f)
00122 available_languages.append(lang)
00123 qthelp.generate(output_directories, OUTPUT_DIR, available_languages, QHP_FILE)
00124
00125
00126 print >> sys.stderr, "\nCleaning Aseba Studio directory..."
00127 studio_output_dir = os.path.join(STUDIO_PATH, OUTPUT_DIR)
00128 studio_doc_qhp = os.path.join(STUDIO_PATH, QHP_FILE)
00129 rmtree(studio_output_dir)
00130 try:
00131 os.remove(studio_doc_qhp)
00132 except OSError:
00133
00134 pass
00135
00136
00137 print >> sys.stderr, "\nCopying new files to Aseba Studio..."
00138 copytree(OUTPUT_DIR, studio_output_dir)
00139 copy(QHP_FILE, STUDIO_PATH)
00140
00141 print >> sys.stderr, "Finished!!! :-)"