Merge branch 'fail_on_error' into 'master'
Fail on error See merge request Pmodules/dependency-checker!1
This commit is contained in:
commit
eeec149e8c
@ -6,9 +6,17 @@ from functools import cache
|
|||||||
|
|
||||||
assert sys.version_info >= (3, 7), 'Python version is too low, please load a python >= 3.7'
|
assert sys.version_info >= (3, 7), 'Python version is too low, please load a python >= 3.7'
|
||||||
|
|
||||||
|
failed_at_least_once=False
|
||||||
|
|
||||||
def subprocess_cmd(cmd):
|
def subprocess_cmd(cmd):
|
||||||
return subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, check=True, shell=True)
|
return subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, check=True, shell=True)
|
||||||
|
|
||||||
|
def failure_handler(module, given_status):
|
||||||
|
if len(module) != 0:
|
||||||
|
print('Module: "' + module + '" should be deployed as ' + given_status)
|
||||||
|
global failed_at_least_once
|
||||||
|
failed_at_least_once = True
|
||||||
|
|
||||||
class PmodulePackage():
|
class PmodulePackage():
|
||||||
def __init__(self, name, status, deps=[]):
|
def __init__(self, name, status, deps=[]):
|
||||||
self.name = name
|
self.name = name
|
||||||
@ -27,22 +35,17 @@ class PmodulePackage():
|
|||||||
def check_deps_status(self):
|
def check_deps_status(self):
|
||||||
deps_status = []
|
deps_status = []
|
||||||
for d in self.deps:
|
for d in self.deps:
|
||||||
if d.given_status == 'unstable' and self.given_status == 'stable':
|
|
||||||
print('Dependency ' + d.name + ' is unstable!')
|
|
||||||
elif d.given_status == 'deprecated':
|
|
||||||
print('Dependency ' + d.name + ' is deprecated!')
|
|
||||||
deps_status += d.true_status
|
deps_status += d.true_status
|
||||||
return deps_status
|
return deps_status
|
||||||
|
|
||||||
def check_correct_status(self):
|
def check_correct_status(self, module=''):
|
||||||
if (self.given_status != 'deprecated') and len(self.true_status) > 1:
|
if (self.given_status != 'deprecated') and len(self.true_status) > 1:
|
||||||
print_cmd = 'Package ' + self.name + ' is deployed as ' + self.given_status
|
|
||||||
if 'deprecated' in self.true_status:
|
if 'deprecated' in self.true_status:
|
||||||
print(print_cmd + ' although it should be deployed as deprecated')
|
|
||||||
self.given_status = 'deprecated'
|
self.given_status = 'deprecated'
|
||||||
|
failure_handler(module, self.given_status)
|
||||||
elif self.given_status == 'stable' and 'unstable' in self.true_status:
|
elif self.given_status == 'stable' and 'unstable' in self.true_status:
|
||||||
print(print_cmd + ' although it should be deployed as unstable')
|
|
||||||
self.given_status = 'unstable'
|
self.given_status = 'unstable'
|
||||||
|
failure_handler(module, self.given_status)
|
||||||
self.true_status = [self.given_status]
|
self.true_status = [self.given_status]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -70,18 +73,20 @@ class PmodulePackage():
|
|||||||
Pmodule_pckg.check_correct_status()
|
Pmodule_pckg.check_correct_status()
|
||||||
return Pmodule_pckg
|
return Pmodule_pckg
|
||||||
else:
|
else:
|
||||||
print(pckg_name + ' could not be found using "' + module_cmd + '"')
|
print('Warning: "' + pckg_name + '" could not be found using "' + module_cmd + '"')
|
||||||
return PmodulePackage('', '')
|
return PmodulePackage('', '')
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
module_cmd = 'module search -a --all-deps --no-header'
|
module_cmd = 'module search -a --all-deps --no-header'
|
||||||
module_cmd_process = subprocess_cmd(module_cmd)
|
module_cmd_process = subprocess_cmd(module_cmd)
|
||||||
for package in module_cmd_process.stderr.splitlines():
|
for module in module_cmd_process.stderr.splitlines():
|
||||||
if len(package) != 0:
|
if len(module) != 0:
|
||||||
print('Resolving status of ' + package)
|
package = module.split()
|
||||||
package = package.split()
|
|
||||||
Pmodule_pckg = PmodulePackage(package[0], package[1], package[3:])
|
Pmodule_pckg = PmodulePackage(package[0], package[1], package[3:])
|
||||||
Pmodule_pckg.check_correct_status()
|
Pmodule_pckg.check_correct_status(module)
|
||||||
|
|
||||||
|
if(failed_at_least_once):
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
if __name__=="__main__":
|
if __name__=="__main__":
|
||||||
main()
|
main()
|
Loading…
x
Reference in New Issue
Block a user