add update plugin, better completion for plugins
This commit is contained in:
parent
e07f7ff130
commit
26ea2e588d
@ -1,2 +1,2 @@
|
|||||||
__version__ = "3.8.0b3"
|
__version__ = "3.8.0b4"
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ def _get_plugins(which, defaultdir):
|
|||||||
return enabled_files
|
return enabled_files
|
||||||
elif which == "--enable":
|
elif which == "--enable":
|
||||||
return disabled_files
|
return disabled_files
|
||||||
elif which == "--del":
|
elif which in ["--del", "--update"]:
|
||||||
all_files.extend(enabled_files)
|
all_files.extend(enabled_files)
|
||||||
all_files.extend(disabled_files)
|
all_files.extend(disabled_files)
|
||||||
return all_files
|
return all_files
|
||||||
@ -91,6 +91,12 @@ def main():
|
|||||||
folders = _getallfolders(config)
|
folders = _getallfolders(config)
|
||||||
profiles = list(config["profiles"].keys())
|
profiles = list(config["profiles"].keys())
|
||||||
plugins = _get_plugins("all", defaultdir)
|
plugins = _get_plugins("all", defaultdir)
|
||||||
|
info = {}
|
||||||
|
info["config"] = config
|
||||||
|
info["nodes"] = nodes
|
||||||
|
info["folders"] = folders
|
||||||
|
info["profiles"] = profiles
|
||||||
|
info["plugins"] = plugins
|
||||||
app = sys.argv[1]
|
app = sys.argv[1]
|
||||||
if app in ["bash", "zsh"]:
|
if app in ["bash", "zsh"]:
|
||||||
positions = [2,4]
|
positions = [2,4]
|
||||||
@ -111,7 +117,7 @@ def main():
|
|||||||
module = importlib.util.module_from_spec(spec)
|
module = importlib.util.module_from_spec(spec)
|
||||||
spec.loader.exec_module(module)
|
spec.loader.exec_module(module)
|
||||||
plugin_completion = getattr(module, "_connpy_completion")
|
plugin_completion = getattr(module, "_connpy_completion")
|
||||||
strings = plugin_completion(wordsnumber, words)
|
strings = plugin_completion(wordsnumber, words, info)
|
||||||
except:
|
except:
|
||||||
exit()
|
exit()
|
||||||
elif wordsnumber >= 3 and words[0] == "ai":
|
elif wordsnumber >= 3 and words[0] == "ai":
|
||||||
@ -138,7 +144,7 @@ def main():
|
|||||||
if words[0] in ["--rm", "--del", "-r", "--mod", "--edit", "-e", "--show", "-s", "mv", "move", "cp", "copy"]:
|
if words[0] in ["--rm", "--del", "-r", "--mod", "--edit", "-e", "--show", "-s", "mv", "move", "cp", "copy"]:
|
||||||
strings.extend(nodes)
|
strings.extend(nodes)
|
||||||
if words[0] == "plugin":
|
if words[0] == "plugin":
|
||||||
strings = ["--help", "--add", "--del", "--enable", "--disable"]
|
strings = ["--help", "--add", "--update", "--del", "--enable", "--disable"]
|
||||||
if words[0] in ["run", "import", "export"]:
|
if words[0] in ["run", "import", "export"]:
|
||||||
strings = ["--help"]
|
strings = ["--help"]
|
||||||
if words[0] == "export":
|
if words[0] == "export":
|
||||||
@ -167,12 +173,12 @@ def main():
|
|||||||
if words[0] == "config" and words[1] in ["--fzf", "--allow-uppercase"]:
|
if words[0] == "config" and words[1] in ["--fzf", "--allow-uppercase"]:
|
||||||
strings=["true", "false"]
|
strings=["true", "false"]
|
||||||
if words[0] == "config" and words[1] in ["--configfolder"]:
|
if words[0] == "config" and words[1] in ["--configfolder"]:
|
||||||
strings=_getcwd(words,words[0],True)
|
strings=_getcwd(words,words[1],True)
|
||||||
if words[0] == "plugin" and words[1] in ["--del", "--enable", "--disable"]:
|
if words[0] == "plugin" and words[1] in ["--update", "--del", "--enable", "--disable"]:
|
||||||
strings=_get_plugins(words[1], defaultdir)
|
strings=_get_plugins(words[1], defaultdir)
|
||||||
|
|
||||||
elif wordsnumber == 5 and words[0] == "plugin" and words[1] == "--add":
|
elif wordsnumber == 5 and words[0] == "plugin" and words[1] in ["--add", "--update"]:
|
||||||
strings=_getcwd(words, words[0])
|
strings=_getcwd(words, words[2])
|
||||||
else:
|
else:
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
|
@ -140,6 +140,7 @@ class connapp:
|
|||||||
pluginparser = subparsers.add_parser("plugin", description="Manage plugins")
|
pluginparser = subparsers.add_parser("plugin", description="Manage plugins")
|
||||||
plugincrud = pluginparser.add_mutually_exclusive_group(required=True)
|
plugincrud = pluginparser.add_mutually_exclusive_group(required=True)
|
||||||
plugincrud.add_argument("--add", metavar=("PLUGIN", "FILE"), nargs=2, help="Add new plugin")
|
plugincrud.add_argument("--add", metavar=("PLUGIN", "FILE"), nargs=2, help="Add new plugin")
|
||||||
|
plugincrud.add_argument("--update", metavar=("PLUGIN", "FILE"), nargs=2, help="Update plugin")
|
||||||
plugincrud.add_argument("--del", dest="delete", metavar="PLUGIN", nargs=1, help="Delete plugin")
|
plugincrud.add_argument("--del", dest="delete", metavar="PLUGIN", nargs=1, help="Delete plugin")
|
||||||
plugincrud.add_argument("--enable", metavar="PLUGIN", nargs=1, help="Enable plugin")
|
plugincrud.add_argument("--enable", metavar="PLUGIN", nargs=1, help="Enable plugin")
|
||||||
plugincrud.add_argument("--disable", metavar="PLUGIN", nargs=1, help="Disable plugin")
|
plugincrud.add_argument("--disable", metavar="PLUGIN", nargs=1, help="Disable plugin")
|
||||||
@ -642,12 +643,41 @@ class connapp:
|
|||||||
dest_file = os.path.join(self.config.defaultdir + "/plugins", args.add[0] + ".py")
|
dest_file = os.path.join(self.config.defaultdir + "/plugins", args.add[0] + ".py")
|
||||||
shutil.copy2(args.add[1], dest_file)
|
shutil.copy2(args.add[1], dest_file)
|
||||||
print(f"Plugin {args.add[0]} added succesfully.")
|
print(f"Plugin {args.add[0]} added succesfully.")
|
||||||
except:
|
except Exception as e:
|
||||||
print("Failed importing plugin file.")
|
print(f"Failed importing plugin file. {e}")
|
||||||
exit(17)
|
exit(17)
|
||||||
else:
|
else:
|
||||||
print("Plugin name should be lowercase letters up to 15 characters.")
|
print("Plugin name should be lowercase letters up to 15 characters.")
|
||||||
exit(15)
|
exit(15)
|
||||||
|
elif args.update:
|
||||||
|
if not os.path.exists(args.update[1]):
|
||||||
|
print("File {} dosn't exists.".format(args.update[1]))
|
||||||
|
exit(14)
|
||||||
|
plugin_file = os.path.join(self.config.defaultdir + "/plugins", args.update[0] + ".py")
|
||||||
|
disabled_plugin_file = os.path.join(self.config.defaultdir + "/plugins", args.update[0] + ".py.bkp")
|
||||||
|
plugin_exist = os.path.exists(plugin_file)
|
||||||
|
disabled_plugin_exist = os.path.exists(disabled_plugin_file)
|
||||||
|
if plugin_exist or disabled_plugin_exist:
|
||||||
|
check_bad_script = self.plugins.verify_script(args.update[1])
|
||||||
|
if check_bad_script:
|
||||||
|
print(check_bad_script)
|
||||||
|
exit(16)
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
disabled_dest_file = os.path.join(self.config.defaultdir + "/plugins", args.update[0] + ".py.bkp")
|
||||||
|
dest_file = os.path.join(self.config.defaultdir + "/plugins", args.update[0] + ".py")
|
||||||
|
if disabled_plugin_exist:
|
||||||
|
shutil.copy2(args.update[1], disabled_dest_file)
|
||||||
|
else:
|
||||||
|
shutil.copy2(args.update[1], dest_file)
|
||||||
|
print(f"Plugin {args.update[0]} updated succesfully.")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Failed updating plugin file. {e}")
|
||||||
|
exit(17)
|
||||||
|
|
||||||
|
else:
|
||||||
|
print("Plugin {} dosn't exist.".format(args.update[0]))
|
||||||
|
exit(14)
|
||||||
elif args.delete:
|
elif args.delete:
|
||||||
plugin_file = os.path.join(self.config.defaultdir + "/plugins", args.delete[0] + ".py")
|
plugin_file = os.path.join(self.config.defaultdir + "/plugins", args.delete[0] + ".py")
|
||||||
disabled_plugin_file = os.path.join(self.config.defaultdir + "/plugins", args.delete[0] + ".py.bkp")
|
disabled_plugin_file = os.path.join(self.config.defaultdir + "/plugins", args.delete[0] + ".py.bkp")
|
||||||
@ -667,8 +697,8 @@ class connapp:
|
|||||||
elif disabled_plugin_exist:
|
elif disabled_plugin_exist:
|
||||||
os.remove(disabled_plugin_file)
|
os.remove(disabled_plugin_file)
|
||||||
print(f"plugin {args.delete[0]} deleted succesfully.")
|
print(f"plugin {args.delete[0]} deleted succesfully.")
|
||||||
except:
|
except Exception as e:
|
||||||
print("Failed deleting plugin file.")
|
print(f"Failed deleting plugin file. {e}")
|
||||||
exit(17)
|
exit(17)
|
||||||
elif args.disable:
|
elif args.disable:
|
||||||
plugin_file = os.path.join(self.config.defaultdir + "/plugins", args.disable[0] + ".py")
|
plugin_file = os.path.join(self.config.defaultdir + "/plugins", args.disable[0] + ".py")
|
||||||
@ -679,8 +709,8 @@ class connapp:
|
|||||||
try:
|
try:
|
||||||
os.rename(plugin_file, disabled_plugin_file)
|
os.rename(plugin_file, disabled_plugin_file)
|
||||||
print(f"plugin {args.disable[0]} disabled succesfully.")
|
print(f"plugin {args.disable[0]} disabled succesfully.")
|
||||||
except:
|
except Exception as e:
|
||||||
print("Failed disabling plugin file.")
|
print(f"Failed disabling plugin file. {e}")
|
||||||
exit(17)
|
exit(17)
|
||||||
elif args.enable:
|
elif args.enable:
|
||||||
plugin_file = os.path.join(self.config.defaultdir + "/plugins", args.enable[0] + ".py")
|
plugin_file = os.path.join(self.config.defaultdir + "/plugins", args.enable[0] + ".py")
|
||||||
@ -691,8 +721,8 @@ class connapp:
|
|||||||
try:
|
try:
|
||||||
os.rename(disabled_plugin_file, plugin_file)
|
os.rename(disabled_plugin_file, plugin_file)
|
||||||
print(f"plugin {args.enable[0]} enabled succesfully.")
|
print(f"plugin {args.enable[0]} enabled succesfully.")
|
||||||
except:
|
except Exception as e:
|
||||||
print("Failed enabling plugin file.")
|
print(f"Failed enabling plugin file. {e}")
|
||||||
exit(17)
|
exit(17)
|
||||||
elif args.list:
|
elif args.list:
|
||||||
enabled_files = []
|
enabled_files = []
|
||||||
|
@ -2261,6 +2261,7 @@ Categorize the user's request based on the operation they want to perform on
|
|||||||
pluginparser = subparsers.add_parser("plugin", description="Manage plugins")
|
pluginparser = subparsers.add_parser("plugin", description="Manage plugins")
|
||||||
plugincrud = pluginparser.add_mutually_exclusive_group(required=True)
|
plugincrud = pluginparser.add_mutually_exclusive_group(required=True)
|
||||||
plugincrud.add_argument("--add", metavar=("PLUGIN", "FILE"), nargs=2, help="Add new plugin")
|
plugincrud.add_argument("--add", metavar=("PLUGIN", "FILE"), nargs=2, help="Add new plugin")
|
||||||
|
plugincrud.add_argument("--update", metavar=("PLUGIN", "FILE"), nargs=2, help="Update plugin")
|
||||||
plugincrud.add_argument("--del", dest="delete", metavar="PLUGIN", nargs=1, help="Delete plugin")
|
plugincrud.add_argument("--del", dest="delete", metavar="PLUGIN", nargs=1, help="Delete plugin")
|
||||||
plugincrud.add_argument("--enable", metavar="PLUGIN", nargs=1, help="Enable plugin")
|
plugincrud.add_argument("--enable", metavar="PLUGIN", nargs=1, help="Enable plugin")
|
||||||
plugincrud.add_argument("--disable", metavar="PLUGIN", nargs=1, help="Disable plugin")
|
plugincrud.add_argument("--disable", metavar="PLUGIN", nargs=1, help="Disable plugin")
|
||||||
@ -2763,12 +2764,41 @@ Categorize the user's request based on the operation they want to perform on
|
|||||||
dest_file = os.path.join(self.config.defaultdir + "/plugins", args.add[0] + ".py")
|
dest_file = os.path.join(self.config.defaultdir + "/plugins", args.add[0] + ".py")
|
||||||
shutil.copy2(args.add[1], dest_file)
|
shutil.copy2(args.add[1], dest_file)
|
||||||
print(f"Plugin {args.add[0]} added succesfully.")
|
print(f"Plugin {args.add[0]} added succesfully.")
|
||||||
except:
|
except Exception as e:
|
||||||
print("Failed importing plugin file.")
|
print(f"Failed importing plugin file. {e}")
|
||||||
exit(17)
|
exit(17)
|
||||||
else:
|
else:
|
||||||
print("Plugin name should be lowercase letters up to 15 characters.")
|
print("Plugin name should be lowercase letters up to 15 characters.")
|
||||||
exit(15)
|
exit(15)
|
||||||
|
elif args.update:
|
||||||
|
if not os.path.exists(args.update[1]):
|
||||||
|
print("File {} dosn't exists.".format(args.update[1]))
|
||||||
|
exit(14)
|
||||||
|
plugin_file = os.path.join(self.config.defaultdir + "/plugins", args.update[0] + ".py")
|
||||||
|
disabled_plugin_file = os.path.join(self.config.defaultdir + "/plugins", args.update[0] + ".py.bkp")
|
||||||
|
plugin_exist = os.path.exists(plugin_file)
|
||||||
|
disabled_plugin_exist = os.path.exists(disabled_plugin_file)
|
||||||
|
if plugin_exist or disabled_plugin_exist:
|
||||||
|
check_bad_script = self.plugins.verify_script(args.update[1])
|
||||||
|
if check_bad_script:
|
||||||
|
print(check_bad_script)
|
||||||
|
exit(16)
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
disabled_dest_file = os.path.join(self.config.defaultdir + "/plugins", args.update[0] + ".py.bkp")
|
||||||
|
dest_file = os.path.join(self.config.defaultdir + "/plugins", args.update[0] + ".py")
|
||||||
|
if disabled_plugin_exist:
|
||||||
|
shutil.copy2(args.update[1], disabled_dest_file)
|
||||||
|
else:
|
||||||
|
shutil.copy2(args.update[1], dest_file)
|
||||||
|
print(f"Plugin {args.update[0]} updated succesfully.")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Failed updating plugin file. {e}")
|
||||||
|
exit(17)
|
||||||
|
|
||||||
|
else:
|
||||||
|
print("Plugin {} dosn't exist.".format(args.update[0]))
|
||||||
|
exit(14)
|
||||||
elif args.delete:
|
elif args.delete:
|
||||||
plugin_file = os.path.join(self.config.defaultdir + "/plugins", args.delete[0] + ".py")
|
plugin_file = os.path.join(self.config.defaultdir + "/plugins", args.delete[0] + ".py")
|
||||||
disabled_plugin_file = os.path.join(self.config.defaultdir + "/plugins", args.delete[0] + ".py.bkp")
|
disabled_plugin_file = os.path.join(self.config.defaultdir + "/plugins", args.delete[0] + ".py.bkp")
|
||||||
@ -2788,8 +2818,8 @@ Categorize the user's request based on the operation they want to perform on
|
|||||||
elif disabled_plugin_exist:
|
elif disabled_plugin_exist:
|
||||||
os.remove(disabled_plugin_file)
|
os.remove(disabled_plugin_file)
|
||||||
print(f"plugin {args.delete[0]} deleted succesfully.")
|
print(f"plugin {args.delete[0]} deleted succesfully.")
|
||||||
except:
|
except Exception as e:
|
||||||
print("Failed deleting plugin file.")
|
print(f"Failed deleting plugin file. {e}")
|
||||||
exit(17)
|
exit(17)
|
||||||
elif args.disable:
|
elif args.disable:
|
||||||
plugin_file = os.path.join(self.config.defaultdir + "/plugins", args.disable[0] + ".py")
|
plugin_file = os.path.join(self.config.defaultdir + "/plugins", args.disable[0] + ".py")
|
||||||
@ -2800,8 +2830,8 @@ Categorize the user's request based on the operation they want to perform on
|
|||||||
try:
|
try:
|
||||||
os.rename(plugin_file, disabled_plugin_file)
|
os.rename(plugin_file, disabled_plugin_file)
|
||||||
print(f"plugin {args.disable[0]} disabled succesfully.")
|
print(f"plugin {args.disable[0]} disabled succesfully.")
|
||||||
except:
|
except Exception as e:
|
||||||
print("Failed disabling plugin file.")
|
print(f"Failed disabling plugin file. {e}")
|
||||||
exit(17)
|
exit(17)
|
||||||
elif args.enable:
|
elif args.enable:
|
||||||
plugin_file = os.path.join(self.config.defaultdir + "/plugins", args.enable[0] + ".py")
|
plugin_file = os.path.join(self.config.defaultdir + "/plugins", args.enable[0] + ".py")
|
||||||
@ -2812,8 +2842,8 @@ Categorize the user's request based on the operation they want to perform on
|
|||||||
try:
|
try:
|
||||||
os.rename(disabled_plugin_file, plugin_file)
|
os.rename(disabled_plugin_file, plugin_file)
|
||||||
print(f"plugin {args.enable[0]} enabled succesfully.")
|
print(f"plugin {args.enable[0]} enabled succesfully.")
|
||||||
except:
|
except Exception as e:
|
||||||
print("Failed enabling plugin file.")
|
print(f"Failed enabling plugin file. {e}")
|
||||||
exit(17)
|
exit(17)
|
||||||
elif args.list:
|
elif args.list:
|
||||||
enabled_files = []
|
enabled_files = []
|
||||||
@ -3799,6 +3829,7 @@ tasks:
|
|||||||
pluginparser = subparsers.add_parser("plugin", description="Manage plugins")
|
pluginparser = subparsers.add_parser("plugin", description="Manage plugins")
|
||||||
plugincrud = pluginparser.add_mutually_exclusive_group(required=True)
|
plugincrud = pluginparser.add_mutually_exclusive_group(required=True)
|
||||||
plugincrud.add_argument("--add", metavar=("PLUGIN", "FILE"), nargs=2, help="Add new plugin")
|
plugincrud.add_argument("--add", metavar=("PLUGIN", "FILE"), nargs=2, help="Add new plugin")
|
||||||
|
plugincrud.add_argument("--update", metavar=("PLUGIN", "FILE"), nargs=2, help="Update plugin")
|
||||||
plugincrud.add_argument("--del", dest="delete", metavar="PLUGIN", nargs=1, help="Delete plugin")
|
plugincrud.add_argument("--del", dest="delete", metavar="PLUGIN", nargs=1, help="Delete plugin")
|
||||||
plugincrud.add_argument("--enable", metavar="PLUGIN", nargs=1, help="Enable plugin")
|
plugincrud.add_argument("--enable", metavar="PLUGIN", nargs=1, help="Enable plugin")
|
||||||
plugincrud.add_argument("--disable", metavar="PLUGIN", nargs=1, help="Disable plugin")
|
plugincrud.add_argument("--disable", metavar="PLUGIN", nargs=1, help="Disable plugin")
|
||||||
|
Loading…
Reference in New Issue
Block a user