mirror of
https://github.com/PiBrewing/craftbeerpi4.git
synced 2024-11-25 08:28:23 +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
|
||||||
return
|
return
|
||||||
|
|
||||||
|
installation = True
|
||||||
try:
|
try:
|
||||||
with open(os.path.join(".", 'config', "config.yaml"), 'rt') as f:
|
try:
|
||||||
data = yaml.load(f, Loader=yaml.FullLoader)
|
p_metadata= metadata(package_name)
|
||||||
if package_name in data["plugins"]:
|
p_name=p_metadata['Name']
|
||||||
print("")
|
if p_name != package_name:
|
||||||
print("Plugin {} already active".format(package_name))
|
print("Error. Package name {} does not exist. Did you mean {}".format(package_name,p_name))
|
||||||
print("")
|
installation = False
|
||||||
return
|
except Exception as e:
|
||||||
data["plugins"].append(package_name)
|
print("Error. Package {} cannot be found in installed packages".format(package_name))
|
||||||
with open(os.path.join(".", 'config', "config.yaml"), 'w') as outfile:
|
installation = False
|
||||||
yaml.dump(data, outfile, default_flow_style=False)
|
if installation:
|
||||||
print("")
|
with open(os.path.join(".", 'config', "config.yaml"), 'rt') as f:
|
||||||
print("Plugin {} activated".format(package_name))
|
data = yaml.load(f, Loader=yaml.FullLoader)
|
||||||
print("")
|
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:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Reference in a new issue