Add more export functionalities
This commit is contained in:
parent
7856dcb9a3
commit
0813b927b0
@ -1,2 +1,2 @@
|
|||||||
__version__ = "3.4.2"
|
__version__ = "3.4.3"
|
||||||
|
|
||||||
|
@ -66,14 +66,14 @@ def main():
|
|||||||
strings=["profile"]
|
strings=["profile"]
|
||||||
if words[0] in ["list", "ls"]:
|
if words[0] in ["list", "ls"]:
|
||||||
strings=["profiles", "nodes", "folders"]
|
strings=["profiles", "nodes", "folders"]
|
||||||
if words[0] in ["bulk", "mv", "cp", "copy", "export"]:
|
if words[0] in ["bulk", "mv", "cp", "copy"]:
|
||||||
strings=["--help"]
|
strings=["--help"]
|
||||||
if words[0] in ["--rm", "--del", "-r", "export"]:
|
if words[0] in ["--rm", "--del", "-r"]:
|
||||||
strings.extend(folders)
|
strings.extend(folders)
|
||||||
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] in ["run", "import"]:
|
if words[0] in ["run", "import", "export"]:
|
||||||
if words[-1] in ["run", "import"]:
|
if words[-1] in ["run", "import", "export"]:
|
||||||
path = './*'
|
path = './*'
|
||||||
else:
|
else:
|
||||||
path = words[-1] + "*"
|
path = words[-1] + "*"
|
||||||
@ -83,10 +83,15 @@ def main():
|
|||||||
pathstrings[i] += '/'
|
pathstrings[i] += '/'
|
||||||
strings = ["--help"]
|
strings = ["--help"]
|
||||||
pathstrings = [s[2:] if s.startswith('./') else s for s in pathstrings]
|
pathstrings = [s[2:] if s.startswith('./') else s for s in pathstrings]
|
||||||
|
if words[0] == "export":
|
||||||
|
pathstrings = [s for s in pathstrings if os.path.isdir(s)]
|
||||||
strings.extend(pathstrings)
|
strings.extend(pathstrings)
|
||||||
if words[0] == "run":
|
if words[0] == "run":
|
||||||
strings.extend(nodes)
|
strings.extend(nodes)
|
||||||
|
|
||||||
|
elif wordsnumber >= 4 and words[0] == "export" and words[1] != "--help":
|
||||||
|
strings = [item for item in folders if not any(word in item for word in words[:-1])]
|
||||||
|
|
||||||
elif wordsnumber == 4:
|
elif wordsnumber == 4:
|
||||||
strings=[]
|
strings=[]
|
||||||
if words[0] == "profile" and words[1] in ["--rm", "--del", "-r", "--mod", "--edit", "-e", "--show", "-s"]:
|
if words[0] == "profile" and words[1] in ["--rm", "--del", "-r", "--mod", "--edit", "-e", "--show", "-s"]:
|
||||||
@ -98,6 +103,7 @@ 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 app == "bash":
|
if app == "bash":
|
||||||
strings = [s if s.endswith('/') else f"'{s} '" for s in strings]
|
strings = [s if s.endswith('/') else f"'{s} '" for s in strings]
|
||||||
print('\t'.join(strings))
|
print('\t'.join(strings))
|
||||||
|
@ -320,8 +320,10 @@ class configfile:
|
|||||||
nodes.update(layer3)
|
nodes.update(layer3)
|
||||||
if filter:
|
if filter:
|
||||||
if isinstance(filter, str):
|
if isinstance(filter, str):
|
||||||
|
filter = "^(?!.*@).+$" if filter == "@" else filter
|
||||||
nodes = {k: v for k, v in nodes.items() if re.search(filter, k)}
|
nodes = {k: v for k, v in nodes.items() if re.search(filter, k)}
|
||||||
elif isinstance(filter, list):
|
elif isinstance(filter, list):
|
||||||
|
filter = ["^(?!.*@).+$" if item == "@" else item for item in filter]
|
||||||
nodes = {k: v for k, v in nodes.items() if any(re.search(pattern, k) for pattern in filter)}
|
nodes = {k: v for k, v in nodes.items() if any(re.search(pattern, k) for pattern in filter)}
|
||||||
else:
|
else:
|
||||||
raise ValueError("filter must be a string or a list of strings")
|
raise ValueError("filter must be a string or a list of strings")
|
||||||
|
@ -107,7 +107,7 @@ class connapp:
|
|||||||
bulkparser.set_defaults(func=self._func_others)
|
bulkparser.set_defaults(func=self._func_others)
|
||||||
# EXPORTPARSER
|
# EXPORTPARSER
|
||||||
exportparser = subparsers.add_parser("export", help="Export connection folder to Yaml file")
|
exportparser = subparsers.add_parser("export", help="Export connection folder to Yaml file")
|
||||||
exportparser.add_argument("export", nargs=2, action=self._store_type, help="Export [@subfolder]@folder /path/to/file.yml")
|
exportparser.add_argument("export", nargs="+", action=self._store_type, help="Export /path/to/file.yml [@subfolder1][@folder1] [@subfolderN][@folderN]")
|
||||||
exportparser.set_defaults(func=self._func_export)
|
exportparser.set_defaults(func=self._func_export)
|
||||||
# IMPORTPARSER
|
# IMPORTPARSER
|
||||||
importparser = subparsers.add_parser("import", help="Import connection folder to config from Yaml file")
|
importparser = subparsers.add_parser("import", help="Import connection folder to config from Yaml file")
|
||||||
@ -583,6 +583,7 @@ class connapp:
|
|||||||
exit(10)
|
exit(10)
|
||||||
for k,v in imported.items():
|
for k,v in imported.items():
|
||||||
uniques = self.config._explode_unique(k)
|
uniques = self.config._explode_unique(k)
|
||||||
|
if "folder" in uniques:
|
||||||
folder = f"@{uniques['folder']}"
|
folder = f"@{uniques['folder']}"
|
||||||
matches = list(filter(lambda k: k == folder, self.folders))
|
matches = list(filter(lambda k: k == folder, self.folders))
|
||||||
if len(matches) == 0:
|
if len(matches) == 0:
|
||||||
@ -601,19 +602,22 @@ class connapp:
|
|||||||
return
|
return
|
||||||
|
|
||||||
def _func_export(self, args):
|
def _func_export(self, args):
|
||||||
matches = list(filter(lambda k: k == args.data[0], self.folders))
|
if os.path.exists(args.data[0]):
|
||||||
if len(matches) == 0:
|
print("File {} already exists".format(args.data[0]))
|
||||||
print("{} folder not found".format(args.data[0]))
|
|
||||||
exit(2)
|
|
||||||
if os.path.exists(args.data[1]):
|
|
||||||
print("File {} already exists".format(args.data[1]))
|
|
||||||
exit(14)
|
exit(14)
|
||||||
|
if len(args.data[1:]) == 0:
|
||||||
|
foldercons = self.config._getallnodesfull(extract = False)
|
||||||
else:
|
else:
|
||||||
foldercons = self.config._getallnodesfull(args.data[0], extract = False)
|
for folder in args.data[1:]:
|
||||||
with open(args.data[1], "w") as file:
|
matches = list(filter(lambda k: k == folder, self.folders))
|
||||||
|
if len(matches) == 0 and folder != "@":
|
||||||
|
print("{} folder not found".format(folder))
|
||||||
|
exit(2)
|
||||||
|
foldercons = self.config._getallnodesfull(args.data[1:], extract = False)
|
||||||
|
with open(args.data[0], "w") as file:
|
||||||
yaml.dump(foldercons, file, Dumper=NoAliasDumper, default_flow_style=False)
|
yaml.dump(foldercons, file, Dumper=NoAliasDumper, default_flow_style=False)
|
||||||
file.close()
|
file.close()
|
||||||
print("File {} generated succesfully".format(args.data[1]))
|
print("File {} generated succesfully".format(args.data[0]))
|
||||||
exit()
|
exit()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -1614,8 +1614,10 @@ Categorize the user's request based on the operation they want to perform on
|
|||||||
nodes.update(layer3)
|
nodes.update(layer3)
|
||||||
if filter:
|
if filter:
|
||||||
if isinstance(filter, str):
|
if isinstance(filter, str):
|
||||||
|
filter = "^(?!.*@).+$" if filter == "@" else filter
|
||||||
nodes = {k: v for k, v in nodes.items() if re.search(filter, k)}
|
nodes = {k: v for k, v in nodes.items() if re.search(filter, k)}
|
||||||
elif isinstance(filter, list):
|
elif isinstance(filter, list):
|
||||||
|
filter = ["^(?!.*@).+$" if item == "@" else item for item in filter]
|
||||||
nodes = {k: v for k, v in nodes.items() if any(re.search(pattern, k) for pattern in filter)}
|
nodes = {k: v for k, v in nodes.items() if any(re.search(pattern, k) for pattern in filter)}
|
||||||
else:
|
else:
|
||||||
raise ValueError("filter must be a string or a list of strings")
|
raise ValueError("filter must be a string or a list of strings")
|
||||||
@ -1894,7 +1896,7 @@ Categorize the user's request based on the operation they want to perform on
|
|||||||
bulkparser.set_defaults(func=self._func_others)
|
bulkparser.set_defaults(func=self._func_others)
|
||||||
# EXPORTPARSER
|
# EXPORTPARSER
|
||||||
exportparser = subparsers.add_parser("export", help="Export connection folder to Yaml file")
|
exportparser = subparsers.add_parser("export", help="Export connection folder to Yaml file")
|
||||||
exportparser.add_argument("export", nargs=2, action=self._store_type, help="Export [@subfolder]@folder /path/to/file.yml")
|
exportparser.add_argument("export", nargs="+", action=self._store_type, help="Export /path/to/file.yml [@subfolder1][@folder1] [@subfolderN][@folderN]")
|
||||||
exportparser.set_defaults(func=self._func_export)
|
exportparser.set_defaults(func=self._func_export)
|
||||||
# IMPORTPARSER
|
# IMPORTPARSER
|
||||||
importparser = subparsers.add_parser("import", help="Import connection folder to config from Yaml file")
|
importparser = subparsers.add_parser("import", help="Import connection folder to config from Yaml file")
|
||||||
@ -2370,6 +2372,7 @@ Categorize the user's request based on the operation they want to perform on
|
|||||||
exit(10)
|
exit(10)
|
||||||
for k,v in imported.items():
|
for k,v in imported.items():
|
||||||
uniques = self.config._explode_unique(k)
|
uniques = self.config._explode_unique(k)
|
||||||
|
if "folder" in uniques:
|
||||||
folder = f"@{uniques['folder']}"
|
folder = f"@{uniques['folder']}"
|
||||||
matches = list(filter(lambda k: k == folder, self.folders))
|
matches = list(filter(lambda k: k == folder, self.folders))
|
||||||
if len(matches) == 0:
|
if len(matches) == 0:
|
||||||
@ -2388,19 +2391,22 @@ Categorize the user's request based on the operation they want to perform on
|
|||||||
return
|
return
|
||||||
|
|
||||||
def _func_export(self, args):
|
def _func_export(self, args):
|
||||||
matches = list(filter(lambda k: k == args.data[0], self.folders))
|
if os.path.exists(args.data[0]):
|
||||||
if len(matches) == 0:
|
print("File {} already exists".format(args.data[0]))
|
||||||
print("{} folder not found".format(args.data[0]))
|
|
||||||
exit(2)
|
|
||||||
if os.path.exists(args.data[1]):
|
|
||||||
print("File {} already exists".format(args.data[1]))
|
|
||||||
exit(14)
|
exit(14)
|
||||||
|
if len(args.data[1:]) == 0:
|
||||||
|
foldercons = self.config._getallnodesfull(extract = False)
|
||||||
else:
|
else:
|
||||||
foldercons = self.config._getallnodesfull(args.data[0], extract = False)
|
for folder in args.data[1:]:
|
||||||
with open(args.data[1], "w") as file:
|
matches = list(filter(lambda k: k == folder, self.folders))
|
||||||
|
if len(matches) == 0 and folder != "@":
|
||||||
|
print("{} folder not found".format(folder))
|
||||||
|
exit(2)
|
||||||
|
foldercons = self.config._getallnodesfull(args.data[1:], extract = False)
|
||||||
|
with open(args.data[0], "w") as file:
|
||||||
yaml.dump(foldercons, file, Dumper=NoAliasDumper, default_flow_style=False)
|
yaml.dump(foldercons, file, Dumper=NoAliasDumper, default_flow_style=False)
|
||||||
file.close()
|
file.close()
|
||||||
print("File {} generated succesfully".format(args.data[1]))
|
print("File {} generated succesfully".format(args.data[0]))
|
||||||
exit()
|
exit()
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -3147,7 +3153,7 @@ tasks:
|
|||||||
</details>
|
</details>
|
||||||
</dd>
|
</dd>
|
||||||
<dt id="connpy.connapp.start"><code class="name flex">
|
<dt id="connpy.connapp.start"><code class="name flex">
|
||||||
<span>def <span class="ident">start</span></span>(<span>self, argv=['connpy', '-o', 'docs/', '--force', '--html'])</span>
|
<span>def <span class="ident">start</span></span>(<span>self, argv=['connpy', '--html', '-o', 'docs/', '-f'])</span>
|
||||||
</code></dt>
|
</code></dt>
|
||||||
<dd>
|
<dd>
|
||||||
<div class="desc"><h3 id="parameters">Parameters:</h3>
|
<div class="desc"><h3 id="parameters">Parameters:</h3>
|
||||||
@ -3208,7 +3214,7 @@ tasks:
|
|||||||
bulkparser.set_defaults(func=self._func_others)
|
bulkparser.set_defaults(func=self._func_others)
|
||||||
# EXPORTPARSER
|
# EXPORTPARSER
|
||||||
exportparser = subparsers.add_parser("export", help="Export connection folder to Yaml file")
|
exportparser = subparsers.add_parser("export", help="Export connection folder to Yaml file")
|
||||||
exportparser.add_argument("export", nargs=2, action=self._store_type, help="Export [@subfolder]@folder /path/to/file.yml")
|
exportparser.add_argument("export", nargs="+", action=self._store_type, help="Export /path/to/file.yml [@subfolder1][@folder1] [@subfolderN][@folderN]")
|
||||||
exportparser.set_defaults(func=self._func_export)
|
exportparser.set_defaults(func=self._func_export)
|
||||||
# IMPORTPARSER
|
# IMPORTPARSER
|
||||||
importparser = subparsers.add_parser("import", help="Import connection folder to config from Yaml file")
|
importparser = subparsers.add_parser("import", help="Import connection folder to config from Yaml file")
|
||||||
|
Loading…
Reference in New Issue
Block a user