Update zaz and easymacro, update locales esperanto
This commit is contained in:
commit
ae1d2a1720
|
@ -11,4 +11,6 @@ docs/
|
|||
virtual/
|
||||
|
||||
|
||||
- Update library easymacro.py
|
||||
*.po~
|
||||
|
||||
|
|
11
CHANGELOG
11
CHANGELOG
|
@ -1,16 +1,25 @@
|
|||
v 0.5.0 [10-nov-2019]
|
||||
---------------------
|
||||
- Update library easymacro.py
|
||||
- Update library zaz.py
|
||||
|
||||
|
||||
v 0.4.0 [27-sep-2019]
|
||||
---------------------
|
||||
- Update library easymacro.py
|
||||
- Add icon in command button
|
||||
|
||||
|
||||
v 0.3.0 [18-sep-2019]
|
||||
---------------------
|
||||
- Add support for generate barcode by code
|
||||
|
||||
|
||||
v 0.2.1 [16-sep-2019]
|
||||
|
||||
---------------------
|
||||
- Fix #1
|
||||
|
||||
|
||||
v 0.2.0 [14-sep-2019]
|
||||
---------------------
|
||||
- Add support for spanish
|
||||
|
|
28
conf.py
28
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 = 'ZAZBarCode'
|
||||
|
@ -318,6 +318,9 @@ PATHS = {
|
|||
'regmerge': '/usr/lib/libreoffice/program/regmerge',
|
||||
'soffice': ('soffice', PROGRAM, FILE_TEST),
|
||||
'install': ('unopkg', 'add', '-v', '-f', '-s'),
|
||||
'profile': '/home/mau/.config/libreoffice/4/user',
|
||||
'gettext': PATH_PYGETTEXT,
|
||||
'msgmerge': PATH_MSGMERGE,
|
||||
}
|
||||
|
||||
|
||||
|
@ -540,20 +543,6 @@ FILE_ADDONS = f"""<?xml version='1.0' encoding='UTF-8'?>
|
|||
"""
|
||||
|
||||
|
||||
NODE_ADDONS = '\n <manifest:file-entry manifest:full-path="Addons.xcu" manifest:media-type="application/vnd.sun.star.configuration-data"/>'
|
||||
if TYPE_EXTENSION > 1:
|
||||
NODE_ADDONS = f'\n <manifest:file-entry manifest:full-path="{FILES["rdb"]}" manifest:media-type="application/vnd.sun.star.uno-typelibrary;type=RDB"/>'
|
||||
if TYPE_EXTENSION == 3:
|
||||
NODE_ADDONS += '\n <manifest:file-entry manifest:full-path="CalcAddIn.xcu" manifest:media-type="application/vnd.sun.star.configuration-data"/>'
|
||||
|
||||
FILE_MANIFEST = f"""<?xml version="1.0" encoding="UTF-8"?>
|
||||
<manifest:manifest>
|
||||
<manifest:file-entry manifest:full-path="{FILES['py']}" manifest:media-type="application/vnd.sun.star.uno-component;type=Python"/>
|
||||
<manifest:file-entry manifest:full-path="Office/{FILES['shortcut']}" manifest:media-type="application/vnd.sun.star.configuration-data"/>{NODE_ADDONS}
|
||||
</manifest:manifest>
|
||||
"""
|
||||
|
||||
|
||||
FILE_UPDATE = ''
|
||||
if URL_XML_UPDATE:
|
||||
FILE_UPDATE = f"""<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
@ -738,9 +727,16 @@ FILE_SHORTCUTS = f"""<?xml version="1.0" encoding="UTF-8"?>
|
|||
"""
|
||||
|
||||
|
||||
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 = {
|
||||
'py': FILE_PY,
|
||||
'manifest': FILE_MANIFEST,
|
||||
'manifest': DATA_MANIFEST,
|
||||
'description': FILE_DESCRIPTION,
|
||||
'addons': FILE_ADDONS,
|
||||
'update': FILE_UPDATE,
|
||||
|
|
3240
easymacro.py
3240
easymacro.py
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
@ -5,10 +5,10 @@
|
|||
xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
|
||||
<identifier value="net.elmau.zaz.BarCode" />
|
||||
<version value="0.4.0" />
|
||||
<version value="0.5.0" />
|
||||
|
||||
<update-download>
|
||||
<src xlink:href="https://gitlab.com/mauriciobaeza/zaz-barcode/raw/master/files/ZAZBarCode_v0.4.0.oxt"/>
|
||||
<src xlink:href="https://gitlab.com/mauriciobaeza/zaz-barcode/raw/master/files/ZAZBarCode_v0.5.0.oxt"/>
|
||||
</update-download>
|
||||
<release-notes>
|
||||
</release-notes>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<manifest:manifest>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest:manifest manifest:version="1.2" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" xmlns:manifest="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0">
|
||||
<manifest:file-entry manifest:full-path="ZAZBarCode.py" manifest:media-type="application/vnd.sun.star.uno-component;type=Python"/>
|
||||
<manifest:file-entry manifest:full-path="Office/Accelerators.xcu" manifest:media-type="application/vnd.sun.star.configuration-data"/>
|
||||
<manifest:file-entry manifest:full-path="Addons.xcu" manifest:media-type="application/vnd.sun.star.configuration-data"/>
|
||||
|
|
|
@ -15,15 +15,7 @@ TITLE = 'ZAZ BarCode'
|
|||
QR = 'qrcode'
|
||||
|
||||
|
||||
p, *_ = app.get_info_path(__file__)
|
||||
path_locales = app.join(p, 'locales')
|
||||
try:
|
||||
lang = gettext.translation('base', path_locales, languages=[app.LANG])
|
||||
lang.install()
|
||||
_ = lang.gettext
|
||||
except Exception as e:
|
||||
from gettext import gettext as _
|
||||
app.error(e)
|
||||
_ = app.install_locales(__file__)
|
||||
|
||||
|
||||
class Controllers(object):
|
||||
|
@ -31,6 +23,10 @@ class Controllers(object):
|
|||
def __init__(self, dlg):
|
||||
self.d = dlg
|
||||
|
||||
def listbox_item_changed(self, event):
|
||||
self.d.text.set_focus()
|
||||
return
|
||||
|
||||
def button_action(self, event):
|
||||
if not self.d.listbox.value:
|
||||
self.d.listbox.set_focus()
|
||||
|
@ -54,6 +50,7 @@ class ZAZBarCode(unohelper.Base, XJob, XJobExecutor):
|
|||
self.ctx = ctx
|
||||
self._data = ''
|
||||
self._type = ''
|
||||
self._ask = False
|
||||
self.path_ext = app.get_path_extension(ID_EXTENSION)
|
||||
self.IMAGES = app.join(self.path_ext, self.IMAGES)
|
||||
|
||||
|
@ -89,15 +86,21 @@ class ZAZBarCode(unohelper.Base, XJob, XJobExecutor):
|
|||
try:
|
||||
generate(self._type, self._data, output=tmp_file)
|
||||
except Exception as e:
|
||||
app.error(e)
|
||||
return str(e)
|
||||
|
||||
if app.is_created(tmp_file.name):
|
||||
return ''
|
||||
|
||||
return _('Not generated')
|
||||
|
||||
def _get_values(self):
|
||||
self._type = ''
|
||||
dlg = self._create_dialog()
|
||||
if dlg.open():
|
||||
self._data = dlg.text.value.strip()
|
||||
self._type = dlg.listbox.value
|
||||
self._ask = True
|
||||
return True
|
||||
|
||||
return False
|
||||
|
@ -118,9 +121,11 @@ class ZAZBarCode(unohelper.Base, XJob, XJobExecutor):
|
|||
self._show_error(result)
|
||||
return
|
||||
|
||||
cell = cell.offset()
|
||||
if not self._ask:
|
||||
cell = cell.offset(0, 1)
|
||||
if app.IS_WIN:
|
||||
tf.close()
|
||||
|
||||
cell.insert_image(tf.name)
|
||||
tf.close()
|
||||
return
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<description xmlns="http://openoffice.org/extensions/description/2006" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:d="http://openoffice.org/extensions/description/2006">
|
||||
<identifier value="net.elmau.zaz.BarCode" />
|
||||
<version value="0.4.0" />
|
||||
<version value="0.5.0" />
|
||||
<display-name>
|
||||
<name lang="en">ZAZ Bar Code</name>
|
||||
<name lang="es">ZAZ Códigos de Barras</name>
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"POT-Creation-Date: 2019-09-14 14:23-0500\n"
|
||||
"POT-Creation-Date: 2019-11-10 15:06-0600\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
|
@ -15,34 +15,38 @@ msgstr ""
|
|||
"Generated-By: pygettext.py 1.5\n"
|
||||
|
||||
|
||||
#: source/ZAZBarCode.py:38
|
||||
#: source/ZAZBarCode.py:29
|
||||
msgid "Select barcode type"
|
||||
msgstr ""
|
||||
|
||||
#: source/ZAZBarCode.py:43
|
||||
#: source/ZAZBarCode.py:34
|
||||
msgid "Data field is mandatory"
|
||||
msgstr ""
|
||||
|
||||
#: source/ZAZBarCode.py:95 source/ZAZBarCode.py:117
|
||||
#: source/ZAZBarCode.py:91
|
||||
msgid "Not generated"
|
||||
msgstr ""
|
||||
|
||||
#: source/ZAZBarCode.py:109 source/ZAZBarCode.py:135
|
||||
msgid "Select data"
|
||||
msgstr ""
|
||||
|
||||
#: source/ZAZBarCode.py:149
|
||||
#: source/ZAZBarCode.py:171
|
||||
msgid ""
|
||||
"Error in: {}\n"
|
||||
"\n"
|
||||
"{}"
|
||||
msgstr ""
|
||||
|
||||
#: source/ZAZBarCode.py:167
|
||||
#: source/ZAZBarCode.py:189
|
||||
msgid "~Select barcode type"
|
||||
msgstr ""
|
||||
|
||||
#: source/ZAZBarCode.py:179
|
||||
#: source/ZAZBarCode.py:201
|
||||
msgid "~Capture data for barcode"
|
||||
msgstr ""
|
||||
|
||||
#: source/ZAZBarCode.py:212
|
||||
#: source/ZAZBarCode.py:234
|
||||
msgid "~Insert Barcode"
|
||||
msgstr ""
|
||||
|
||||
|
|
Binary file not shown.
|
@ -5,45 +5,49 @@
|
|||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: \n"
|
||||
"POT-Creation-Date: 2019-09-14 14:23-0500\n"
|
||||
"PO-Revision-Date: 2019-09-14 14:45-0500\n"
|
||||
"POT-Creation-Date: 2019-11-10 15:06-0600\n"
|
||||
"PO-Revision-Date: 2019-11-10 15:15-0600\n"
|
||||
"Last-Translator: \n"
|
||||
"Language-Team: \n"
|
||||
"Language: en\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Generated-By: pygettext.py 1.5\n"
|
||||
"X-Generator: Poedit 2.2.1\n"
|
||||
"Last-Translator: \n"
|
||||
"X-Generator: Poedit 2.2.4\n"
|
||||
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||
"Language: en\n"
|
||||
|
||||
#: source/ZAZBarCode.py:38
|
||||
#: source/ZAZBarCode.py:29
|
||||
msgid "Select barcode type"
|
||||
msgstr ""
|
||||
|
||||
#: source/ZAZBarCode.py:43
|
||||
#: source/ZAZBarCode.py:34
|
||||
msgid "Data field is mandatory"
|
||||
msgstr ""
|
||||
|
||||
#: source/ZAZBarCode.py:95 source/ZAZBarCode.py:117
|
||||
#: source/ZAZBarCode.py:91
|
||||
msgid "Not generated"
|
||||
msgstr ""
|
||||
|
||||
#: source/ZAZBarCode.py:109 source/ZAZBarCode.py:135
|
||||
msgid "Select data"
|
||||
msgstr ""
|
||||
|
||||
#: source/ZAZBarCode.py:149
|
||||
#: source/ZAZBarCode.py:171
|
||||
msgid ""
|
||||
"Error in: {}\n"
|
||||
"\n"
|
||||
"{}"
|
||||
msgstr ""
|
||||
|
||||
#: source/ZAZBarCode.py:167
|
||||
#: source/ZAZBarCode.py:189
|
||||
msgid "~Select barcode type"
|
||||
msgstr ""
|
||||
|
||||
#: source/ZAZBarCode.py:179
|
||||
#: source/ZAZBarCode.py:201
|
||||
msgid "~Capture data for barcode"
|
||||
msgstr ""
|
||||
|
||||
#: source/ZAZBarCode.py:212
|
||||
#: source/ZAZBarCode.py:234
|
||||
msgid "~Insert Barcode"
|
||||
msgstr ""
|
||||
|
|
Binary file not shown.
|
@ -5,31 +5,35 @@
|
|||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: \n"
|
||||
"POT-Creation-Date: 2019-09-14 14:23-0500\n"
|
||||
"PO-Revision-Date: 2019-09-20 19:21+0200\n"
|
||||
"POT-Creation-Date: 2019-11-10 15:06-0600\n"
|
||||
"PO-Revision-Date: 2019-11-10 15:26-0600\n"
|
||||
"Last-Translator: \n"
|
||||
"Language-Team: \n"
|
||||
"Language: eo\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Generated-By: pygettext.py 1.5\n"
|
||||
"X-Generator: Poedit 2.0.6\n"
|
||||
"Last-Translator: \n"
|
||||
"X-Generator: Poedit 2.2.4\n"
|
||||
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||
"Language: eo\n"
|
||||
|
||||
#: source/ZAZBarCode.py:38
|
||||
#: source/ZAZBarCode.py:29
|
||||
msgid "Select barcode type"
|
||||
msgstr "Elektu strikodan tipon"
|
||||
|
||||
#: source/ZAZBarCode.py:43
|
||||
#: source/ZAZBarCode.py:34
|
||||
msgid "Data field is mandatory"
|
||||
msgstr "Datumkampo estas deviga"
|
||||
|
||||
#: source/ZAZBarCode.py:95 source/ZAZBarCode.py:117
|
||||
#: source/ZAZBarCode.py:91
|
||||
msgid "Not generated"
|
||||
msgstr "Ne generita"
|
||||
|
||||
#: source/ZAZBarCode.py:109 source/ZAZBarCode.py:135
|
||||
msgid "Select data"
|
||||
msgstr "Elektu datumojn"
|
||||
|
||||
#: source/ZAZBarCode.py:149
|
||||
#: source/ZAZBarCode.py:171
|
||||
msgid ""
|
||||
"Error in: {}\n"
|
||||
"\n"
|
||||
|
@ -39,14 +43,14 @@ msgstr ""
|
|||
"\n"
|
||||
"{}"
|
||||
|
||||
#: source/ZAZBarCode.py:167
|
||||
#: source/ZAZBarCode.py:189
|
||||
msgid "~Select barcode type"
|
||||
msgstr "~Elektu strikodan tipon"
|
||||
|
||||
#: source/ZAZBarCode.py:179
|
||||
#: source/ZAZBarCode.py:201
|
||||
msgid "~Capture data for barcode"
|
||||
msgstr "~Kaptu datumojn por strikodo"
|
||||
|
||||
#: source/ZAZBarCode.py:212
|
||||
#: source/ZAZBarCode.py:234
|
||||
msgid "~Insert Barcode"
|
||||
msgstr "~Enmetu Strikodon"
|
||||
|
|
Binary file not shown.
|
@ -5,31 +5,35 @@
|
|||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: \n"
|
||||
"POT-Creation-Date: 2019-09-14 14:23-0500\n"
|
||||
"PO-Revision-Date: 2019-09-14 14:44-0500\n"
|
||||
"POT-Creation-Date: 2019-11-10 15:06-0600\n"
|
||||
"PO-Revision-Date: 2019-11-10 15:07-0600\n"
|
||||
"Last-Translator: \n"
|
||||
"Language-Team: \n"
|
||||
"Language: es\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Generated-By: pygettext.py 1.5\n"
|
||||
"X-Generator: Poedit 2.2.1\n"
|
||||
"Last-Translator: \n"
|
||||
"X-Generator: Poedit 2.2.4\n"
|
||||
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||
"Language: es\n"
|
||||
|
||||
#: source/ZAZBarCode.py:38
|
||||
#: source/ZAZBarCode.py:29
|
||||
msgid "Select barcode type"
|
||||
msgstr "Seleccione el tipo de código de barras"
|
||||
|
||||
#: source/ZAZBarCode.py:43
|
||||
#: source/ZAZBarCode.py:34
|
||||
msgid "Data field is mandatory"
|
||||
msgstr "Los datos son obligatorios"
|
||||
|
||||
#: source/ZAZBarCode.py:95 source/ZAZBarCode.py:117
|
||||
#: source/ZAZBarCode.py:91
|
||||
msgid "Not generated"
|
||||
msgstr "No generado"
|
||||
|
||||
#: source/ZAZBarCode.py:109 source/ZAZBarCode.py:135
|
||||
msgid "Select data"
|
||||
msgstr "Seleccione los datos"
|
||||
|
||||
#: source/ZAZBarCode.py:149
|
||||
#: source/ZAZBarCode.py:171
|
||||
msgid ""
|
||||
"Error in: {}\n"
|
||||
"\n"
|
||||
|
@ -39,14 +43,14 @@ msgstr ""
|
|||
"\n"
|
||||
"{}"
|
||||
|
||||
#: source/ZAZBarCode.py:167
|
||||
#: source/ZAZBarCode.py:189
|
||||
msgid "~Select barcode type"
|
||||
msgstr "~Tipo de código de barras"
|
||||
|
||||
#: source/ZAZBarCode.py:179
|
||||
#: source/ZAZBarCode.py:201
|
||||
msgid "~Capture data for barcode"
|
||||
msgstr "~Datos del código de barras"
|
||||
|
||||
#: source/ZAZBarCode.py:212
|
||||
#: source/ZAZBarCode.py:234
|
||||
msgid "~Insert Barcode"
|
||||
msgstr "~Insertar Código"
|
||||
|
|
File diff suppressed because it is too large
Load Diff
245
zaz.py
245
zaz.py
|
@ -19,15 +19,21 @@
|
|||
|
||||
import argparse
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import zipfile
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
from shutil import copyfile
|
||||
from subprocess import call
|
||||
import zipfile
|
||||
from xml.etree import ElementTree as ET
|
||||
from xml.dom.minidom import parseString
|
||||
|
||||
|
||||
from conf import (
|
||||
DATA,
|
||||
DIRS,
|
||||
DOMAIN,
|
||||
EXTENSION,
|
||||
FILES,
|
||||
INFO,
|
||||
|
@ -37,6 +43,84 @@ from conf import (
|
|||
log)
|
||||
|
||||
|
||||
class LiboXML(object):
|
||||
TYPES = {
|
||||
'py': 'application/vnd.sun.star.uno-component;type=Python',
|
||||
'zip': 'application/binary',
|
||||
'xcu': 'application/vnd.sun.star.configuration-data',
|
||||
'rdb': 'application/vnd.sun.star.uno-typelibrary;type=RDB',
|
||||
'xcs': 'application/vnd.sun.star.configuration-schema',
|
||||
'help': 'application/vnd.sun.star.help',
|
||||
'component': 'application/vnd.sun.star.uno-components',
|
||||
}
|
||||
NAME_SPACES = {
|
||||
'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',
|
||||
}
|
||||
|
||||
def __init__(self):
|
||||
self._manifest = None
|
||||
self._paths = []
|
||||
|
||||
def _save_path(self, attr):
|
||||
self._paths.append(attr['{{{}}}full-path'.format(self.NAME_SPACES['manifest'])])
|
||||
return
|
||||
|
||||
def _clean(self, name, nodes):
|
||||
has_words = re.compile('\\w')
|
||||
|
||||
if not re.search(has_words, str(nodes.tail)):
|
||||
nodes.tail = ''
|
||||
if not re.search(has_words, str(nodes.text)):
|
||||
nodes.text = ''
|
||||
|
||||
for node in nodes:
|
||||
if name == 'manifest':
|
||||
self._save_path(node.attrib)
|
||||
if not re.search(has_words, str(node.tail)):
|
||||
node.tail = ''
|
||||
if not re.search(has_words, str(node.text)):
|
||||
node.text = ''
|
||||
return
|
||||
|
||||
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'],
|
||||
}
|
||||
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'])
|
||||
self._manifest = ET.fromstring(data)
|
||||
data = {'xmlns:loext': self.NAME_SPACES['xmlns:loext']}
|
||||
self._manifest.attrib.update(**data)
|
||||
self._clean('manifest', self._manifest)
|
||||
return
|
||||
|
||||
def add_data_manifest(self, data):
|
||||
node_name = 'manifest:file-entry'
|
||||
attr = {
|
||||
'manifest:full-path': '',
|
||||
'manifest:media-type': '',
|
||||
}
|
||||
for path in data:
|
||||
if path in self._paths:
|
||||
continue
|
||||
ext = path.split('.')[-1]
|
||||
attr['manifest:full-path'] = path
|
||||
attr['manifest:media-type'] = self.TYPES.get(ext, '')
|
||||
ET.SubElement(self._manifest, node_name, attr)
|
||||
return self._get_xml(self._manifest)
|
||||
|
||||
def _get_xml(self, doc):
|
||||
xml = parseString(ET.tostring(doc, encoding='utf-8'))
|
||||
return xml.toprettyxml(indent=' ', encoding='utf-8').decode('utf-8')
|
||||
|
||||
|
||||
def _exists(path):
|
||||
return os.path.exists(path)
|
||||
|
||||
|
@ -55,6 +139,19 @@ def _save(path, data):
|
|||
return
|
||||
|
||||
|
||||
def _get_files(path, filters=''):
|
||||
paths = []
|
||||
if filters in ('*', '*.*'):
|
||||
filters = ''
|
||||
for folder, _, files in os.walk(path):
|
||||
if filters:
|
||||
pattern = re.compile(r'\.(?:{})$'.format(filters), re.IGNORECASE)
|
||||
paths += [_join(folder, f) for f in files if pattern.search(f)]
|
||||
else:
|
||||
paths += files
|
||||
return paths
|
||||
|
||||
|
||||
def _compress_oxt():
|
||||
log.info('Compress OXT extension...')
|
||||
|
||||
|
@ -222,8 +319,11 @@ def _update_files():
|
|||
target = _join(path_source, 'pythonpath', source)
|
||||
copyfile(source, target)
|
||||
|
||||
xml = LiboXML()
|
||||
|
||||
path = _join(path_source, DIRS['meta'], FILES['manifest'])
|
||||
_save(path, DATA['manifest'])
|
||||
data = xml.new_manifest(DATA['manifest'])
|
||||
_save(path, data)
|
||||
|
||||
path = _join(path_source, DIRS['office'])
|
||||
_mkdir(path)
|
||||
|
@ -265,7 +365,138 @@ def _new():
|
|||
return
|
||||
|
||||
|
||||
def _get_info_path(path):
|
||||
path, filename = os.path.split(path)
|
||||
name, extension = os.path.splitext(filename)
|
||||
return (path, filename, name, extension)
|
||||
|
||||
|
||||
def _zip_embed(source, files):
|
||||
PATH = 'Scripts/python/'
|
||||
EASYMACRO = 'easymacro.'
|
||||
|
||||
p, f, name, e = _get_info_path(source)
|
||||
now = datetime.now().strftime('_%Y%m%d_%H%M%S')
|
||||
path_source = _join(p, name + now + e)
|
||||
copyfile(source, path_source)
|
||||
target = source
|
||||
|
||||
with zipfile.PyZipFile(EASYMACRO + 'zip', mode='w') as zf:
|
||||
zf.writepy(EASYMACRO + 'py')
|
||||
|
||||
xml = LiboXML()
|
||||
|
||||
path_easymacro = PATH + EASYMACRO + 'zip'
|
||||
names = [f[1] for f in files] + [path_easymacro]
|
||||
nodes = []
|
||||
with zipfile.ZipFile(target, 'w', compression=zipfile.ZIP_DEFLATED) as zt:
|
||||
with zipfile.ZipFile(path_source, compression=zipfile.ZIP_DEFLATED) as zs:
|
||||
for name in zs.namelist():
|
||||
if FILES['manifest'] in name:
|
||||
path_manifest = name
|
||||
xml_manifest = zs.open(name).read()
|
||||
elif name in names:
|
||||
continue
|
||||
else:
|
||||
zt.writestr(name, zs.open(name).read())
|
||||
|
||||
data = []
|
||||
for path, name in files:
|
||||
data.append(name)
|
||||
zt.write(path, name)
|
||||
|
||||
zt.write(EASYMACRO + 'zip', path_easymacro)
|
||||
data.append(path_easymacro)
|
||||
|
||||
xml.parse_manifest(xml_manifest)
|
||||
xml_manifest = xml.add_data_manifest(data)
|
||||
zt.writestr(path_manifest, xml_manifest)
|
||||
|
||||
os.unlink(EASYMACRO + 'zip')
|
||||
return
|
||||
|
||||
|
||||
def _embed(args):
|
||||
PATH = 'Scripts/python'
|
||||
PYTHONPATH = 'pythonpath'
|
||||
|
||||
doc = args.document
|
||||
if not doc:
|
||||
msg = '-d/--document Path file to embed is mandatory'
|
||||
log.error(msg)
|
||||
return
|
||||
if not _exists(doc):
|
||||
msg = 'Path file not exists'
|
||||
log.error(msg)
|
||||
return
|
||||
|
||||
files = []
|
||||
if args.files:
|
||||
files = args.files.split(',')
|
||||
source = _join(PATHS['profile'], PATH)
|
||||
content = os.listdir(source)
|
||||
if PYTHONPATH in content:
|
||||
content.remove(PYTHONPATH)
|
||||
|
||||
if files:
|
||||
files = [(_join(source, f), _join(PATH, f)) for f in files if f in content]
|
||||
else:
|
||||
files = [(_join(source, f), _join(PATH, f)) for f in content]
|
||||
|
||||
_zip_embed(doc, files)
|
||||
|
||||
log.info('Embedded macros successfully...')
|
||||
return
|
||||
|
||||
|
||||
def _locales(args):
|
||||
EASYMACRO = 'easymacro.py'
|
||||
|
||||
if args.files:
|
||||
files = args.files.split(',')
|
||||
else:
|
||||
files = _get_files(DIRS['source'], 'py')
|
||||
paths = ' '.join([f for f in files if not EASYMACRO in f])
|
||||
path_pot = _join(DIRS['source'], DIRS['locales'], '{}.pot'.format(DOMAIN))
|
||||
call([PATHS['gettext'], '-o', path_pot, paths])
|
||||
log.info('POT generate successfully...')
|
||||
return
|
||||
|
||||
|
||||
def _update():
|
||||
path_locales = _join(DIRS['source'], DIRS['locales'])
|
||||
path_pot = _join(DIRS['source'], DIRS['locales'], '{}.pot'.format(DOMAIN))
|
||||
if not _exists(path_pot):
|
||||
log.error('Not exists file POT...')
|
||||
return
|
||||
|
||||
files = _get_files(path_locales, 'po')
|
||||
if not files:
|
||||
log.error('First, generate files PO...')
|
||||
return
|
||||
|
||||
for f in files:
|
||||
call([PATHS['msgmerge'], '-U', f, path_pot])
|
||||
log.info('\tUpdate: {}'.format(f))
|
||||
|
||||
log.info('Locales update successfully...')
|
||||
return
|
||||
|
||||
|
||||
|
||||
def main(args):
|
||||
if args.update:
|
||||
_update()
|
||||
return
|
||||
|
||||
if args.locales:
|
||||
_locales(args)
|
||||
return
|
||||
|
||||
if args.embed:
|
||||
_embed(args)
|
||||
return
|
||||
|
||||
if args.new:
|
||||
_new()
|
||||
return
|
||||
|
@ -279,7 +510,7 @@ def main(args):
|
|||
if args.install:
|
||||
_install_and_test()
|
||||
|
||||
log.info('Extension make sucesfully...')
|
||||
log.info('Extension make successfully...')
|
||||
return
|
||||
|
||||
|
||||
|
@ -290,6 +521,14 @@ def _process_command_line_arguments():
|
|||
default=False, required=False)
|
||||
parser.add_argument('-n', '--new', dest='new', action='store_true',
|
||||
default=False, required=False)
|
||||
parser.add_argument('-e', '--embed', dest='embed', action='store_true',
|
||||
default=False, required=False)
|
||||
parser.add_argument('-d', '--document', dest='document', default='')
|
||||
parser.add_argument('-f', '--files', dest='files', default='')
|
||||
parser.add_argument('-l', '--locales', dest='locales', action='store_true',
|
||||
default=False, required=False)
|
||||
parser.add_argument('-u', '--update', dest='update', action='store_true',
|
||||
default=False, required=False)
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue