From 3326fb8dfe61c7a711ab76ccbc6bb3a821d7ebf0 Mon Sep 17 00:00:00 2001 From: Jon Date: Wed, 5 Dec 2018 21:37:12 +0100 Subject: [PATCH 1/4] Tidied build.py --- build.py | 81 ++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 50 insertions(+), 31 deletions(-) diff --git a/build.py b/build.py index fa6fe29..338a6ad 100644 --- a/build.py +++ b/build.py @@ -1,4 +1,16 @@ #!/usr/bin/env python +""" +Example use +python build.py + +python build.py 2 true + + +unopkg.exe add --force Mendeley-1.1.1.oxt + +/Applications/LibreOffice.app/Contents/MacOS/unopkg add --force Mendeley-2.oxt + +""" from __future__ import print_function import os @@ -11,8 +23,11 @@ def convert_vba_script_to_xml(input_path, module_name, debug_mode): ''' xml_footer = '' - vba_script = file(input_path).read() - vba_script = vba_script.replace('${DEBUG_MODE}', debug_mode) + + with open(input_path) as vba_file: + vba_script = vba_file.read() + vba_script = vba_script.replace('${DEBUG_MODE}', debug_mode) + xml_script = xml_header + xml.sax.saxutils.escape(vba_script) + xml_footer return xml_script @@ -26,34 +41,38 @@ def convert_vba_script_to_xml(input_path, module_name, debug_mode): EXTENSION_TEMPLATE_DIR = 'MendeleyEmptyExtension.oxt' EXTENSION_SOURCE_DIRS = ['external', 'src'] - extension_archive = zipfile.ZipFile('Mendeley-%s.oxt' % plugin_version, 'w') - for dir_path, dirnames, filenames in os.walk(EXTENSION_TEMPLATE_DIR): - for name in filenames: - file_path = dir_path + '/' + name - if name == 'description.xml': - description_content = file(file_path).read().replace('%PLUGIN_VERSION%', plugin_version) - extension_archive.writestr(name, description_content) - else: - extension_archive.write(file_path, os.path.relpath(file_path, EXTENSION_TEMPLATE_DIR)) - - # Preprocess VBA source files and save to plugin archive - for source_dir in EXTENSION_SOURCE_DIRS: - for dir_path, dirnames, filenames in os.walk(source_dir): + # extension_archive = + with zipfile.ZipFile('Mendeley-%s.oxt' % plugin_version, 'w') as extension_archive: + for dir_path, dirnames, filenames in os.walk(EXTENSION_TEMPLATE_DIR): for name in filenames: - if name.endswith('.vb'): - # VBA files are converted to XML files with a single