Optimize things that need to run if already correct
This commit is contained in:
parent
2c1000af45
commit
c959f14172
14
run.py
14
run.py
@ -91,7 +91,8 @@ def convert_template(env, template, key_value_store, out):
|
|||||||
if not os.path.isdir(out_dir_name):
|
if not os.path.isdir(out_dir_name):
|
||||||
dryrun_safe_mkdir(out_dir_name)
|
dryrun_safe_mkdir(out_dir_name)
|
||||||
|
|
||||||
if os.path.isfile(out) and not args.force:
|
if os.path.isfile(out):
|
||||||
|
if is_content_different(out, rendered):
|
||||||
if args.diff:
|
if args.diff:
|
||||||
with open(out) as file:
|
with open(out) as file:
|
||||||
current = file.read()
|
current = file.read()
|
||||||
@ -104,8 +105,13 @@ def convert_template(env, template, key_value_store, out):
|
|||||||
return
|
return
|
||||||
|
|
||||||
dryrun_safe_write(out, rendered)
|
dryrun_safe_write(out, rendered)
|
||||||
|
|
||||||
if template_permissions != default_permissions:
|
if template_permissions != default_permissions:
|
||||||
dryrun_safe_chmod(out, template_permissions)
|
dryrun_safe_chmod(out, template_permissions)
|
||||||
|
else:
|
||||||
|
current_permissions = os.stat(out).st_mode & 0o777
|
||||||
|
if template_permissions != current_permissions:
|
||||||
|
dryrun_safe_chmod(out, template_permissions)
|
||||||
|
|
||||||
if args.link:
|
if args.link:
|
||||||
first_line = source.split('\n')[0]
|
first_line = source.split('\n')[0]
|
||||||
@ -135,6 +141,12 @@ def create_symlink(source, destination):
|
|||||||
|
|
||||||
dryrun_safe_create_symlink(source, destination)
|
dryrun_safe_create_symlink(source, destination)
|
||||||
|
|
||||||
|
def is_content_different(file_location, test_content):
|
||||||
|
with open(file_location) as file:
|
||||||
|
content = file.read()
|
||||||
|
|
||||||
|
return content != test_content
|
||||||
|
|
||||||
def get_current_umask():
|
def get_current_umask():
|
||||||
current_umask = os.umask(0o022)
|
current_umask = os.umask(0o022)
|
||||||
os.umask(current_umask)
|
os.umask(current_umask)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user