Add non-zero exit code on permission check failure

This commit is contained in:
Richard Berger
2020-06-16 07:05:15 -04:00
parent 7a00ec90e5
commit 61235308f1

View File

@ -3,6 +3,7 @@
# #
# Written by Richard Berger (Temple University) # Written by Richard Berger (Temple University)
import os import os
import sys
import glob import glob
import yaml import yaml
import argparse import argparse
@ -70,6 +71,7 @@ def generate_permission_mask(line):
return mask return mask
def check_folder(directory, config, fix=False, verbose=False): def check_folder(directory, config, fix=False, verbose=False):
success = True
files = [] files = []
for base_path in config['include']: for base_path in config['include']:
@ -96,6 +98,10 @@ def check_folder(directory, config, fix=False, verbose=False):
os.chmod(path, mask) os.chmod(path, mask)
else: else:
print("[Error] Can not write permissions of file {}".format(path)) print("[Error] Can not write permissions of file {}".format(path))
success = False
else:
success = False
return success
def main(): def main():
@ -112,7 +118,8 @@ def main():
else: else:
config = yaml.load(DEFAULT_CONFIG, Loader=yaml.FullLoader) config = yaml.load(DEFAULT_CONFIG, Loader=yaml.FullLoader)
check_folder(args.DIRECTORY, config, args.fix, args.verbose) if not check_folder(args.DIRECTORY, config, args.fix, args.verbose):
sys.exit(1)
if __name__ == "__main__": if __name__ == "__main__":
main() main()