Deploying Python Macro Script to LibreOffice Document in Windows 7 using Deployment Script?

I have this deployment script (src) for deploying python macros to LibreOffice (see below) and I want to make the script work on Windows and not just Linux.

However, when I try to deploy with it using it on Windows 7 the zip file created ends up with the C:\ (really C__) in the path where the script is deployed; and I believe that it’s really expecting it to be in Scripts/python not Scripts/python/C__…the file that is deployed to won’t open afterwards stating something about it being corrupt.

from zipfile import ZipFile

import shutil
import sys
import os

if len(sys.argv) < 3:
  print("Usage: {} scriptfile hostdocument".format(sys.argv[0]))
  exit()

MACRO_FILE = sys.argv[1]
DOCUMENT_FILE = sys.argv[2]
MANIFEST_PATH = 'META-INF/manifest.xml';
EMBED_PATH = 'Scripts/python/' + MACRO_FILE;

hasMeta = False
with ZipFile(DOCUMENT_FILE) as bundle:
  
  # grab the manifest
  manifest = []
  for rawLine in bundle.open('META-INF/manifest.xml'):
    line = rawLine.decode('utf-8');
    if MACRO_FILE in line:
      hasMeta = True
    if('</manifest:manifest>' in line) and (hasMeta == False):
      for path in ['Scripts/','Scripts/python', EMBED_PATH]:
        manifest.append('<manifest:file-entry manifest:media-type="application/binary" manifest:full-path="{}"/>').format(path))
      manifest.append(line)
  
  # remove the manifest and script file
  with ZipFile(DOCUENT_FILE + ".tmp", 'w') as tmp:
     for item in bundle.infolist():
        buffer = bundle.read(item.filename)
        if(item.filename not in [MANIFEST_PATH, EMBEDED_PATH]):
           tmp.writestr(item, buffer)

# os.replace(DOCUMENT_FILE + '.tmp', DOCUMENT_FILE); # for python 3.3+
os.remove(DOCUMENT_FILE);
shutil.move(DOCUMENT_FILE + '.tmp', DOCUMENT_FILE)

with ZipFile(DOCUMENT_FILE, 'a') as bundle:
   bundle.write(MACRO_FILE, EMBED_PATH)
   bundle.writestr(MANIFEST_PATH, ''.join(manifest))

print("Added the script {} to {}".format(MACRO_FILE, DOCUMENT_FILE))

@helpdeskaleer: The path did not include “C__” when I tested it, after fixing typos such as changing EMBEDED_PATH on line 34 to EMBED_PATH. What command line did you use - cmd.exe or PowerShell? And what exactly were the parameters? The parameters that worked for me were python 1.py mymac.py "Untitled 1.odt". Finally, as stated in guidelines for asking, do not post as community wiki.

However, I did get the error about the file being corrupt.

For further help, please edit the question and correct the code so that it compiles properly. I clicked on the “src” link but did not see the original code.

@JimK The push_macro.py is here: Environment for scripting LibreOffice with Python · GitHub along with some more source code…

Use APSO to embed macros in LibreOffice documents.