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 import sys
00020 import pickle
00021
00022 from wikidot.urltoname import urltoname
00023 from wikidot.tree import WikiNode
00024
00025
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
00050 page_link = urltoname(url)
00051
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
00058
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