1 """
   2     InterWiki server module
   3 
   4     @copyright: LinuxWiki:ThomasWaldmann
   5     @license: GPL, see COPYING for details
   6 """
   7 
   8 import xmlrpclib, pickle
   9 
  10 sisterlist = {
  11     # name:        (type,       url                      )
  12     'LinuxWiki':   ('MoinMoin', 'http://linuxwiki.org/', ),
  13     'JuraWiki':    ('MoinMoin', 'http://jurawiki.de/',   ),
  14 }
  15 
  16 sistersets = {}
  17 
  18 def getPageList(wikiname):
  19     """ get the pagelist from a wiki
  20     """
  21     type, url = sisterlist[wikiname]
  22     if type == 'MoinMoin':
  23         srcwiki = xmlrpclib.ServerProxy(url+"?action=xmlrpc2")
  24         pages = srcwiki.getAllPages()
  25     return pages
  26 
  27 def collectpages():
  28     """ Iterate over sistersites, get pagelists of them and add them to the sets
  29     """
  30     for wiki in sisterlist:
  31         pages = getPageList(wiki)
  32         for page in pages:
  33             sets = findSetByMember(wiki, page, create=True)
  34             for set in sets:
  35                 addMember(set, wiki, page)
  36 
  37 def addMember(set, wiki, page, newstatus=None):
  38     """ add an interwiki link to a set of interwiki links
  39         newstatus
  40           == None means that we want to add the interwiki link as member of this set, if allowed
  41           == True means that we explicitely want the interwiki link as a member of this set (force)
  42           == False means that we explicitely exclude this page from being a member of this set (force)
  43     """
  44     try:
  45         oldstatus = set[(wiki,page)]
  46     except KeyError:
  47         oldstatus = None
  48     if oldstatus == None or newstatus != None:
  49         set[(wiki,page)] = newstatus
  50 
  51 def delMember(set, wiki, page):
  52     """ remove an interwiki link from a set of interwiki links
  53     """
  54     try:
  55         del set[(wiki,page)]
  56     except KeyError:
  57         pass
  58 
  59 def findSetByKey(key, create=False):
  60     """ find a set by giving the key (normally the pagename),
  61         if there is no such set, create a new, empty one.
  62     """
  63     global sistersets
  64     try:
  65         set = sistersets[key]
  66     except KeyError:
  67         if create:
  68             set = sistersets[key] = {}
  69         else:
  70             set = None
  71     return set
  72 
  73 def findSetByMember(wiki, page, create=False):
  74     """ return the list of sets that have a specific member
  75     """
  76     global sistersets
  77     result = []
  78     for set in sistersets.values():
  79         if set.has_key((wiki,page)):
  80             result.append(set)
  81     if not result and create:
  82         sistersets[page] = {}
  83         result.append(sistersets[page])
  84     return result
  85 
  86 def getSisterPages(wiki, page):
  87     sets = findSetByMember(wiki, page)
  88     result = []
  89     for set in sets:
  90         for interwiki in set:
  91             if set[interwiki] == None:
  92                 result.append(interwiki)
  93     for set in sets:
  94         for interwiki in set:
  95             if set[interwiki] == False:
  96                 result.remove(interwiki)
  97     for set in sets:
  98         for interwiki in set:
  99             if set[interwiki] == True and not interwiki in result:
 100                 result.append(interwiki)
 101     return result            
 102 
 103 def execute(xmlrpcobj, *args):
 104     cfg = xmlrpcobj.request.cfg
 105     fname = "%s/%s" % (cfg.data_dir, 'sistersets.pickle')
 106     f = open(fname, 'r')
 107     sistersets = pickle.load(f)
 108     return getSisterPages(*args)
 109 
 110 if 0:
 111     collectpages()
 112     f = open('sistersets.pickle','w')
 113     pickle.dump(sistersets, f)
 114 
 115 #print repr(getSisterPages('LinuxWiki','StartSeite'))

MoinMoin: SisterServerCode (last edited 2007-10-29 19:12:14 by localhost)