diff --git a/CHANGELOG b/CHANGELOG index 21ee6c8..d1e9ecc 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,6 @@ +v 0.5.0 [0-mar-2020] + - + v 0.4.0 [10-mar-2020] - Update easymacro.py - Fix: in OSx Catalina diff --git a/README.md b/README.md index 03d869f..28f175c 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ https://gitlab.com/mauriciobaeza/zaz This extension have a cost of maintenance of 1 euro every year. BCH: `qztd3l00xle5tffdqvh2snvadkuau2ml0uqm4n875d` + BTC: `3FhiXcXmAesmQzrNEngjHFnvaJRhU1AGWV` You have others cryptos, welcome too! diff --git a/VERSION b/VERSION index 26b5dec..79a2734 100644 --- a/VERSION +++ b/VERSION @@ -1,2 +1 @@ -0.4.0 - +0.5.0 \ No newline at end of file diff --git a/conf.py b/conf.py index acd4846..bf0095a 100644 --- a/conf.py +++ b/conf.py @@ -26,7 +26,7 @@ import logging TYPE_EXTENSION = 1 # ~ https://semver.org/ -VERSION = '0.4.0' +VERSION = '0.5.0' # ~ Your great extension name, not used spaces NAME = 'ZAZPip' @@ -41,8 +41,7 @@ ID = 'net.elmau.zaz.pip' USE_LOCALES = True DOMAIN = 'base' PATH_LOCALES = 'locales' -# ~ locate pygettext.py -PATH_PYGETTEXT = '/usr/lib/python3.7/Tools/i18n/pygettext.py' +PATH_PYGETTEXT = '/usr/lib/python3.8/Tools/i18n/pygettext.py' PATH_MSGMERGE = 'msgmerge' @@ -93,17 +92,6 @@ INFO = { } -CONTEXT = { - 'calc': 'com.sun.star.sheet.SpreadsheetDocument', - 'writer': 'com.sun.star.text.TextDocument', - 'impress': 'com.sun.star.presentation.PresentationDocument', - 'draw': 'com.sun.star.drawing.DrawingDocument', - 'base': 'com.sun.star.sdb.OfficeDatabaseDocument', - 'math': 'com.sun.star.formula.FormulaProperties', - 'basic': 'com.sun.star.script.BasicIDE', -} - - # ~ Menus, only for TYPE_EXTENSION = 1 # ~ Parent can be: AddonMenu or OfficeMenuBar # ~ For icons con name: NAME_16.bmp, used only NAME @@ -260,7 +248,7 @@ elif TYPE_EXTENSION == 3: METHODS = _methods() -FILE_PY = f"""import uno +DATA_PY = f"""import uno import unohelper {SRV_IMPORT} @@ -280,177 +268,6 @@ g_ImplementationHelper = unohelper.ImplementationHelper() g_ImplementationHelper.addImplementation({NAME}, ID_EXTENSION, SERVICE) """ - -tmp = ' {}' -node = [tmp.format(k, v['display_name']) for k, v in INFO.items()] -NODE_DISPLAY_NAME = '\n'.join(node) - -tmp = ' ' -node = [tmp.format(k) for k, v in INFO.items()] -NODE_EXTENSION_DESCRIPTION = '\n'.join(node) - -NODE_ICON = '' -if ICON: - NODE_ICON = f' ' - -NODE_PUBLISHER = '' -if PUBLISHER: - tmp = ' {}' - node = [tmp.format(v['link'], k, v['text']) for k, v in PUBLISHER.items()] - NODE_PUBLISHER = '\n'.join(node) - -NODE_DEPENDENCIES_MINIMAL = '' -if DEPENDENCIES_MINIMAL: - NODE_DEPENDENCIES_MINIMAL = f"""\n - - """ - -tmp = ' ' -node = [tmp.format(DIRS['registration'], k) for k in INFO.keys()] -NODE_LICENSE = '\n'.join(node) - -NODE_UPDATE = '' -if URL_XML_UPDATE: - NODE_UPDATE = f""" - - - """ - -FILE_DESCRIPTION = f""" - - - - -{NODE_DISPLAY_NAME} - - -{NODE_EXTENSION_DESCRIPTION} - - -{NODE_ICON} - - -{NODE_PUBLISHER} - - - -{NODE_LICENSE} - - {NODE_DEPENDENCIES_MINIMAL}{NODE_UPDATE} - -""" - -NODE_MENU = """ - -{titles} - - - service:{id}?{argument} - - - _self - - - {context} - - - %origin%/{folder}/{icon} - - """ - -opt = 'fuse' -if PARENT == 'OfficeMenuBar': - opt = 'replace' - - -def _get_context(args): - if not args: - return '' - c = [] - for v in args.split(','): - c.append(CONTEXT[v]) - return ','.join(c) - - -menus = [] -toolbar = [] -tmp = ' {}' -for i, m in enumerate(MENUS): - titles = [tmp.format(k, v) for k, v in m['title'].items()] - values = { - 'id': ID, - 'index': i+101, - 'opt': opt, - 'titles': '\n'.join(titles), - 'argument': m['argument'], - 'context': _get_context(m['context']), - 'folder': DIRS['images'], - 'icon': m['icon'], - } - menus.append(NODE_MENU.format(**values)) - if m['toolbar']: - values['index'] = f't{i+1}' - toolbar.append(NODE_MENU.format(**values)) - -NODE_TOOLBAR = '' -NODE_MENUS = '' -if TYPE_EXTENSION == 1: - if PARENT == 'AddonMenu': - NODE_MENUS = '\n'.join(menus) - elif PARENT == 'OfficeMenuBar': - tmp = ' {}' - titles = '\n'.join([tmp.format(k, v) for k, v in MENU_MAIN.items()]) - SUBMENUS = '\n ' + '\n'.join(menus) + '\n ' - NODE_MENUS = f""" - - {titles} - - - _self - - {SUBMENUS} - """ - - if toolbar: - node_toolbars = '\n'.join(toolbar) - NODE_TOOLBAR = f""" - - {node_toolbars} - - """ - -FILE_ADDONS = f""" - - - -{NODE_MENUS} - -{NODE_TOOLBAR} - - -""" - - -FILE_UPDATE = '' -if URL_XML_UPDATE: - FILE_UPDATE = f""" - - - - - - - - - - - -""" - - def _functions(): a = '[in] any {}' t = ' any {}({});' @@ -567,72 +384,42 @@ FILE_ADDIN = f""" """ -NODE_SHORTCUT = """ {0} - {0} - {0}service:{2}?{3} - {0} - {0} -""" - -NODE_SHORTCUTS = '' -if TYPE_EXTENSION == 1: - node_global = [] - node_module = {} - for m in MENUS: - if not m.get('shortcut', ''): - continue - if m['context']: - for c in m['context'].split(','): - if not c in node_module: - node_module[c] = [] - node = NODE_SHORTCUT.format(' ', m['shortcut'], ID, m['argument']) - node_module[c].append(node) - continue - node = NODE_SHORTCUT.format('', m['shortcut'], ID, m['argument']) - node_global.append(node) - if node_global: - NODE_SHORTCUTS = ' \n' - NODE_SHORTCUTS += '\n'.join(node_global) - NODE_SHORTCUTS += ' ' - if node_module: - NODE_SHORTCUTS += ' \n' - for c, n in node_module.items(): - NODE_SHORTCUTS += ' \n'.format(CONTEXT[c]) - NODE_SHORTCUTS += '\n'.join(n) - NODE_SHORTCUTS += ' \n' - NODE_SHORTCUTS += ' ' - -FILE_SHORTCUTS = f""" - - -{NODE_SHORTCUTS} - - -""" - - DATA_MANIFEST = [FILES['py'], f"Office/{FILES['shortcut']}", 'Addons.xcu'] if TYPE_EXTENSION > 1: DATA_MANIFEST.append(FILES['rdb']) if TYPE_EXTENSION == 3: DATA_MANIFEST.append('CalcAddIn.xcu') +DATA_DESCRIPTION = { + 'identifier': {'value': ID}, + 'version': {'value': VERSION}, + 'display-name': {k: v['display_name'] for k, v in INFO.items()}, + 'icon': ICON_EXT, + 'publisher': PUBLISHER, + 'update': URL_XML_UPDATE, +} + +DATA_ADDONS = { + 'parent': PARENT, + 'images': DIRS['images'], + 'main': MENU_MAIN, + 'menus': MENUS, +} DATA = { - 'py': FILE_PY, + 'py': DATA_PY, 'manifest': DATA_MANIFEST, - 'description': FILE_DESCRIPTION, - 'addons': FILE_ADDONS, - 'update': FILE_UPDATE, + 'description': DATA_DESCRIPTION, + 'addons': DATA_ADDONS, + 'update': URL_OXT, 'idl': FILE_IDL, 'addin': FILE_ADDIN, - 'shortcut': FILE_SHORTCUTS, } +with open('VERSION', 'w') as f: + f.write(VERSION) + + # ~ LICENSE_ACCEPT_BY = 'user' # or admin # ~ LICENSE_SUPPRESS_ON_UPDATE = True diff --git a/files/ZAZPip_v0.4.0.oxt b/files/ZAZPip_v0.5.0.oxt similarity index 94% rename from files/ZAZPip_v0.4.0.oxt rename to files/ZAZPip_v0.5.0.oxt index 727814a..b141096 100644 Binary files a/files/ZAZPip_v0.4.0.oxt and b/files/ZAZPip_v0.5.0.oxt differ diff --git a/source/Addons.xcu b/source/Addons.xcu index f34210f..691020b 100644 --- a/source/Addons.xcu +++ b/source/Addons.xcu @@ -1,26 +1,25 @@ - - - + + + - - - Open Pip - Abrir Pip - - - service:net.elmau.zaz.pip?open - - - _self - - - - - - %origin%/images/icon - - + + + Open Pip + Abrir Pip + + + + + + service:net.elmau.zaz.pip?open + + + _self + + + %origin%/images/icon + + - - + diff --git a/source/Office/Accelerators.xcu b/source/Office/Accelerators.xcu index 50227f7..c5ac0c1 100644 --- a/source/Office/Accelerators.xcu +++ b/source/Office/Accelerators.xcu @@ -1,9 +1,5 @@ - - + + diff --git a/source/ZAZPip.py b/source/ZAZPip.py index 72aa6a8..d8dfc16 100644 --- a/source/ZAZPip.py +++ b/source/ZAZPip.py @@ -3,7 +3,6 @@ import unohelper from com.sun.star.task import XJobExecutor import easymacro as app - ID_EXTENSION = 'net.elmau.zaz.pip' SERVICE = ('com.sun.star.task.Job',) diff --git a/source/description.xml b/source/description.xml index 3a29c42..3b7128f 100644 --- a/source/description.xml +++ b/source/description.xml @@ -1,26 +1,26 @@ - + - - + + ZAZ Pip ZAZ Pip - - + + - + El Mau El Mau - - - + + + diff --git a/zaz.py b/zaz.py index 9cad0c8..17a0ea5 100644 --- a/zaz.py +++ b/zaz.py @@ -44,6 +44,15 @@ from conf import ( class LiboXML(object): + CONTEXT = { + 'calc': 'com.sun.star.sheet.SpreadsheetDocument', + 'writer': 'com.sun.star.text.TextDocument', + 'impress': 'com.sun.star.presentation.PresentationDocument', + 'draw': 'com.sun.star.drawing.DrawingDocument', + 'base': 'com.sun.star.sdb.OfficeDatabaseDocument', + 'math': 'com.sun.star.formula.FormulaProperties', + 'basic': 'com.sun.star.script.BasicIDE', + } TYPES = { 'py': 'application/vnd.sun.star.uno-component;type=Python', 'zip': 'application/binary', @@ -53,18 +62,34 @@ class LiboXML(object): 'help': 'application/vnd.sun.star.help', 'component': 'application/vnd.sun.star.uno-components', } - NAME_SPACES = { + NS_MANIFEST = { 'manifest_version': '1.2', 'manifest': 'urn:oasis:names:tc:opendocument:xmlns:manifest:1.0', 'xmlns:loext': 'urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0', } + NS_DESCRIPTION = { + 'xmlns': 'http://openoffice.org/extensions/description/2006', + 'xmlns:xlink': 'http://www.w3.org/1999/xlink', + 'xmlns:d': 'http://openoffice.org/extensions/description/2006', + } + NS_ADDONS = { + 'xmlns:xs': 'http://www.w3.org/2001/XMLSchema', + 'xmlns:oor': 'http://openoffice.org/2001/registry', + } + NS_UPDATE = { + 'xmlns': 'http://openoffice.org/extensions/update/2006', + 'xmlns:d': 'http://openoffice.org/extensions/description/2006', + 'xmlns:xlink': 'http://www.w3.org/1999/xlink', + } def __init__(self): self._manifest = None self._paths = [] + self._path_images = '' + self._toolbars = [] def _save_path(self, attr): - self._paths.append(attr['{{{}}}full-path'.format(self.NAME_SPACES['manifest'])]) + self._paths.append(attr['{{{}}}full-path'.format(self.NS_MANIFEST['manifest'])]) return def _clean(self, name, nodes): @@ -86,17 +111,17 @@ class LiboXML(object): def new_manifest(self, data): attr = { - 'manifest:version': self.NAME_SPACES['manifest_version'], - 'xmlns:manifest': self.NAME_SPACES['manifest'], - 'xmlns:loext': self.NAME_SPACES['xmlns:loext'], + 'manifest:version': self.NS_MANIFEST['manifest_version'], + 'xmlns:manifest': self.NS_MANIFEST['manifest'], + 'xmlns:loext': self.NS_MANIFEST['xmlns:loext'], } self._manifest = ET.Element('manifest:manifest', attr) return self.add_data_manifest(data) def parse_manifest(self, data): - ET.register_namespace('manifest', self.NAME_SPACES['manifest']) + ET.register_namespace('manifest', self.NS_MANIFEST['manifest']) self._manifest = ET.fromstring(data) - data = {'xmlns:loext': self.NAME_SPACES['xmlns:loext']} + data = {'xmlns:loext': self.NS_MANIFEST['xmlns:loext']} self._manifest.attrib.update(**data) self._clean('manifest', self._manifest) return @@ -116,6 +141,217 @@ class LiboXML(object): ET.SubElement(self._manifest, node_name, attr) return self._get_xml(self._manifest) + def new_description(self, data): + doc = ET.Element('description', self.NS_DESCRIPTION) + + key = 'identifier' + ET.SubElement(doc, key, data[key]) + + key = 'version' + ET.SubElement(doc, key, data[key]) + + key = 'display-name' + node = ET.SubElement(doc, key) + for k, v in data[key].items(): + sn = ET.SubElement(node, 'name', {'lang': k}) + sn.text = v + + node = ET.SubElement(doc, 'extension-description') + for k in data[key].keys(): + attr = { + 'lang': k, + 'xlink:href': f'description/desc_{k}.txt', + } + ET.SubElement(node, 'src', attr) + + key = 'icon' + node = ET.SubElement(doc, key) + attr = {'xlink:href': f"images/{data[key]}"} + ET.SubElement(node, 'default', attr) + + key = 'publisher' + node = ET.SubElement(doc, key) + for k, v in data[key].items(): + attr = { + 'xlink:href': v['link'], + 'lang': k, + } + sn = ET.SubElement(node, 'name', attr) + sn.text = v['text'] + + key = 'display-name' + node = ET.SubElement(doc, 'registration') + attr = { + 'accept-by': 'user', + 'suppress-on-update': 'true', + } + node = ET.SubElement(node, 'simple-license', attr) + for k in data[key].keys(): + attr = { + 'xlink:href': f"{DIRS['registration']}/license_{k}.txt", + 'lang': k + } + ET.SubElement(node, 'license-text', attr) + + if data['update']: + node = ET.SubElement(doc, 'update-information') + ET.SubElement(node, 'src', {'xlink:href': data['update']}) + + return self._get_xml(doc) + + def _get_context(self, args): + if not args: + return '' + context = ','.join([self.CONTEXT[v] for v in args.split(',')]) + return context + + def _add_node_value(self, node, name, value='_self'): + attr = {'oor:name': name, 'oor:type': 'xs:string'} + sn = ET.SubElement(node, 'prop', attr) + sn = ET.SubElement(sn, 'value') + sn.text = value + return + + def _add_menu(self, id_extension, node, index, menu, in_menu_bar=True): + if in_menu_bar: + attr = { + 'oor:name': index, + 'oor:op': 'replace', + } + subnode = ET.SubElement(node, 'node', attr) + else: + subnode = node + + attr = {'oor:name': 'Title', 'oor:type': 'xs:string'} + sn1 = ET.SubElement(subnode, 'prop', attr) + for k, v in menu['title'].items(): + sn2 = ET.SubElement(sn1, 'value', {'xml:lang': k}) + sn2.text = v + value = self._get_context(menu['context']) + self._add_node_value(subnode, 'Context', value) + + if 'submenu' in menu: + sn = ET.SubElement(subnode, 'node', {'oor:name': 'Submenu'}) + for i, m in enumerate(menu['submenu']): + self._add_menu(id_extension, sn, f'{index}.s{i}', m) + if m.get('toolbar', False): + self._toolbars.append(m) + return + + value = f"service:{id_extension}?{menu['argument']}" + self._add_node_value(subnode, 'URL', value) + self._add_node_value(subnode, 'Target') + value = f"%origin%/{self._path_images}/{menu['icon']}" + self._add_node_value(subnode, 'ImageIdentifier', value) + return + + def new_addons(self, id_extension, data): + in_menu_bar = data['parent'] == 'OfficeMenuBar' + self._path_images = data['images'] + attr = { + 'oor:name': 'Addons', + 'oor:package': 'org.openoffice.Office', + } + attr.update(self.NS_ADDONS) + doc = ET.Element('oor:component-data', attr) + parent = ET.SubElement(doc, 'node', {'oor:name': 'AddonUI'}) + node = ET.SubElement(parent, 'node', {'oor:name': data['parent']}) + + op = 'fuse' + if in_menu_bar: + op = 'replace' + + attr = {'oor:name': id_extension, 'oor:op': op} + node = ET.SubElement(node, 'node', attr) + + if in_menu_bar: + attr = {'oor:name': 'Title', 'oor:type': 'xs:string'} + subnode = ET.SubElement(node, 'prop', attr) + for k, v in data['main'].items(): + sn = ET.SubElement(subnode, 'value', {'xml:lang': k}) + sn.text = v + + self._add_node_value(node, 'Target') + node = ET.SubElement(node, 'node', {'oor:name': 'Submenu'}) + + for i, menu in enumerate(data['menus']): + self._add_menu(id_extension, node, f'm{i}', menu, in_menu_bar) + if menu.get('toolbar', False): + self._toolbars.append(menu) + + if self._toolbars: + attr = {'oor:name': 'OfficeToolBar'} + toolbar = ET.SubElement(parent, 'node', attr) + attr = {'oor:name': id_extension, 'oor:op': 'replace'} + toolbar = ET.SubElement(toolbar, 'node', attr) + for t, menu in enumerate(self._toolbars): + self._add_menu(id_extension, toolbar, f't{t}', menu) + + return self._get_xml(doc) + + def _add_shortcut(self, node, key, id_extension, arg): + attr = {'oor:name': key, 'oor:op': 'fuse'} + subnode = ET.SubElement(node, 'node', attr) + subnode = ET.SubElement(subnode, 'prop', {'oor:name': 'Command'}) + subnode = ET.SubElement(subnode, 'value', {'xml:lang': 'en-US'}) + subnode.text = f"service:{id_extension}?{arg}" + return + + def _get_acceleartors(self, menu): + if 'submenu' in menu: + for m in menu['submenu']: + return self._get_acceleartors(m) + + if not menu.get('shortcut', ''): + return '' + + return menu + + def new_accelerators(self, id_extension, menus): + attr = { + 'oor:name': 'Accelerators', + 'oor:package': 'org.openoffice.Office', + } + attr.update(self.NS_ADDONS) + doc = ET.Element('oor:component-data', attr) + parent = ET.SubElement(doc, 'node', {'oor:name': 'PrimaryKeys'}) + + data = [] + for m in menus: + info = self._get_acceleartors(m) + if info: + data.append(info) + + node_global = None + node_modules = None + for m in data: + if m['context']: + if node_modules is None: + node_modules = ET.SubElement( + parent, 'node', {'oor:name': 'Modules'}) + for app in m['context'].split(','): + node = ET.SubElement( + node_modules, 'node', {'oor:name': self.CONTEXT[app]}) + self._add_shortcut( + node, m['shortcut'], id_extension, m['argument']) + else: + if node_global is None: + node_global = ET.SubElement( + parent, 'node', {'oor:name': 'Global'}) + self._add_shortcut( + node_global, m['shortcut'], id_extension, m['argument']) + + return self._get_xml(doc) + + def new_update(self, extension, url_oxt): + doc = ET.Element('description', self.NS_UPDATE) + ET.SubElement(doc, 'identifier', {'value': extension['id']}) + ET.SubElement(doc, 'version', {'value': extension['version']}) + node = ET.SubElement(doc, 'update-download') + ET.SubElement(node, 'src', {'xlink:href': url_oxt}) + node = ET.SubElement(doc, 'release-notes') + return self._get_xml(doc) + def _get_xml(self, doc): xml = parseString(ET.tostring(doc, encoding='utf-8')) return xml.toprettyxml(indent=' ', encoding='utf-8').decode('utf-8') @@ -155,11 +391,7 @@ def _get_files(path, filters=''): def _compress_oxt(): log.info('Compress OXT extension...') - path = DIRS['files'] - if not _exists(path): - _mkdir(path) - - path_oxt = _join(path, FILES['oxt']) + path_oxt = _join(DIRS['files'], FILES['oxt']) z = zipfile.ZipFile(path_oxt, 'w', compression=zipfile.ZIP_DEFLATED) root_len = len(os.path.abspath(DIRS['source'])) @@ -173,10 +405,6 @@ def _compress_oxt(): z.write(fullpath, file_name, zipfile.ZIP_DEFLATED) z.close() - if DATA['update']: - path_xml = _join(path, FILES['update']) - _save(path_xml, DATA['update']) - log.info('Extension OXT created sucesfully...') return @@ -294,6 +522,10 @@ def _compile_idl(): def _update_files(): + path_files = DIRS['files'] + if not _exists(path_files): + _mkdir(path_files) + path_source = DIRS['source'] for k, v in INFO.items(): @@ -325,16 +557,21 @@ def _update_files(): data = xml.new_manifest(DATA['manifest']) _save(path, data) - path = _join(path_source, DIRS['office']) - _mkdir(path) - path = _join(path_source, DIRS['office'], FILES['shortcut']) - _save(path, DATA['shortcut']) - - path = _join(path_source, FILES['addons']) - _save(path, DATA['addons']) - path = _join(path_source, FILES['description']) - _save(path, DATA['description']) + data = xml.new_description(DATA['description']) + _save(path, data) + + if TYPE_EXTENSION == 1: + path = _join(path_source, FILES['addons']) + data = xml.new_addons(EXTENSION['id'], DATA['addons']) + _save(path, data) + + path = _join(path_source, DIRS['office']) + _mkdir(path) + path = _join(path_source, DIRS['office'], FILES['shortcut']) + data = xml.new_accelerators(EXTENSION['id'], DATA['addons']['menus']) + _save(path, data) + if TYPE_EXTENSION == 3: path = _join(path_source, FILES['addin']) @@ -342,10 +579,15 @@ def _update_files(): if USE_LOCALES: msg = "Don't forget generate DOMAIN.pot for locales" - log.info(msg) for lang in EXTENSION['languages']: path = _join(path_source, DIRS['locales'], lang, 'LC_MESSAGES') Path(path).mkdir(parents=True, exist_ok=True) + log.info(msg) + + if DATA['update']: + path_xml = _join(path_files, FILES['update']) + data = xml.new_update(EXTENSION, DATA['update']) + _save(path_xml, data) _compile_idl() return