mirror of
https://github.com/PiBrewing/craftbeerpi4.git
synced 2024-11-10 01:17:42 +01:00
Added check for plugin addition
before plugin is added to the config, cli.py checks if the package does exist and if the name is correct (capital letters,...)
This commit is contained in:
parent
259f5abc78
commit
972c9dbf49
2 changed files with 25 additions and 14 deletions
|
@ -1 +1 @@
|
|||
__version__ = "4.0.1.15"
|
||||
__version__ = "4.0.1.16"
|
||||
|
|
37
cbpi/cli.py
37
cbpi/cli.py
|
@ -218,20 +218,31 @@ def plugins_add(package_name):
|
|||
return
|
||||
return
|
||||
|
||||
installation = True
|
||||
try:
|
||||
with open(os.path.join(".", 'config', "config.yaml"), 'rt') as f:
|
||||
data = yaml.load(f, Loader=yaml.FullLoader)
|
||||
if package_name in data["plugins"]:
|
||||
print("")
|
||||
print("Plugin {} already active".format(package_name))
|
||||
print("")
|
||||
return
|
||||
data["plugins"].append(package_name)
|
||||
with open(os.path.join(".", 'config', "config.yaml"), 'w') as outfile:
|
||||
yaml.dump(data, outfile, default_flow_style=False)
|
||||
print("")
|
||||
print("Plugin {} activated".format(package_name))
|
||||
print("")
|
||||
try:
|
||||
p_metadata= metadata(package_name)
|
||||
p_name=p_metadata['Name']
|
||||
if p_name != package_name:
|
||||
print("Error. Package name {} does not exist. Did you mean {}".format(package_name,p_name))
|
||||
installation = False
|
||||
except Exception as e:
|
||||
print("Error. Package {} cannot be found in installed packages".format(package_name))
|
||||
installation = False
|
||||
if installation:
|
||||
with open(os.path.join(".", 'config', "config.yaml"), 'rt') as f:
|
||||
data = yaml.load(f, Loader=yaml.FullLoader)
|
||||
if package_name in data["plugins"]:
|
||||
print("")
|
||||
print("Plugin {} already active".format(package_name))
|
||||
print("")
|
||||
return
|
||||
data["plugins"].append(package_name)
|
||||
with open(os.path.join(".", 'config', "config.yaml"), 'w') as outfile:
|
||||
yaml.dump(data, outfile, default_flow_style=False)
|
||||
print("")
|
||||
print("Plugin {} activated".format(package_name))
|
||||
print("")
|
||||
except Exception as e:
|
||||
print(e)
|
||||
pass
|
||||
|
|
Loading…
Reference in a new issue