# -*- encoding: UTF-8 -*- from __future__ import unicode_literals import sys import re import os import codecs comment = re.compile(r"[\n#]") ids = re.compile(r"\w+:\s*\*?\w+(,\s*\*?\w+)*") langu = re.compile(r"\[.+=.+\]\s*") titl = re.compile(r"\w+\s*=\s*") helptexts = [] xdl_header = """ """ xdl_footer = """ """ xdl_group = '\n' xdl_item = '\n' xcs_header = """ Contains the options data used for the test extensions. """ xcs_leaf_header = r""" The data for one leaf. """ xcs_leaf = r""" """ xcs_leaf_footer = r""" """ xcs_component_header = """ """ xcs_component = """ """ xcs_footer = """ """ xcu_header = u""" Dictionaries Szótárak """ xcu_node_header = """ org.openoffice.comp.pyuno.lightproof.oxt.%s """ xcu_node = """ %s """ xcu_node_footer = """ %%origin%%/%s.xdl org.openoffice.comp.pyuno.LightproofOptionsEventHandler.%s """ xcu_footer = """ """ indexes = {} indexes_def = {} modules = {} def create_xdl(pkg, lines, target, lang): global indexes global indexes_def global modules indexes[lang] = [] indexes_def[lang] = [] modules[lang] = [] f2 = "" state = 0 f2n = "dialog/" + lang + ".xdl" f2 = f2 + xdl_header%lang k = 0 k2 = 0 lin = 0 ok = False for i in lines: i = i.strip() if "=" in i and r"\n" in i: helptexts.append(i.split("=")[0]) for i in lines: i = i.strip().replace(r"\n", "@#@") + "\n" lin = lin + 1 if not comment.match(i): if state == 0: ok = True if ids.match(i.strip()): j = i.strip().split(":") f2 = f2 + xdl_group%(j[0].strip(), k, k2 * 10 + 5, j[0].strip()) for l in j[1].split(","): k = k + 1 k2 = k2 + 1 l = l.strip() la = l.split(" ") l3 = 0 itemlen = int(240 / len(la)) for l2 in la: if l2 != "-": checked = "false" if l2[0] == '*': checked = "true" l2 = l2[1:] indexes_def[lang] += [l2] indexes[lang] += [l2] helptext = "" if l2 in helptexts: helptext = "dlg:help-text=\"&hlp_" + l2 + "\"" f2 = f2 + xdl_item%(l2, k, 10 + itemlen * l3, k2 * 10 + 5, itemlen, l2, checked, helptext) l3 = l3 + 1 k = k + 1 k2 = k2 + 1 k = k + 1 else: ok = False if langu.match(i.strip()): if "xdl" in f2n: f2 = f2 + xdl_footer target.writestr(f2n, f2) f2 = "" i = i.strip() langname = i[1:i.find("=")] modules[lang] += [langname[:langname.find("_")], i[i.find("=")+1:-1]] f2n = "dialog/" + lang + "_" + langname + ".properties" state = state + 1 if state == 1: target.writestr("dialog/" + lang + "_" + langname + ".default", "") elif titl.match(i.strip()): hlp = i.encode("unicode-escape").decode('ascii').replace(r"\n","\n").replace(r"\t","\t").replace(r"\x","\\u00").split("@#@", 1) if len(hlp) > 1: helptexts.append(hlp[0].split("=")[0]) f2 = f2 + "hlp_" + hlp[0].split("=")[0] + "=" + hlp[1] hlp[0] = hlp[0] + "\n" f2 = f2 + hlp[0] elif not ok: print ("Syntax error in line %d: %s" %(lin, i)) if "xdl" in f2n: f2 = f2 + xdl_footer target.writestr(f2n, f2) #def c(pkg, author, language, inpdir, target, prgtarget, dlg): def c(pkg, dlgdata, target, lang): # create xdl dialog data files create_xdl(pkg, dlgdata, target, lang) s = xcs_header% ("Lightproof_" + pkg) for i in indexes: s = s + xcs_leaf_header%i + \ xcs_leaf*len(indexes[i])%tuple(indexes[i]) + \ xcs_leaf_footer s = s + xcs_component_header for i in indexes: s = s + xcs_component%(i,i) target.writestr("dialog/OptionsDialog.xcs", s + xcs_footer) s = "" for i in indexes: s = s + xcu_node_header%(pkg, pkg) + \ xcu_node*(len(modules[i])//2)%tuple(modules[i]) + \ xcu_node_footer%(i, pkg) target.writestr("dialog/OptionsDialog.xcu", (xcu_header + s + xcu_footer).encode("utf-8")) # python resource file s = """lopts = {} lopts_default = {} """ for i in indexes: s = s + "lopts['" + i + "'] = " + str(indexes[i]) + "\n" for i in indexes: s = s + "lopts_default['" + i + "'] = " + str(indexes_def[i]) + "\n" target.writestr("pythonpath/lightproof_opts_%s.py"%pkg, s)