Merge "File validation extended to callback_plugins, main loop optimized"
This commit is contained in:
commit
45a525037b
|
@ -22,6 +22,7 @@ def exit_usage():
|
||||||
|
|
||||||
|
|
||||||
def validate_library_file(file_path, quiet):
|
def validate_library_file(file_path, quiet):
|
||||||
|
|
||||||
with open(file_path) as f:
|
with open(file_path) as f:
|
||||||
file_content = f.read()
|
file_content = f.read()
|
||||||
if 'DOCUMENTATION = ' not in file_content \
|
if 'DOCUMENTATION = ' not in file_content \
|
||||||
|
@ -32,6 +33,30 @@ def validate_library_file(file_path, quiet):
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
def validate_callback_file(file_path, quiet):
|
||||||
|
required_attributes = [
|
||||||
|
'CALLBACK_VERSION',
|
||||||
|
'CALLBACK_NAME']
|
||||||
|
|
||||||
|
with open(file_path) as file:
|
||||||
|
file_content = file.read()
|
||||||
|
if any([attr not in file_content for attr in required_attributes]):
|
||||||
|
if quiet < 3:
|
||||||
|
print(
|
||||||
|
'Missing required callback plugin attributes in {}'.format(file_path))
|
||||||
|
return 1
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
def validate_file(file_path, quiet):
|
||||||
|
if os.path.split(file_path)[0].endswith('library'):
|
||||||
|
return validate_library_file(file_path, quiet)
|
||||||
|
elif os.path.split(file_path)[0].endswith('callback_plugins'):
|
||||||
|
return validate_callback_file(file_path, quiet)
|
||||||
|
else:
|
||||||
|
raise ValueError()
|
||||||
|
|
||||||
|
|
||||||
def parse_args():
|
def parse_args():
|
||||||
p = argparse.ArgumentParser()
|
p = argparse.ArgumentParser()
|
||||||
|
|
||||||
|
@ -52,28 +77,32 @@ def main():
|
||||||
path_args = args.path_args
|
path_args = args.path_args
|
||||||
quiet = args.quiet
|
quiet = args.quiet
|
||||||
exit_val = 0
|
exit_val = 0
|
||||||
|
scanned_subdirs = ['callback_plugins', 'library']
|
||||||
failed_files = []
|
failed_files = []
|
||||||
|
|
||||||
for base_path in path_args:
|
for base_path in path_args:
|
||||||
|
scanned_paths = [
|
||||||
|
os.path.join(
|
||||||
|
base_path,
|
||||||
|
'validations_common',
|
||||||
|
path) for path in scanned_subdirs]
|
||||||
|
|
||||||
if os.path.isdir(base_path):
|
if os.path.isdir(base_path):
|
||||||
for subdir, dirs, files in os.walk(base_path):
|
for subdir, dirs, files in os.walk(base_path):
|
||||||
if '.tox' in dirs:
|
if '.tox' in dirs:
|
||||||
dirs.remove('.tox')
|
dirs.remove('.tox')
|
||||||
if '.git' in dirs:
|
if '.git' in dirs:
|
||||||
dirs.remove('.git')
|
dirs.remove('.git')
|
||||||
for f in files:
|
if subdir in scanned_paths:
|
||||||
if f.endswith('.py') \
|
for f in files:
|
||||||
and not f == '__init__.py' \
|
if f.endswith('.py') and f != '__init__.py':
|
||||||
and subdir in [os.path.join(base_path,
|
file_path = os.path.join(subdir, f)
|
||||||
'validations_common',
|
if quiet < 1:
|
||||||
'library')]:
|
print('Validating {}'.format(file_path))
|
||||||
file_path = os.path.join(subdir, f)
|
failed = validate_file(file_path, quiet)
|
||||||
if quiet < 1:
|
if failed:
|
||||||
print('Validating {}'.format(file_path))
|
failed_files.append(file_path)
|
||||||
failed = validate_library_file(file_path, quiet)
|
exit_val |= failed
|
||||||
if failed:
|
|
||||||
failed_files.append(file_path)
|
|
||||||
exit_val |= failed
|
|
||||||
else:
|
else:
|
||||||
print('Unexpected argument {}'.format(base_path))
|
print('Unexpected argument {}'.format(base_path))
|
||||||
exit_usage()
|
exit_usage()
|
||||||
|
|
Loading…
Reference in New Issue