From fddeec93a71e71629e9ff6f06ca4c239282bf958 Mon Sep 17 00:00:00 2001 From: Lertsenem Date: Thu, 23 Jul 2020 09:44:23 +0200 Subject: [PATCH] Fix script to change msi file The msi modification failed because the msi file was still open when the script started modifying it. The simplest solution was to put all that in another separate setup_noadmin.py script. --- setup.py | 69 ---------------------------------------- setup_noadmin.py | 83 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 69 deletions(-) create mode 100644 setup_noadmin.py diff --git a/setup.py b/setup.py index 06fcada..6316708 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,5 @@ import distutils, distutils.util -import msilib import os -import pathlib import setuptools import sys @@ -61,73 +59,6 @@ if os.name == "nt": ], ) - - # ------------------------------------------------------------------------- - # Modifications to allow for a non-admin-required msi - print("modifying final msi '{}' for standard user installation" \ - .format(msi_filepath)) - if not msi_filepath.exists(): - print("msi file does not exist") - else: - try: - db = msilib.OpenDatabase( - str(msi_filepath), - msilib.MSIDBOPEN_TRANSACT, - ) - - si = db.GetSummaryInformation(20) - cur_wc = si.GetProperty(msilib.PID_WORDCOUNT) - si.SetProperty( - msilib.PID_WORDCOUNT, - cur_wc | 0b1000, - ) - si.SetProperty( - msilib.PID_AUTHOR, - "{} - {}" \ - .format( - lokrez.version.ENTITY, - lokrez.version.AUTHOR, - ), - ) - si.Persist() - - # Install for the current user only - vi = db.OpenView( - "DELETE FROM `Property` WHERE `Property`.`Property` = " \ - "'ALLUSERS'", - ) - vi.Execute(None) - vi.Close() - - # Add the manufacturer name - vi = db.OpenView( - "UPDATE `Property` SET `Property`.`Value`='{} - {}' WHERE " \ - "`Property`.`Property` = 'Manufacturer'" \ - .format( - lokrez.version.ENTITY, - lokrez.version.AUTHOR, - ), - ) - vi.Execute(None) - vi.Close() - - # Update Path env variable for the user only - vi = db.OpenView( - "UPDATE `Environment` SET `Environment`.`Name`='=-Path' " \ - "WHERE `Environment`.`Environment` = 'E_PATH'", - ) - vi.Execute(None) - vi.Close() - - db.Commit() - db.Close() - - except Exception as e: - print("fail") - print(str(e)) - print(e.args) - raise - sys.exit(0) # Linux build diff --git a/setup_noadmin.py b/setup_noadmin.py new file mode 100644 index 0000000..ac8b772 --- /dev/null +++ b/setup_noadmin.py @@ -0,0 +1,83 @@ +import distutils, distutils.util +import msilib +import pathlib + +import lokrez, lokrez.version + +# ----------------------------------------------------------------------------- +arch = distutils.util.get_platform().split("-")[-1] + +msi_filepath = pathlib.Path( + "dist", + "{}-{}-{}.msi" \ + .format( + lokrez.version.NAME, + lokrez.version.__version__.replace("dev", "1337"), + arch, + ), + ) + +# ----------------------------------------------------------------------------- +# Modifications to allow for a non-admin-required msi +print("modifying final msi '{}' for standard user installation" \ + .format(msi_filepath)) +if not msi_filepath.exists(): + print("msi file does not exist") +else: + try: + db = msilib.OpenDatabase( + str(msi_filepath), + msilib.MSIDBOPEN_TRANSACT, + ) + + si = db.GetSummaryInformation(20) + cur_wc = si.GetProperty(msilib.PID_WORDCOUNT) + si.SetProperty( + msilib.PID_WORDCOUNT, + cur_wc | 0b1000, + ) + si.SetProperty( + msilib.PID_AUTHOR, + "{} - {}" \ + .format( + lokrez.version.ENTITY, + lokrez.version.AUTHOR, + ), + ) + si.Persist() + + # Install for the current user only + vi = db.OpenView( + "DELETE FROM `Property` WHERE `Property`.`Property` = 'ALLUSERS'" + ) + vi.Execute(None) + vi.Close() + + # Add the manufacturer name + vi = db.OpenView( + "UPDATE `Property` SET `Property`.`Value`='{} - {}' WHERE " \ + "`Property`.`Property` = 'Manufacturer'" \ + .format( + lokrez.version.ENTITY, + lokrez.version.AUTHOR, + ), + ) + vi.Execute(None) + vi.Close() + + # Update Path env variable for the user only + vi = db.OpenView( + "UPDATE `Environment` SET `Environment`.`Name`='=-Path' " \ + "WHERE `Environment`.`Environment` = 'E_PATH'", + ) + vi.Execute(None) + vi.Close() + + db.Commit() + db.Close() + + except Exception as e: + print("fail") + print(str(e)) + print(e.args) + raise