Back to index

moin  1.9.0~rc2
po2wiki.py
Go to the documentation of this file.
00001 #!/usr/bin/python
00002 """
00003     remove everthing top of the first msgid line (PIs destroyed by gettext),
00004     prepend some processing instructions to a .po file to be able to put it
00005     onto moinmaster wiki, letting it get processed by gettext parser
00006 """
00007 
00008 master_url = "http://master19.moinmo.in/?action=xmlrpc2"
00009 user = "ThomasWaldmann" # must be a known Wiki account
00010 
00011 import sys, os
00012 import xmlrpclib
00013 
00014 password = os.environ.get("PASS", "")
00015 sys.path.insert(0, '../..')
00016 
00017 def run():
00018     excluded = ["en", ] # languages managed in repository, not in wiki
00019 
00020     lang = sys.argv[1]
00021 
00022     data = sys.stdin.read()
00023 
00024     if lang in excluded:
00025         f = open("%s.MoinMoin.po" % lang, "w")
00026         f.write(data)
00027         f.close()
00028         sys.exit(0)
00029 
00030     data = data.decode('utf-8')
00031 
00032     cutpos = data.index(u"msgid")
00033     data = data[cutpos:] # remove comments at top
00034 
00035     data = u"""\
00036 ## Please edit system and help pages ONLY in the master wiki!
00037 ## For more information, please see MoinMoin:MoinDev/Translation.
00038 ##master-page:None
00039 ##master-date:None
00040 #acl -All:write Default
00041 #format gettext
00042 #language %s
00043 
00044 #
00045 # MoinMoin %s system text translation
00046 #
00047 %s""" % (lang, lang, data)
00048 
00049 
00050     pagename = "MoinI18n/%s" % lang
00051     pagedata = data.encode('utf-8')
00052 
00053     wiki = xmlrpclib.ServerProxy(master_url)
00054     token = wiki.getAuthToken(user, password)
00055     mc = xmlrpclib.MultiCall(wiki)
00056     mc.applyAuthToken(token)
00057     mc.WhoAmI() # then we see in the result if auth worked correctly!
00058     mc.putPage(pagename, pagedata)
00059     mc.deleteAuthToken(token)
00060     result = mc()
00061     print "Page: %s rc=%r" % (pagename, list(result))
00062 
00063 if __name__ == "__main__":
00064     run()
00065