updatedoc.py
Go to the documentation of this file.
00001 #! /usr/bin/env python
00002 
00003 #   Aseba - an event-based framework for distributed robot control
00004 #   Copyright (C) 2007--2011:
00005 #           Stephane Magnenat <stephane at magnenat dot net>
00006 #           (http://stephane.magnenat.net)
00007 #           and other contributors, see authors.txt for details
00008 #
00009 #   This program is free software: you can redistribute it and/or modify
00010 #   it under the terms of the GNU Lesser General Public License as published
00011 #   by the Free Software Foundation, version 3 of the License.
00012 #
00013 #   This program is distributed in the hope that it will be useful,
00014 #   but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 #   GNU Lesser General Public License for more details.
00017 #
00018 #   You should have received a copy of the GNU Lesser General Public License
00019 #   along with this program. If not, see <http://www.gnu.org/licenses/>.
00020 
00021 # System lib
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 # Custom lib
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                 }                       # used for updating help index
00040 language_map = complete_language_map.copy()    # used for fetching
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 # Update only one language?
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         # reset language map
00058         language_map.clear()
00059         language_map[lang] = url
00060 
00061 # Clean html/png/css
00062 if len(sys.argv) == 2:
00063     # Clean only one language
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     # Complete update
00072     print >> sys.stderr, "Performing a complete update"
00073     rmtree(OUTPUT_DIR, True)
00074     os.mkdir(OUTPUT_DIR)
00075 
00076 # Clean qhp
00077 try:
00078     os.remove(QHP_FILE)
00079 except OSError:
00080     # File doesn't exist
00081     pass
00082 
00083 # Reload the cached structure
00084 try:
00085     cache = open(STRUCTURE_CACHE, 'rb')
00086     wikidot.structure.unserialize(cache)
00087 except IOError:
00088     pass
00089 
00090 # Fetch the wiki, for all languages
00091 available_languages = language_map.keys()
00092 for lang in available_languages:
00093     print >> sys.stderr, "\n*** Getting doc for language ", lang, " ***"
00094     # Get + clean the output directory for the current language
00095     output = OUTPUT_DIR + '_' + lang
00096     rmtree(output, True)
00097     # Prepare the tree before fetching this language
00098     wikidot.structure.add_language(lang)
00099     wikidot.structure.set_current_language(lang)
00100     # Fetch!
00101     fetchwikidot(language_map[lang], output)
00102     # Add the CSS to output directory
00103     copy(CSS_FILE, output)
00104     # Copy from output to OUTPUT_DIR
00105     # copytree not possible, as OUTPUT_DIR already exists
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 # Save the structure for future use
00111 cache = open(STRUCTURE_CACHE, 'wb')
00112 wikidot.structure.serialize(cache)
00113 
00114 # Generate the Qt Help files
00115 # Collect all the output directories
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 # Clean Aseba Studio files
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     # File doesn't exist
00134     pass
00135 
00136 # Copy new files
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!!! :-)"


aseba
Author(s): Stéphane Magnenat
autogenerated on Sun Oct 5 2014 23:46:39