Merge branch 'develop'

Fix #1
This commit is contained in:
Mauricio Baeza 2019-09-16 19:44:48 -05:00
commit 032a9cf67c
15 changed files with 218 additions and 62 deletions

View File

@ -1,3 +1,6 @@
v 0.2.1 [16-sep-2019]
- Fix #1
v 0.2.0 [14-sep-2019] v 0.2.0 [14-sep-2019]
--------------------- ---------------------
- Add support for spanish - Add support for spanish

View File

@ -1 +1,2 @@
0.2.0 0.2.1

89
conf.py
View File

@ -26,7 +26,7 @@ import logging
TYPE_EXTENSION = 1 TYPE_EXTENSION = 1
# ~ https://semver.org/ # ~ https://semver.org/
VERSION = '0.2.0' VERSION = '0.2.1'
# ~ Your great extension name, not used spaces # ~ Your great extension name, not used spaces
NAME = 'ZAZBarCode' NAME = 'ZAZBarCode'
@ -34,9 +34,19 @@ NAME = 'ZAZBarCode'
# ~ Should be unique, used URL inverse # ~ Should be unique, used URL inverse
ID = 'net.elmau.zaz.BarCode' ID = 'net.elmau.zaz.BarCode'
# ~ If you extension will be multilanguage set True # ~ If you extension will be multilanguage set: True
USE_LOCALES = False # ~ This feature used gettext, set pythonpath and easymacro in True
# ~ Yu can used PoEdit for edit PO files and generate MO files.
# ~ https://poedit.net/
USE_LOCALES = True
DOMAIN = 'base'
PATH_LOCALES = 'locales'
# ~ locate pygettext.py
PATH_PYGETTEXT = '/usr/lib/python3.7/Tools/i18n/pygettext.py'
PATH_MSGMERGE = 'msgmerge'
# ~ Show in extension manager
PUBLISHER = { PUBLISHER = {
'en': {'text': 'El Mau', 'link': 'https://gitlab.com/mauriciobaeza'}, 'en': {'text': 'El Mau', 'link': 'https://gitlab.com/mauriciobaeza'},
'es': {'text': 'El Mau', 'link': 'https://gitlab.com/mauriciobaeza'}, 'es': {'text': 'El Mau', 'link': 'https://gitlab.com/mauriciobaeza'},
@ -97,8 +107,14 @@ CONTEXT = {
# ~ Menus, only for TYPE_EXTENSION = 1 # ~ Menus, only for TYPE_EXTENSION = 1
# ~ Parent can be: AddonMenu or OfficeMenuBar # ~ Parent can be: AddonMenu or OfficeMenuBar
# ~ For icons con name: NAME_16.bmp, used only NAME # ~ For icons con name: NAME_16.bmp, used only NAME
# ~ PARENT = 'AddonMenu' # ~ PARENT = ''
# ~ MENU_MAIN = '' # ~ MENU_MAIN = {}
# ~ Shortcut: Key + "Modifier Keys"
# ~ Important: Not used any shortcuts used for LibreOffice
# ~ SHIFT is mapped to Shift on all platforms.
# ~ MOD1 is mapped to Ctrl on Windows/Linux, while it is mapped to Cmd on Mac.
# ~ MOD2 is mapped to Alt on all platforms.
# ~ For example: Shift+Ctrl+Alt+T -> T_SHIFT_MOD1_MOD2
PARENT = 'OfficeMenuBar' PARENT = 'OfficeMenuBar'
MENU_MAIN = { MENU_MAIN = {
'en': 'ZAZ BarCode', 'en': 'ZAZ BarCode',
@ -111,6 +127,7 @@ MENUS = (
'context': 'calc,writer,impress,draw', 'context': 'calc,writer,impress,draw',
'icon': 'barcode', 'icon': 'barcode',
'toolbar': False, 'toolbar': False,
'shortcut': 'I_SHIFT_MOD1_MOD2',
}, },
{ {
'title': {'en': 'Insert CODE39', 'es': 'Insertar CODE39'}, 'title': {'en': 'Insert CODE39', 'es': 'Insertar CODE39'},
@ -247,11 +264,12 @@ EXTENSION = {
'name': NAME, 'name': NAME,
'id': ID, 'id': ID,
'icon': (ICON, ICON_EXT), 'icon': (ICON, ICON_EXT),
'languages': tuple(INFO.keys())
} }
# ~ If used more libraries set python path in True and copy inside # ~ If used more libraries set python path in True and copy inside
# ~ If used easymacro pythonpath always is True # ~ If used easymacro pythonpath always is True, recommended
DIRS = { DIRS = {
'meta': 'META-INF', 'meta': 'META-INF',
'source': 'source', 'source': 'source',
@ -259,8 +277,9 @@ DIRS = {
'images': 'images', 'images': 'images',
'registration': 'registration', 'registration': 'registration',
'files': 'files', 'files': 'files',
'pythonpath': False, 'office': 'Office',
'locales': 'locales', 'locales': PATH_LOCALES,
'pythonpath': True,
} }
@ -276,6 +295,7 @@ FILES = {
'rdb': f'X{NAME}.rdb', 'rdb': f'X{NAME}.rdb',
'update': f'{NAME.lower()}.update.xml', 'update': f'{NAME.lower()}.update.xml',
'addin': 'CalcAddIn.xcu', 'addin': 'CalcAddIn.xcu',
'shortcut': 'Accelerators.xcu',
'easymacro': True, 'easymacro': True,
} }
@ -528,7 +548,8 @@ if TYPE_EXTENSION == 3:
FILE_MANIFEST = f"""<?xml version="1.0" encoding="UTF-8"?> FILE_MANIFEST = f"""<?xml version="1.0" encoding="UTF-8"?>
<manifest:manifest> <manifest:manifest>
<manifest:file-entry manifest:full-path="{FILES['py']}" manifest:media-type="application/vnd.sun.star.uno-component;type=Python"/>{NODE_ADDONS} <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> </manifest:manifest>
""" """
@ -669,6 +690,55 @@ FILE_ADDIN = f"""<?xml version="1.0" encoding="UTF-8"?>
</oor:component-data>""" </oor:component-data>"""
NODE_SHORTCUT = """ {0}<node oor:name="{1}" oor:op="fuse">
{0}<prop oor:name="Command">
{0}<value xml:lang="en-US">service:{2}?{3}</value>
{0}</prop>
{0}</node>
"""
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 = ' <node oor:name="Global">\n'
NODE_SHORTCUTS += '\n'.join(node_global)
NODE_SHORTCUTS += ' </node>'
if node_module:
NODE_SHORTCUTS += ' <node oor:name="Modules">\n'
for c, n in node_module.items():
NODE_SHORTCUTS += ' <node oor:name="{}">\n'.format(CONTEXT[c])
NODE_SHORTCUTS += '\n'.join(n)
NODE_SHORTCUTS += ' </node>\n'
NODE_SHORTCUTS += ' </node>'
FILE_SHORTCUTS = f"""<?xml version="1.0" encoding="UTF-8"?>
<oor:component-data
xmlns:oor="http://openoffice.org/2001/registry"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
oor:name="Accelerators"
oor:package="org.openoffice.Office">
<node oor:name="PrimaryKeys">
{NODE_SHORTCUTS}
</node>
</oor:component-data>
"""
DATA = { DATA = {
'py': FILE_PY, 'py': FILE_PY,
'manifest': FILE_MANIFEST, 'manifest': FILE_MANIFEST,
@ -677,6 +747,7 @@ DATA = {
'update': FILE_UPDATE, 'update': FILE_UPDATE,
'idl': FILE_IDL, 'idl': FILE_IDL,
'addin': FILE_ADDIN, 'addin': FILE_ADDIN,
'shortcut': FILE_SHORTCUTS,
} }

View File

@ -68,12 +68,9 @@ MSG_LANG = {
FILE_NAME_DEBUG = 'zaz-debug.log' FILE_NAME_DEBUG = 'zaz-debug.log'
LOG_FORMAT = '%(asctime)s - %(levelname)s - %(message)s' LOG_FORMAT = '%(asctime)s - %(levelname)s - %(message)s'
LOG_DATE = '%d/%m/%Y %H:%M:%S' LOG_DATE = '%d/%m/%Y %H:%M:%S'
LEVEL_ERROR = logging.getLevelName(logging.ERROR) logging.addLevelName(logging.ERROR, '\033[1;41mERROR\033[1;0m')
LEVEL_DEBUG = logging.getLevelName(logging.DEBUG) logging.addLevelName(logging.DEBUG, '\x1b[33mDEBUG\033[1;0m')
LEVEL_INFO = logging.getLevelName(logging.INFO) logging.addLevelName(logging.INFO, '\x1b[32mINFO\033[1;0m')
logging.addLevelName(logging.ERROR, f'\033[1;41m{LEVEL_ERROR}\033[1;0m')
logging.addLevelName(logging.DEBUG, f'\x1b[33m{LEVEL_DEBUG}\033[1;0m')
logging.addLevelName(logging.INFO, f'\x1b[32m{LEVEL_INFO}\033[1;0m')
logging.basicConfig(level=logging.DEBUG, format=LOG_FORMAT, datefmt=LOG_DATE) logging.basicConfig(level=logging.DEBUG, format=LOG_FORMAT, datefmt=LOG_DATE)
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -176,10 +173,12 @@ def debug(info):
# ~ doc = app.newDoc(WRITER) # ~ doc = app.newDoc(WRITER)
# ~ out = OutputDoc(doc) # ~ out = OutputDoc(doc)
# ~ sys.stdout = out # ~ sys.stdout = out
pprint(info) # ~ pprint(info)
doc = LogWin(new_doc('writer').obj)
doc.write(info)
return return
log.debug(info) log.debug(str(info))
return return
@ -203,6 +202,11 @@ def run_in_thread(fn):
return run return run
def sleep(sec):
time.sleep(sec)
return
def _(msg): def _(msg):
L = LANGUAGE.split('-')[0] L = LANGUAGE.split('-')[0]
if L == 'en': if L == 'en':
@ -247,7 +251,10 @@ def get_dispatch():
def get_temp_file(): def get_temp_file():
return tempfile.NamedTemporaryFile() delete = True
if IS_WIN:
delete = False
return tempfile.NamedTemporaryFile(delete=delete)
def _path_url(path): def _path_url(path):

Binary file not shown.

BIN
files/ZAZBarCode_v0.2.1.oxt Normal file

Binary file not shown.

View File

@ -5,10 +5,10 @@
xmlns:xlink="http://www.w3.org/1999/xlink"> xmlns:xlink="http://www.w3.org/1999/xlink">
<identifier value="net.elmau.zaz.BarCode" /> <identifier value="net.elmau.zaz.BarCode" />
<version value="0.2.0" /> <version value="0.2.1" />
<update-download> <update-download>
<src xlink:href="https://gitlab.com/mauriciobaeza/zaz-barcode/raw/master/files/ZAZBarCode_v0.2.0.oxt"/> <src xlink:href="https://gitlab.com/mauriciobaeza/zaz-barcode/raw/master/files/ZAZBarCode_v0.2.1.oxt"/>
</update-download> </update-download>
<release-notes> <release-notes>
</release-notes> </release-notes>

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<manifest:manifest> <manifest:manifest>
<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="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"/> <manifest:file-entry manifest:full-path="Addons.xcu" manifest:media-type="application/vnd.sun.star.configuration-data"/>
</manifest:manifest> </manifest:manifest>

View File

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<oor:component-data
xmlns:oor="http://openoffice.org/2001/registry"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
oor:name="Accelerators"
oor:package="org.openoffice.Office">
<node oor:name="PrimaryKeys">
<node oor:name="Modules">
<node oor:name="com.sun.star.sheet.SpreadsheetDocument">
<node oor:name="I_SHIFT_MOD1_MOD2" oor:op="fuse">
<prop oor:name="Command">
<value xml:lang="en-US">service:net.elmau.zaz.BarCode?ask</value>
</prop>
</node>
</node>
<node oor:name="com.sun.star.text.TextDocument">
<node oor:name="I_SHIFT_MOD1_MOD2" oor:op="fuse">
<prop oor:name="Command">
<value xml:lang="en-US">service:net.elmau.zaz.BarCode?ask</value>
</prop>
</node>
</node>
<node oor:name="com.sun.star.presentation.PresentationDocument">
<node oor:name="I_SHIFT_MOD1_MOD2" oor:op="fuse">
<prop oor:name="Command">
<value xml:lang="en-US">service:net.elmau.zaz.BarCode?ask</value>
</prop>
</node>
</node>
<node oor:name="com.sun.star.drawing.DrawingDocument">
<node oor:name="I_SHIFT_MOD1_MOD2" oor:op="fuse">
<prop oor:name="Command">
<value xml:lang="en-US">service:net.elmau.zaz.BarCode?ask</value>
</prop>
</node>
</node>
</node>
</node>
</oor:component-data>

View File

@ -27,7 +27,6 @@ except Exception as e:
class Controllers(object): class Controllers(object):
@app.catch_exception
def __init__(self, dlg): def __init__(self, dlg):
self.d = dlg self.d = dlg
@ -54,7 +53,6 @@ class ZAZBarCode(unohelper.Base, XJobExecutor):
self._data = '' self._data = ''
self._type = '' self._type = ''
@app.catch_exception
def trigger(self, args): def trigger(self, args):
self._type = args self._type = args
if args == 'ask' and not self._get_values(): if args == 'ask' and not self._get_values():
@ -103,6 +101,8 @@ class ZAZBarCode(unohelper.Base, XJobExecutor):
return return
cell = cell.offset() cell = cell.offset()
if app.IS_WIN:
tf.close()
cell.insert_image(tf.name) cell.insert_image(tf.name)
tf.close() tf.close()
return return
@ -124,6 +124,8 @@ class ZAZBarCode(unohelper.Base, XJobExecutor):
self._show_error(result) self._show_error(result)
return return
if app.IS_WIN:
tf.close()
doc.insert_image(tf.name) doc.insert_image(tf.name)
tf.close() tf.close()
return return
@ -136,6 +138,8 @@ class ZAZBarCode(unohelper.Base, XJobExecutor):
self._show_error(result) self._show_error(result)
return return
if app.IS_WIN:
tf.close()
doc.insert_image(tf.name) doc.insert_image(tf.name)
tf.close() tf.close()
return return

View File

@ -1,7 +1,7 @@
<?xml version='1.0' encoding='UTF-8'?> <?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"> <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" /> <identifier value="net.elmau.zaz.BarCode" />
<version value="0.2.0" /> <version value="0.2.1" />
<display-name> <display-name>
<name lang="en">ZAZ Bar Code</name> <name lang="en">ZAZ Bar Code</name>
<name lang="es">ZAZ Códigos de Barras</name> <name lang="es">ZAZ Códigos de Barras</name>

View File

@ -68,12 +68,9 @@ MSG_LANG = {
FILE_NAME_DEBUG = 'zaz-debug.log' FILE_NAME_DEBUG = 'zaz-debug.log'
LOG_FORMAT = '%(asctime)s - %(levelname)s - %(message)s' LOG_FORMAT = '%(asctime)s - %(levelname)s - %(message)s'
LOG_DATE = '%d/%m/%Y %H:%M:%S' LOG_DATE = '%d/%m/%Y %H:%M:%S'
LEVEL_ERROR = logging.getLevelName(logging.ERROR) logging.addLevelName(logging.ERROR, '\033[1;41mERROR\033[1;0m')
LEVEL_DEBUG = logging.getLevelName(logging.DEBUG) logging.addLevelName(logging.DEBUG, '\x1b[33mDEBUG\033[1;0m')
LEVEL_INFO = logging.getLevelName(logging.INFO) logging.addLevelName(logging.INFO, '\x1b[32mINFO\033[1;0m')
logging.addLevelName(logging.ERROR, f'\033[1;41m{LEVEL_ERROR}\033[1;0m')
logging.addLevelName(logging.DEBUG, f'\x1b[33m{LEVEL_DEBUG}\033[1;0m')
logging.addLevelName(logging.INFO, f'\x1b[32m{LEVEL_INFO}\033[1;0m')
logging.basicConfig(level=logging.DEBUG, format=LOG_FORMAT, datefmt=LOG_DATE) logging.basicConfig(level=logging.DEBUG, format=LOG_FORMAT, datefmt=LOG_DATE)
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -176,10 +173,12 @@ def debug(info):
# ~ doc = app.newDoc(WRITER) # ~ doc = app.newDoc(WRITER)
# ~ out = OutputDoc(doc) # ~ out = OutputDoc(doc)
# ~ sys.stdout = out # ~ sys.stdout = out
pprint(info) # ~ pprint(info)
doc = LogWin(new_doc('writer').obj)
doc.write(info)
return return
log.debug(info) log.debug(str(info))
return return
@ -203,6 +202,11 @@ def run_in_thread(fn):
return run return run
def sleep(sec):
time.sleep(sec)
return
def _(msg): def _(msg):
L = LANGUAGE.split('-')[0] L = LANGUAGE.split('-')[0]
if L == 'en': if L == 'en':
@ -247,7 +251,10 @@ def get_dispatch():
def get_temp_file(): def get_temp_file():
return tempfile.NamedTemporaryFile() delete = True
if IS_WIN:
delete = False
return tempfile.NamedTemporaryFile(delete=delete)
def _path_url(path): def _path_url(path):

View File

@ -1,8 +1,12 @@
import struct
from bisect import bisect_left
from qrcode import constants, exceptions, util from qrcode import constants, exceptions, util
from qrcode.image.base import BaseImage from qrcode.image.base import BaseImage
import six
from bisect import bisect_left def int2byte(value):
return struct.Struct('>B').pack(value)
def make(data=None, **kwargs): def make(data=None, **kwargs):
@ -236,7 +240,7 @@ class QRCode(object):
self.make() self.make()
modcount = self.modules_count modcount = self.modules_count
codes = [six.int2byte(code).decode('cp437') codes = [int2byte(code).decode('cp437')
for code in (255, 223, 220, 219)] for code in (255, 223, 220, 219)]
if tty: if tty:
invert = True invert = True
@ -377,7 +381,7 @@ class QRCode(object):
data_len = len(data) data_len = len(data)
for col in six.moves.xrange(self.modules_count - 1, 0, -2): for col in range(self.modules_count - 1, 0, -2):
if col <= 6: if col <= 6:
col -= 1 col -= 1

View File

@ -1,8 +1,8 @@
import re import re
import math import math
import six # ~ import six
from six.moves import xrange # ~ from six.moves import xrange
from qrcode import base, exceptions, LUT from qrcode import base, exceptions, LUT
@ -32,8 +32,10 @@ MODE_SIZE_LARGE = {
MODE_KANJI: 12, MODE_KANJI: 12,
} }
ALPHA_NUM = six.b('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:')
RE_ALPHA_NUM = re.compile(six.b('^[') + re.escape(ALPHA_NUM) + six.b(r']*\Z')) ALPHA_NUM = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:'.encode("latin-1")
RE_ALPHA_NUM = re.compile('^['.encode("latin-1") + re.escape(ALPHA_NUM) + r']*\Z'.encode("latin-1"))
# The number of bits for numeric delimited data lengths. # The number of bits for numeric delimited data lengths.
NUMBER_LENGTH = {3: 10, 2: 7, 1: 4} NUMBER_LENGTH = {3: 10, 2: 7, 1: 4}
@ -96,8 +98,8 @@ PAD1 = 0x11
_data_count = lambda block: block.data_count _data_count = lambda block: block.data_count
BIT_LIMIT_TABLE = [ BIT_LIMIT_TABLE = [
[0] + [8*sum(map(_data_count, base.rs_blocks(version, error_correction))) [0] + [8*sum(map(_data_count, base.rs_blocks(version, error_correction)))
for version in xrange(1, 41)] for version in range(1, 41)]
for error_correction in xrange(4) for error_correction in range(4)
] ]
@ -192,7 +194,7 @@ def lost_point(modules):
def _lost_point_level1(modules, modules_count): def _lost_point_level1(modules, modules_count):
lost_point = 0 lost_point = 0
modules_range = xrange(modules_count) modules_range = range(modules_count)
container = [0] * (modules_count + 1) container = [0] * (modules_count + 1)
for row in modules_range: for row in modules_range:
@ -225,7 +227,7 @@ def _lost_point_level1(modules, modules_count):
container[length] += 1 container[length] += 1
lost_point += sum(container[each_length] * (each_length - 2) lost_point += sum(container[each_length] * (each_length - 2)
for each_length in xrange(5, modules_count + 1)) for each_length in range(5, modules_count + 1))
return lost_point return lost_point
@ -233,7 +235,7 @@ def _lost_point_level1(modules, modules_count):
def _lost_point_level2(modules, modules_count): def _lost_point_level2(modules, modules_count):
lost_point = 0 lost_point = 0
modules_range = xrange(modules_count - 1) modules_range = range(modules_count - 1)
for row in modules_range: for row in modules_range:
this_row = modules[row] this_row = modules[row]
next_row = modules[row + 1] next_row = modules[row + 1]
@ -262,8 +264,8 @@ def _lost_point_level3(modules, modules_count):
# row/column, preceded or followed by light area 4 modules wide. From ISOIEC. # row/column, preceded or followed by light area 4 modules wide. From ISOIEC.
# pattern1: 10111010000 # pattern1: 10111010000
# pattern2: 00001011101 # pattern2: 00001011101
modules_range = xrange(modules_count) modules_range = range(modules_count)
modules_range_short = xrange(modules_count-10) modules_range_short = range(modules_count-10)
lost_point = 0 lost_point = 0
for row in modules_range: for row in modules_range:
@ -348,14 +350,14 @@ def optimal_data_chunks(data, minimum=4):
:param minimum: The minimum number of bytes in a row to split as a chunk. :param minimum: The minimum number of bytes in a row to split as a chunk.
""" """
data = to_bytestring(data) data = to_bytestring(data)
num_pattern = six.b(r'\d') num_pattern = r'\d'.encode("latin-1")
alpha_pattern = six.b('[') + re.escape(ALPHA_NUM) + six.b(']') alpha_pattern = '['.encode("latin-1") + re.escape(ALPHA_NUM) + ']'.encode("latin-1")
if len(data) <= minimum: if len(data) <= minimum:
num_pattern = re.compile(six.b('^') + num_pattern + six.b('+$')) num_pattern = re.compile('^'.encode("latin-1") + num_pattern + '+$'.encode("latin-1"))
alpha_pattern = re.compile(six.b('^') + alpha_pattern + six.b('+$')) alpha_pattern = re.compile('^'.encode("latin-1") + alpha_pattern + '+$'.encode("latin-1"))
else: else:
re_repeat = ( re_repeat = (
six.b('{') + six.text_type(minimum).encode('ascii') + six.b(',}')) '{'.encode("latin-1") + str(minimum).encode('ascii') + ',}'.encode("latin-1"))
num_pattern = re.compile(num_pattern + re_repeat) num_pattern = re.compile(num_pattern + re_repeat)
alpha_pattern = re.compile(alpha_pattern + re_repeat) alpha_pattern = re.compile(alpha_pattern + re_repeat)
num_bits = _optimal_split(data, num_pattern) num_bits = _optimal_split(data, num_pattern)
@ -390,8 +392,8 @@ def to_bytestring(data):
Convert data to a (utf-8 encoded) byte-string if it isn't a byte-string Convert data to a (utf-8 encoded) byte-string if it isn't a byte-string
already. already.
""" """
if not isinstance(data, six.binary_type): if not isinstance(data, bytes):
data = six.text_type(data).encode('utf-8') data = str(data).encode('utf-8')
return data return data
@ -439,12 +441,12 @@ class QRData(object):
def write(self, buffer): def write(self, buffer):
if self.mode == MODE_NUMBER: if self.mode == MODE_NUMBER:
for i in xrange(0, len(self.data), 3): for i in range(0, len(self.data), 3):
chars = self.data[i:i + 3] chars = self.data[i:i + 3]
bit_length = NUMBER_LENGTH[len(chars)] bit_length = NUMBER_LENGTH[len(chars)]
buffer.put(int(chars), bit_length) buffer.put(int(chars), bit_length)
elif self.mode == MODE_ALPHA_NUM: elif self.mode == MODE_ALPHA_NUM:
for i in xrange(0, len(self.data), 2): for i in range(0, len(self.data), 2):
chars = self.data[i:i + 2] chars = self.data[i:i + 2]
if len(chars) > 1: if len(chars) > 1:
buffer.put( buffer.put(
@ -453,12 +455,13 @@ class QRData(object):
else: else:
buffer.put(ALPHA_NUM.find(chars), 6) buffer.put(ALPHA_NUM.find(chars), 6)
else: else:
if six.PY3: # ~ if six.PY3:
# Iterating a bytestring in Python 3 returns an integer, # Iterating a bytestring in Python 3 returns an integer,
# no need to ord(). # no need to ord().
data = self.data # ~ data = self.data
else: # ~ else:
data = [ord(c) for c in self.data] # ~ data = [ord(c) for c in self.data]
data = self.data
for c in data: for c in data:
buffer.put(c, 8) buffer.put(c, 8)

18
zaz.py
View File

@ -20,6 +20,7 @@
import argparse import argparse
import os import os
import sys import sys
from pathlib import Path
from shutil import copyfile from shutil import copyfile
from subprocess import call from subprocess import call
import zipfile import zipfile
@ -32,6 +33,7 @@ from conf import (
INFO, INFO,
PATHS, PATHS,
TYPE_EXTENSION, TYPE_EXTENSION,
USE_LOCALES,
log) log)
@ -44,7 +46,7 @@ def _join(*paths):
def _mkdir(path): def _mkdir(path):
return os.mkdir(path) return Path(path).mkdir(parents=True, exist_ok=True)
def _save(path, data): def _save(path, data):
@ -112,6 +114,8 @@ def _create_new_directories():
_mkdir(path) _mkdir(path)
path = _join(path_source, DIRS['registration']) path = _join(path_source, DIRS['registration'])
_mkdir(path) _mkdir(path)
path = _join(path_source, DIRS['office'])
_mkdir(path)
if FILES['easymacro'] or DIRS['pythonpath']: if FILES['easymacro'] or DIRS['pythonpath']:
path = _join(path_source, 'pythonpath') path = _join(path_source, 'pythonpath')
@ -221,6 +225,11 @@ def _update_files():
path = _join(path_source, DIRS['meta'], FILES['manifest']) path = _join(path_source, DIRS['meta'], FILES['manifest'])
_save(path, DATA['manifest']) _save(path, DATA['manifest'])
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']) path = _join(path_source, FILES['addons'])
_save(path, DATA['addons']) _save(path, DATA['addons'])
@ -231,6 +240,13 @@ def _update_files():
path = _join(path_source, FILES['addin']) path = _join(path_source, FILES['addin'])
_save(path, DATA['addin']) _save(path, DATA['addin'])
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)
_compile_idl() _compile_idl()
return return