From 0f12e20b918aa0f650ab4c1d86938c3b713766c5 Mon Sep 17 00:00:00 2001 From: Vladislav Yarmak Date: Sat, 14 Sep 2019 16:10:28 +0300 Subject: [PATCH] ap: direct mode --- win/tools/autopatch/autopatch.py | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/win/tools/autopatch/autopatch.py b/win/tools/autopatch/autopatch.py index 14539d9..c060974 100755 --- a/win/tools/autopatch/autopatch.py +++ b/win/tools/autopatch/autopatch.py @@ -44,6 +44,10 @@ def parse_args(): parser.add_argument("-o", "--stdout", action="store_true", help="output into stdout") + parser.add_argument("-D", "--direct", + action="store_true", + help="supply patched library directly instead of " + "installer file. Implies --stdout option.") args = parser.parse_args() return args @@ -113,13 +117,18 @@ def make_patch(archive, *, arch_tgt, search, replacement, - sevenzip="7z"): - with tempfile.TemporaryDirectory() as tmpdir: - with ExtractedTarget(archive, - tmpdir, - arch_tgt, - sevenzip=sevenzip) as tgt: - f = expand(tgt, sevenzip=sevenzip) + sevenzip="7z", + direct=False): + if direct: + with open(archive, 'rb') as fo: + f = fo.read() + else: + with tempfile.TemporaryDirectory() as tmpdir: + with ExtractedTarget(archive, + tmpdir, + arch_tgt, + sevenzip=sevenzip) as tgt: + f = expand(tgt, sevenzip=sevenzip) offset = f.find(search) del f if offset == -1: @@ -160,9 +169,10 @@ def main(): arch_tgt=args.target, search=search, replacement=replacement, - sevenzip=args.sevenzip) + sevenzip=args.sevenzip, + direct=args.direct) patch_content = format_patch(patch, args.target_name) - if args.stdout: + if args.stdout or args.direct: with open(sys.stdout.fileno(), mode='wb', closefd=False) as out: out.write(patch_content) else: