$search
00001 # Aseba - an event-based framework for distributed robot control 00002 # Copyright (C) 2007--2011: 00003 # Stephane Magnenat <stephane at magnenat dot net> 00004 # (http://stephane.magnenat.net) 00005 # and other contributors, see authors.txt for details 00006 # 00007 # This program is free software: you can redistribute it and/or modify 00008 # it under the terms of the GNU Lesser General Public License as published 00009 # by the Free Software Foundation, version 3 of the License. 00010 # 00011 # This program is distributed in the hope that it will be useful, 00012 # but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 # GNU Lesser General Public License for more details. 00015 # 00016 # You should have received a copy of the GNU Lesser General Public License 00017 # along with this program. If not, see <http://www.gnu.org/licenses/>. 00018 00019 import sys 00020 import pickle 00021 00022 from wikidot.urltoname import urltoname 00023 from wikidot.tree import WikiNode 00024 00025 # Global variables used to build the wiki's structure 00026 __structure__ = dict() 00027 __lang__ = '' 00028 00029 def add_language(lang): 00030 """Create a new entry for this language in the dictionary""" 00031 global __structure__ 00032 __structure__[lang] = WikiNode('root_' + lang, '') 00033 00034 def set_current_language(lang): 00035 """Set the current language, for future insertions""" 00036 global __lang__ 00037 __lang__ = lang 00038 00039 def get_structure(lang): 00040 """Return the tree corresponding to a specific language""" 00041 return __structure__[lang] 00042 00043 def insert(title, url, breadcrumbs = set()): 00044 """Insert a page into the current tree 00045 00046 Set the current language using the 'set_current_language()' function.""" 00047 00048 global __structure__ 00049 # convert url 00050 page_link = urltoname(url) 00051 # convert breadcrumbs 00052 page_breadcrumbs = list() 00053 for x in breadcrumbs: 00054 page_breadcrumbs.append(urltoname(x)) 00055 if __lang__ != '': 00056 __structure__[__lang__].insert(title, page_link, page_breadcrumbs) 00057 # print >> sys.stderr, "**** Dump after insert:" 00058 # __structure__[__lang__].dump() 00059 else: 00060 print >> sys.stderr, "*** Error in wikidot.structure.insert: set the language beforehand" 00061 00062 def serialize(f): 00063 pickler = pickle.Pickler(f) 00064 pickler.dump(__lang__) 00065 pickler.dump(__structure__) 00066 00067 def unserialize(f): 00068 global __lang__ 00069 global __structure__ 00070 pickler = pickle.Unpickler(f) 00071 __lang__ = pickler.load() 00072 __structure__ = pickler.load() 00073