From c169e557cdab4295cf8f29a4ed4746dacdcaa093 Mon Sep 17 00:00:00 2001 From: Daniel-I-Am Date: Mon, 27 Dec 2021 15:51:08 +0100 Subject: [PATCH] Preserve file permissions from template --- run.py | 9 +++++++++ templates/rofi/askpass-rofi | 0 templates/rofi/rofisudo | 0 3 files changed, 9 insertions(+) mode change 100644 => 100755 templates/rofi/askpass-rofi mode change 100644 => 100755 templates/rofi/rofisudo diff --git a/run.py b/run.py index 8b64e95..f3311de 100755 --- a/run.py +++ b/run.py @@ -81,6 +81,8 @@ def convert_template(env, template, key_value_store, out): with open(template, 'r') as file: source = file.read() + template_permissions = oct(os.stat(template).st_mode & 0o777) + template = env.from_string(source) rendered = template.render(**key_value_store) @@ -101,6 +103,7 @@ def convert_template(env, template, key_value_store, out): return dryrun_safe_write(out, rendered) + dryrun_safe_chmod(out, template_permissions) if args.link: first_line = source.split('\n')[0] @@ -134,6 +137,12 @@ def dryrun_safe_write(location, content): else: print(f'Would write to `{location}`.') +def dryrun_safe_chmod(location, permissions): + if not args.dryrun: + os.chmod(location, permissions) + else: + print(f'Would change the permissions of {location} to {permissions}') + def dryrun_safe_remove(location): if not args.dryrun: os.remove(location) diff --git a/templates/rofi/askpass-rofi b/templates/rofi/askpass-rofi old mode 100644 new mode 100755 diff --git a/templates/rofi/rofisudo b/templates/rofi/rofisudo old mode 100644 new mode 100755