Preserve file permissions from template
This commit is contained in:
parent
95c237d2e8
commit
c169e557cd
9
run.py
9
run.py
@ -81,6 +81,8 @@ def convert_template(env, template, key_value_store, out):
|
|||||||
with open(template, 'r') as file:
|
with open(template, 'r') as file:
|
||||||
source = file.read()
|
source = file.read()
|
||||||
|
|
||||||
|
template_permissions = oct(os.stat(template).st_mode & 0o777)
|
||||||
|
|
||||||
template = env.from_string(source)
|
template = env.from_string(source)
|
||||||
rendered = template.render(**key_value_store)
|
rendered = template.render(**key_value_store)
|
||||||
|
|
||||||
@ -101,6 +103,7 @@ def convert_template(env, template, key_value_store, out):
|
|||||||
return
|
return
|
||||||
|
|
||||||
dryrun_safe_write(out, rendered)
|
dryrun_safe_write(out, rendered)
|
||||||
|
dryrun_safe_chmod(out, template_permissions)
|
||||||
|
|
||||||
if args.link:
|
if args.link:
|
||||||
first_line = source.split('\n')[0]
|
first_line = source.split('\n')[0]
|
||||||
@ -134,6 +137,12 @@ def dryrun_safe_write(location, content):
|
|||||||
else:
|
else:
|
||||||
print(f'Would write to `{location}`.')
|
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):
|
def dryrun_safe_remove(location):
|
||||||
if not args.dryrun:
|
if not args.dryrun:
|
||||||
os.remove(location)
|
os.remove(location)
|
||||||
|
|||||||
0
templates/rofi/askpass-rofi
Normal file → Executable file
0
templates/rofi/askpass-rofi
Normal file → Executable file
0
templates/rofi/rofisudo
Normal file → Executable file
0
templates/rofi/rofisudo
Normal file → Executable file
Loading…
Reference in New Issue
Block a user