I learnt about 2 days ago how to get Python macros to work, and then how to incorporate them into an LO file (in my case Base files, .odb).
From a tutorial I learnt this technique, using a utility Python file to package up the Python file containing the macro(s):
shutil.copyfile(existing_odb_file_str, new_document_file) # new_document_file is the version of the .odb in another directory, which will have the macros added:
doc = zipfile.ZipFile(new_document_file, 'a')
doc.write(macro_script_file_str, f"Scripts/python/{macro_script_file_str}")
# configure_logging_file_str = 'configure_logging.py'
# doc.write(configure_logging_file_str, f"Scripts/python/{configure_logging_file_str}")
manifest = []
for line in doc.open('META-INF/manifest.xml'):
if '</manifest:manifest>' in line.decode('utf-8'):
for path in ['Scripts/','Scripts/python/', f'Scripts/python/{macro_script_file_str}']:
# for path in ['Scripts/','Scripts/python/', f'Scripts/python/{macro_script_file_str}', f'Scripts/python/{configure_logging_file_str}']:
manifest.append(' <manifest:file-entry manifest:media-type="application/binary" manifest:full-path="%s"/>' % path)
manifest.append(line.decode('utf-8'))
doc.writestr('META-INF/manifest.xml', ''.join(manifest))
doc.close()
As may be apparent, what Iām now trying to do is to also package up another file, configure_logging.py, and then import configure_logging
from the (in-odb-file) macro script file proper.
To clarify, I want both of these Python files to be packaged up in the .odb form.
If you uncomment the commented lines above you see what I have tried. But the line import configure_logging
raises ModuleNotFoundError
. What should I be doing?