From cd93eb85e2755d8e21ef4dc0d68626f9e2b40dfe Mon Sep 17 00:00:00 2001 From: Vladislav Yarmak Date: Wed, 4 Sep 2019 18:20:51 +0300 Subject: [PATCH 1/2] ap: allow batch operation against multiple package files --- win/tools/autopatch/autopatch.py | 78 ++++++++++++++++---------------- 1 file changed, 40 insertions(+), 38 deletions(-) diff --git a/win/tools/autopatch/autopatch.py b/win/tools/autopatch/autopatch.py index 8a25864..14539d9 100755 --- a/win/tools/autopatch/autopatch.py +++ b/win/tools/autopatch/autopatch.py @@ -22,7 +22,8 @@ def parse_args(): description="Generates .1337 patch for Nvidia drivers for Windows", formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument("installer_file", - help="location of installer executable") + nargs="+", + help="location of installer executable(s)") parser.add_argument("-7", "--7zip", default="7z", dest="sevenzip", @@ -154,44 +155,45 @@ def main(): replacement = unhexlify(args.replacement) assert len(search) == len(replacement), "len() of search and replacement"\ " is not equal" - patch = make_patch(args.installer_file, - arch_tgt=args.target, - search=search, - replacement=replacement, - sevenzip=args.sevenzip) - patch_content = format_patch(patch, args.target_name) - if args.stdout: - with open(sys.stdout.fileno(), mode='wb', closefd=False) as out: - out.write(patch_content) - else: - version, product_type = identify_driver(args.installer_file, - sevenzip=args.sevenzip) - drv_prefix = { - "100": "quadro_", - "300": "", - "301": "nsd_", - } - installer_name = os.path.basename(args.installer_file).lower() - if 'winserv2008' in installer_name: - os_prefix = 'ws2012_x64' - elif 'winserv-2016' in installer_name: - os_prefix = 'ws2016_x64' - elif 'win10' in installer_name: - os_prefix = 'win10_x64' - elif 'win7' in installer_name: - os_prefix = 'win7_x64' + for installer_file in args.installer_file: + patch = make_patch(installer_file, + arch_tgt=args.target, + search=search, + replacement=replacement, + sevenzip=args.sevenzip) + patch_content = format_patch(patch, args.target_name) + if args.stdout: + with open(sys.stdout.fileno(), mode='wb', closefd=False) as out: + out.write(patch_content) else: - raise UnknownPlatformException("Can't infer platform from filename %s" - % (repr(installer_name),)) - driver_name = drv_prefix[product_type] + version - out_dir = os.path.join( - os.path.dirname( - os.path.abspath(__file__)), '..', '..', os_prefix, driver_name) - os.makedirs(out_dir, 0o755, True) - out_filename = os.path.join(out_dir, - os.path.splitext(args.target_name)[0] + PATCH_EXT) - with open(out_filename, 'xb') as out: - out.write(patch_content) + version, product_type = identify_driver(installer_file, + sevenzip=args.sevenzip) + drv_prefix = { + "100": "quadro_", + "300": "", + "301": "nsd_", + } + installer_name = os.path.basename(installer_file).lower() + if 'winserv2008' in installer_name: + os_prefix = 'ws2012_x64' + elif 'winserv-2016' in installer_name: + os_prefix = 'ws2016_x64' + elif 'win10' in installer_name: + os_prefix = 'win10_x64' + elif 'win7' in installer_name: + os_prefix = 'win7_x64' + else: + raise UnknownPlatformException("Can't infer platform from filename %s" + % (repr(installer_name),)) + driver_name = drv_prefix[product_type] + version + out_dir = os.path.join( + os.path.dirname( + os.path.abspath(__file__)), '..', '..', os_prefix, driver_name) + os.makedirs(out_dir, 0o755, True) + out_filename = os.path.join(out_dir, + os.path.splitext(args.target_name)[0] + PATCH_EXT) + with open(out_filename, 'xb') as out: + out.write(patch_content) if __name__ == '__main__': From aeeeaa2f8d6efe7f4020cd238014be92673059f0 Mon Sep 17 00:00:00 2001 From: Vladislav Yarmak Date: Wed, 4 Sep 2019 18:31:30 +0300 Subject: [PATCH 2/2] ap: update docs --- win/tools/autopatch/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/win/tools/autopatch/README.md b/win/tools/autopatch/README.md index fdaf9b4..cb21f52 100644 --- a/win/tools/autopatch/README.md +++ b/win/tools/autopatch/README.md @@ -16,12 +16,12 @@ This script accepts path to Nvidia Drivers installer, makes .1337 patch and save $ ./autopatch.py --help usage: autopatch.py [-h] [-7 SEVENZIP] [-T TARGET] [-N TARGET_NAME] [-S SEARCH] [-R REPLACEMENT] [-o] - installer_file + installer_file [installer_file ...] Generates .1337 patch for Nvidia drivers for Windows positional arguments: - installer_file location of installer executable + installer_file location of installer executable(s) optional arguments: -h, --help show this help message and exit