From 39f83d3dc2fbcadab759b49f0f36b39b8dc266d8 Mon Sep 17 00:00:00 2001 From: Julien Nabet Date: Fri, 17 Nov 2023 13:21:17 +0100 Subject: [PATCH] createmsi: retrieve file handle explicitely so we can close it at the end Seen on https://ci.libreoffice.org/view/tb%20platform%20status/job/lo_daily_tb_win_wix/3/console [build PRL] CustomTarget/instsetoo_native/install/install.phony Exception ignored in: <_io.FileIO name='lo.json' mode='rb' closefd=True> Traceback (most recent call last): File "C:\cygwin64\home\tdf\jenkins\daily_workspace\tb\src_master\msicreator\createmsi.py", line 42, in __init__ jsondata = json.load(open(jsonfile, 'rb')) ResourceWarning: unclosed file <_io.BufferedReader name='lo.json'> Change-Id: I98b7436e4e870f4cbcd31a41a4e9d0e84249f5f9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159566 Tested-by: Jenkins Reviewed-by: Mike Kaganski --- msicreator/createmsi.py | 115 ++++++++++++++++++++-------------------- 1 file changed, 58 insertions(+), 57 deletions(-) diff --git a/msicreator/createmsi.py b/msicreator/createmsi.py index 23ae885906ff..d728e64520d2 100644 --- a/msicreator/createmsi.py +++ b/msicreator/createmsi.py @@ -39,65 +39,66 @@ class UIGraphics: class PackageGenerator: def __init__(self, jsonfile): - jsondata = json.load(open(jsonfile, 'rb')) - self.product_name = jsondata['product_name'] - self.manufacturer = jsondata['manufacturer'] - self.version = jsondata['version'] - self.comments = jsondata['comments'] - self.installdir = jsondata['installdir'] - self.license_file = jsondata.get('license_file', None) - self.name = jsondata['name'] - self.guid = jsondata.get('product_guid', '*') - self.upgrade_guid = jsondata['upgrade_guid'] - self.basename = jsondata['name_base'] - self.need_msvcrt = jsondata.get('need_msvcrt', False) - self.addremove_icon = jsondata.get('addremove_icon', None) - self.startmenu_shortcut = jsondata.get('startmenu_shortcut', None) - self.desktop_shortcut = jsondata.get('desktop_shortcut', None) - self.main_xml = self.basename + '.wxs' - self.main_o = self.basename + '.wixobj' - self.idnum = 0 - self.graphics = UIGraphics() - if 'graphics' in jsondata: - if 'banner' in jsondata['graphics']: - self.graphics.banner = jsondata['graphics']['banner'] - if 'background' in jsondata['graphics']: - self.graphics.background = jsondata['graphics']['background'] - if 'arch' in jsondata: - self.arch = jsondata['arch'] - else: - # rely on the environment variable since python architecture may not be the same as system architecture - if 'PROGRAMFILES(X86)' in os.environ: - self.arch = 64 + with open(jsonfile, 'rb') as f: + jsondata = json.load(f) + self.product_name = jsondata['product_name'] + self.manufacturer = jsondata['manufacturer'] + self.version = jsondata['version'] + self.comments = jsondata['comments'] + self.installdir = jsondata['installdir'] + self.license_file = jsondata.get('license_file', None) + self.name = jsondata['name'] + self.guid = jsondata.get('product_guid', '*') + self.upgrade_guid = jsondata['upgrade_guid'] + self.basename = jsondata['name_base'] + self.need_msvcrt = jsondata.get('need_msvcrt', False) + self.addremove_icon = jsondata.get('addremove_icon', None) + self.startmenu_shortcut = jsondata.get('startmenu_shortcut', None) + self.desktop_shortcut = jsondata.get('desktop_shortcut', None) + self.main_xml = self.basename + '.wxs' + self.main_o = self.basename + '.wixobj' + self.idnum = 0 + self.graphics = UIGraphics() + if 'graphics' in jsondata: + if 'banner' in jsondata['graphics']: + self.graphics.banner = jsondata['graphics']['banner'] + if 'background' in jsondata['graphics']: + self.graphics.background = jsondata['graphics']['background'] + if 'arch' in jsondata: + self.arch = jsondata['arch'] else: - self.arch = 32 if '32' in platform.architecture()[0] else 64 - self.final_output = '%s-%s-%d.msi' % (self.basename, self.version, self.arch) - if self.arch == 64: - self.progfile_dir = 'ProgramFiles64Folder' - if platform.system() == "Windows": - redist_glob = 'C:\\Program Files\\Microsoft Visual Studio\\*\\*\\VC\\Redist\\MSVC\\v*\\MergeModules\\Microsoft_VC*_CRT_x64.msm' + # rely on the environment variable since python architecture may not be the same as system architecture + if 'PROGRAMFILES(X86)' in os.environ: + self.arch = 64 + else: + self.arch = 32 if '32' in platform.architecture()[0] else 64 + self.final_output = '%s-%s-%d.msi' % (self.basename, self.version, self.arch) + if self.arch == 64: + self.progfile_dir = 'ProgramFiles64Folder' + if platform.system() == "Windows": + redist_glob = 'C:\\Program Files\\Microsoft Visual Studio\\*\\*\\VC\\Redist\\MSVC\\v*\\MergeModules\\Microsoft_VC*_CRT_x64.msm' + else: + redist_glob = '/usr/share/msicreator/Microsoft_VC141_CRT_x64.msm' else: - redist_glob = '/usr/share/msicreator/Microsoft_VC141_CRT_x64.msm' - else: - self.progfile_dir = 'ProgramFilesFolder' - if platform.system() == "Windows": - redist_glob = 'C:\\Program Files\\Microsoft Visual Studio\\*\\Community\\VC\\Redist\\MSVC\\*\\MergeModules\\Microsoft_VC*_CRT_x86.msm' - else: - redist_glob = '/usr/share/msicreator/Microsoft_VC141_CRT_x86.msm' - trials = glob(redist_glob) - if self.need_msvcrt: - if len(trials) > 1: - sys.exit('There are more than one redist dirs: ' + - ', '.join(trials)) - if len(trials) == 0: - sys.exit('No redist dirs were detected, install MSM redistributables with VS installer.') - self.redist_path = trials[0] - self.component_num = 0 - self.registry_entries = jsondata.get('registry_entries', None) - self.major_upgrade = jsondata.get('major_upgrade', None) - self.parts = jsondata['parts'] - self.feature_components = {} - self.feature_properties = {} + self.progfile_dir = 'ProgramFilesFolder' + if platform.system() == "Windows": + redist_glob = 'C:\\Program Files\\Microsoft Visual Studio\\*\\Community\\VC\\Redist\\MSVC\\*\\MergeModules\\Microsoft_VC*_CRT_x86.msm' + else: + redist_glob = '/usr/share/msicreator/Microsoft_VC141_CRT_x86.msm' + trials = glob(redist_glob) + if self.need_msvcrt: + if len(trials) > 1: + sys.exit('There are more than one redist dirs: ' + + ', '.join(trials)) + if len(trials) == 0: + sys.exit('No redist dirs were detected, install MSM redistributables with VS installer.') + self.redist_path = trials[0] + self.component_num = 0 + self.registry_entries = jsondata.get('registry_entries', None) + self.major_upgrade = jsondata.get('major_upgrade', None) + self.parts = jsondata['parts'] + self.feature_components = {} + self.feature_properties = {} def generate_files(self): self.root = ET.Element('Wix', {'xmlns': 'http://schemas.microsoft.com/wix/2006/wi'})