edco 1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
edco-1.0/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Vsevolod Romanovsky
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
edco-1.0/MANIFEST.in ADDED
@@ -0,0 +1,4 @@
1
+ include LICENSE
2
+ include README.md
3
+ graft edco/completions
4
+
edco-1.0/PKG-INFO ADDED
@@ -0,0 +1,13 @@
1
+ Metadata-Version: 2.4
2
+ Name: edco
3
+ Version: 1.0
4
+ Summary: EDCO - EDit COnfigs, make your configuration easier
5
+ Author-email: Sevaed <seva.romanovsky@gmail.com>
6
+ License: MIT
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Classifier: Operating System :: OS Independent
10
+ Requires-Python: >=3.8
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE
13
+ Dynamic: license-file
edco-1.0/README.md ADDED
File without changes
@@ -0,0 +1,2 @@
1
+ __version__ = "1.0"
2
+
@@ -0,0 +1,20 @@
1
+ from . import commands as cmd
2
+ from . import tui
3
+ from . import data
4
+ import sys
5
+
6
+ def main():
7
+ if len(sys.argv) < 2:
8
+ tui.run_tui()
9
+ elif sys.argv[1] == "--_list-names":
10
+ cmd.list_names()
11
+ else:
12
+ arg = sys.argv[1]
13
+ commands = {"-p":cmd.path, "-c":cmd.cat, "-a":cmd.add_element, "-n":cmd.names,"-h":cmd.help, "--help":cmd.help, "-d":cmd.del_smth}
14
+ if arg in commands:
15
+ commands[arg](*sys.argv[2:])
16
+ elif arg in data.get_data("data"):
17
+ cmd.edit_config(arg)
18
+ else:
19
+ cmd.name_not_found()
20
+
@@ -0,0 +1,178 @@
1
+ from edco.data import get_data
2
+
3
+ import subprocess
4
+ import os
5
+ import sys
6
+ import json
7
+
8
+ CONFIG_PATH = get_data("path")
9
+ EDITOR = str(os.environ.get("EDITOR", "nvim"))
10
+ ASCII_CODES = {
11
+ "RESET": "\033[0m",
12
+ "BOLD": "\033[1m",
13
+ "DIM": "\033[2m",
14
+ "CYAN": "\033[36m",
15
+ "YELLOW": "\033[33m",
16
+ "GREEN": "\033[32m",
17
+ }
18
+
19
+ data = get_data("data")
20
+
21
+ def list_names():
22
+ names = data.keys()
23
+ print(" ".join(names))
24
+ sys.exit(0)
25
+
26
+ def rewrite():
27
+ with open(CONFIG_PATH, "w") as config:
28
+ json.dump(data, config)
29
+
30
+
31
+ def is_enough(args, numb=0):
32
+ if len(args) >= numb:
33
+ return True
34
+ else:
35
+ help()
36
+ exit("Not enough elements")
37
+
38
+
39
+ def edit_config(*args):
40
+ is_enough(args, 1)
41
+ if args[0] not in data:
42
+ name_not_found()
43
+ else:
44
+ path = get_path(args[0])
45
+ subprocess.call([EDITOR, path])
46
+ if "command" in data[args[0]]:
47
+ subprocess.call(data[args[0]]["command"])
48
+
49
+
50
+ def name_not_found():
51
+ exit("Name not found")
52
+
53
+
54
+ def get_path(name=""):
55
+ return data[name]["path"]
56
+
57
+
58
+ def path(*args):
59
+ is_enough(args, 1)
60
+ name = args[0]
61
+ if name in data:
62
+ print(get_path(name))
63
+ else:
64
+ name_not_found()
65
+
66
+
67
+ def cat(*args):
68
+ is_enough(args, 1)
69
+ name = args[0]
70
+ with open(get_path(name), "r") as config:
71
+ print(config.read())
72
+
73
+
74
+ def add_element(*args):
75
+ is_enough(args, 2)
76
+ conf = len(args)
77
+ name = args[0]
78
+ path = args[1]
79
+ if name in data:
80
+ print("This name already taken")
81
+ exit(1)
82
+ if 2 < conf < 5:
83
+ if "=" not in args[2] or (conf > 3 and "=" not in args[3]) or conf > 4:
84
+ help()
85
+ if conf == 3:
86
+ k, v = args[2].split("=", 1)
87
+ data[name] = {"path": path, k: v}
88
+ elif conf == 4:
89
+ k, v = args[2].split("=", 1)
90
+ val3 = args[3].split("=", 1)[1]
91
+ if k == "group":
92
+ data[name] = {"path": path, "group": v, "command": val3}
93
+ else:
94
+ data[name] = {"path": path, "group": val3, "command": v}
95
+ else:
96
+ data[name] = {"path": path}
97
+ rewrite()
98
+ print(f"{path} was saved as {name}")
99
+
100
+
101
+ def del_smth(*args):
102
+ is_enough(args, 2)
103
+ if args[0] == "name" and args[1] in data:
104
+ print(data[args[1]]["path"] + " was removed")
105
+ data.pop(args[1])
106
+ rewrite()
107
+ elif args[0] == "group":
108
+ group = args[1]
109
+ to_remove = []
110
+ for i in data:
111
+ if group == data[i].get("group"):
112
+ to_remove.append(i)
113
+ print(i + " will be removed")
114
+ while True:
115
+ ask = input(f"Remove all files in group {group}? y/N")
116
+ if ask in ["y", "Y", "yes", "Yes", "YES"]:
117
+ for i in to_remove:
118
+ data.pop(i)
119
+ rewrite()
120
+ exit(0)
121
+ elif ask in ["", "n", "N", "no", "No", "NO"]:
122
+ exit(0)
123
+ else:
124
+ help()
125
+
126
+
127
+ def names(*args):
128
+ groups = {}
129
+ no_group = []
130
+ C = ASCII_CODES
131
+ COLOR_GROUP = f"{C['BOLD']}{C['CYAN']}"
132
+ COLOR_CONFIG = C["GREEN"]
133
+ COLOR_FIELD = C["DIM"]
134
+ RESET = C["RESET"]
135
+
136
+ for name, config in data.items():
137
+ group = config.get("group")
138
+ if group is None:
139
+ no_group.append((name, config))
140
+ else:
141
+ groups.setdefault(group, []).append((name, config))
142
+
143
+ for name, cfg in sorted(no_group):
144
+ print(f"{COLOR_CONFIG}• {name}{RESET}")
145
+
146
+ for group in sorted(groups):
147
+ print(f"{COLOR_GROUP}▼ {group}{RESET}")
148
+ items = groups[group]
149
+ for i, (name, cfg) in enumerate(sorted(items)):
150
+ branch = "└──" if i == len(items) - 1 else "├──"
151
+ print(f" {COLOR_CONFIG}{branch} {name}{RESET}")
152
+
153
+
154
+ def help(*args):
155
+ C = ASCII_CODES
156
+
157
+ print(f"""
158
+ {C['BOLD']}Config Manager{C['RESET']} — manage named config files with optional groups and commands
159
+
160
+ {C['BOLD']}Usage:{C['RESET']}
161
+ {C['CYAN']}config <name>{C['RESET']} {C['DIM']}Open config in $EDITOR{C['RESET']}
162
+ {C['CYAN']}config -p <name>{C['RESET']} {C['DIM']}Print path to config{C['RESET']}
163
+ {C['CYAN']}config -c <name>{C['RESET']} {C['DIM']}Print contents of config file{C['RESET']}
164
+ {C['CYAN']}config -a <name> <path>{C['RESET']} {C['DIM']}Add new config{C['RESET']}
165
+ [key=value ...] {C['DIM']}(e.g. group=shells command=\"echo done\"){C['RESET']}
166
+
167
+ {C['CYAN']}config -d name <name>{C['RESET']} {C['DIM']}Delete config by name{C['RESET']}
168
+ {C['CYAN']}config -d group <group>{C['RESET']} {C['DIM']}Delete all configs in group (with confirm){C['RESET']}
169
+
170
+ {C['CYAN']}config -n{C['RESET']} {C['DIM']}Show all configs (grouped){C['RESET']}
171
+ {C['CYAN']}config -h{C['RESET']} {C['DIM']}Show this help message{C['RESET']}
172
+
173
+ {C['BOLD']}Examples:{C['RESET']}
174
+ {C['GREEN']}config -a kitty ~/.config/kitty/kitty.conf command=\"kill -SIGUSR1 $(pgrep kitty)\"{C['RESET']}
175
+ {C['GREEN']}config fish{C['RESET']} {C['DIM']}Opens config named 'fish' in your editor{C['RESET']}
176
+ {C['GREEN']}config -d group shells{C['RESET']} {C['DIM']}Prompts before deleting all configs in 'shells'{C['RESET']}
177
+ """)
178
+ exit(0)
@@ -0,0 +1,7 @@
1
+ #compdef config
2
+ # Zsh‐completion for `config` (репозиторий reco-config-manager)
3
+
4
+ autoload -U +X bashcompinit && bashcompinit
5
+ # Подключаем Bash‐функцию из того же файла
6
+ source "${0:A:h}/config"
7
+
@@ -0,0 +1,12 @@
1
+ # Bash‐completion for `config` (репозиторий edco-config-manager)
2
+ _config_completion() {
3
+ local cur commands names
4
+ COMPREPLY=()
5
+ cur="${COMP_WORDS[COMP_CWORD]}"
6
+ commands="-p -c -a -n -h --help -d --_list-names --install-completion"
7
+ # Получаем список имён из вашего скрипта
8
+ names=$(config --_list-names 2>/dev/null)
9
+ COMPREPLY=( $(compgen -W "${commands} ${names}" -- "$cur") )
10
+ }
11
+ complete -F _config_completion config
12
+
@@ -0,0 +1,18 @@
1
+ # Fish‐completion for `config` (репозиторий edco-config-manager)
2
+
3
+ function __fish_config_list_names
4
+ # подавляем ошибки при отсутствии имени
5
+ config --_list-names ^/dev/null
6
+ end
7
+
8
+ # Опции
9
+ complete -c config -l p -d "Print path to config"
10
+ complete -c config -l c -d "Print contents of config"
11
+ complete -c config -l a -d "Add new config"
12
+ complete -c config -l n -d "Show all configs"
13
+ complete -c config -l d -d "Delete config(s)"
14
+ complete -c config -l h -d "Show help message"
15
+ complete -c config -l install-completion -d "Install shell completions"
16
+ # Автодополнение имён из JSON
17
+ complete -c config -f -a "(__fish_config_list_names)"
18
+
edco-1.0/edco/data.py ADDED
@@ -0,0 +1,22 @@
1
+ import json
2
+ import os
3
+ from typing import Union
4
+
5
+ def get_data(mode)-> Union[dict]:
6
+ path = os.path.expanduser("~/.config/EDCO.json")
7
+ if os.path.exists(path):
8
+ pass
9
+ else:
10
+ with open(path, "w") as file:
11
+ json.dump({"EDCO":{"path":path}}, file)
12
+ print("File ~/.config/EDCO.json was created.")
13
+
14
+ if mode == "data":
15
+ with open(path) as file:
16
+ data = json.load(file)
17
+ return data
18
+ elif mode == "path":
19
+ return path
20
+ else:
21
+ exit(0)
22
+
@@ -0,0 +1,9 @@
1
+ {
2
+ "include": ["reco"],
3
+ "executionEnvironments": [
4
+ {
5
+ "root": "./reco"
6
+ }
7
+ ]
8
+ }
9
+
edco-1.0/edco/tui.py ADDED
@@ -0,0 +1,148 @@
1
+ from edco.data import get_data
2
+ from edco.commands import edit_config
3
+
4
+ import curses
5
+ from curses import wrapper
6
+
7
+ def run_tui():
8
+ data = get_data("data")
9
+
10
+ def data_to_TUIdata(data={}):
11
+ groups = {}
12
+ ungroup = []
13
+ for i in data:
14
+ if "group" in data[i]:
15
+ group = data[i]["group"]
16
+ if group not in groups:
17
+ groups[group] = []
18
+ groups[group].append(i)
19
+ else:
20
+ ungroup.append(i)
21
+ groups = dict(sorted(groups.items(), key=lambda item: (-len(item[1]), item[0])))
22
+ groups["nogroup"] = ungroup
23
+ return groups
24
+
25
+ groups = data_to_TUIdata(data)
26
+
27
+ UP = [curses.KEY_UP, ord("k"), ord("w")]
28
+ DOWN = [curses.KEY_DOWN, ord("j"), ord("s")]
29
+ RIGHT = [curses.KEY_RIGHT, ord("l"), ord("d")]
30
+ LEFT = [curses.KEY_LEFT, ord("h"), ord("a")]
31
+ ENTER = [curses.KEY_ENTER, 10, 13, ord(" ")]
32
+ EXIT = [ord("q")]
33
+
34
+ def main(stdscr):
35
+ curses.curs_set(0)
36
+ curses.init_pair(1, curses.COLOR_CYAN, curses.COLOR_BLACK)
37
+ curses.init_pair(2, curses.COLOR_GREEN, curses.COLOR_BLACK)
38
+ curses.init_pair(3, curses.COLOR_MAGENTA, curses.COLOR_BLACK)
39
+ curses.init_pair(4, curses.COLOR_RED, curses.COLOR_BLACK)
40
+
41
+ current_choice = [0, 0]
42
+ blocks = []
43
+
44
+ def draw_menu():
45
+ blocks.clear()
46
+ stdscr.clear()
47
+ x = 2
48
+ maxlen = 0
49
+ for count, name in enumerate(groups.keys()):
50
+ x += maxlen
51
+ y = 2
52
+ if name != "nogroup":
53
+ stdscr.addstr(y, x, "▼ " + name, curses.color_pair(1))
54
+ col = 2
55
+ elif groups[name]:
56
+ stdscr.addstr(y, x, "▼ " + name, curses.color_pair(3))
57
+ col = 4
58
+ else:
59
+ col = 2
60
+ for counto, obj in enumerate(groups[name]):
61
+ blocks.append(([count, counto], name))
62
+ if counto != len(groups[name]) - 1:
63
+ line = "├── " + obj
64
+ else:
65
+ line = "└── " + obj
66
+ if [count, counto] == current_choice:
67
+ stdscr.addstr(y + counto + 1, x, line, curses.A_REVERSE)
68
+ else:
69
+ stdscr.addstr(y + counto + 1, x, line, curses.color_pair(col))
70
+
71
+ if len(line) > maxlen:
72
+ maxlen = len(line)
73
+
74
+ draw_menu()
75
+
76
+ while True:
77
+ key = stdscr.getch()
78
+
79
+ def name_of_position(pos):
80
+ for i in blocks:
81
+ if pos in i:
82
+ return groups[i[1]][i[0][1]]
83
+ exit(1)
84
+
85
+ name_of_current_group = ""
86
+ for i in blocks:
87
+ if current_choice == i[0]:
88
+ name_of_current_group = i[1]
89
+
90
+ def name_of_pos_group(numb):
91
+ for i in blocks:
92
+ if i[0][0] == numb:
93
+ return i[1]
94
+ exit(1)
95
+
96
+ def is_right_exist(pos):
97
+ for i in blocks:
98
+ if pos[0] + 1 == i[0][0]:
99
+ return True
100
+ return False
101
+
102
+ def is_left_exist(pos):
103
+ for i in blocks:
104
+ if pos[0] - 1 == i[0][0]:
105
+ return True
106
+ return False
107
+
108
+ def is_right_choice_exist(pos):
109
+ for i in blocks:
110
+ if [pos[0] + 1, pos[1]] in i:
111
+ return True
112
+ return False
113
+
114
+ def is_left_choice_exist(pos):
115
+ for i in blocks:
116
+ if [pos[0] - 1, pos[1]] in i:
117
+ return True
118
+ return False
119
+
120
+ if key in UP and current_choice[1] != 0:
121
+ current_choice[1] -= 1
122
+ if (
123
+ key in DOWN
124
+ and current_choice[1] != len(groups[name_of_current_group]) - 1
125
+ ):
126
+ current_choice[1] += 1
127
+ if key in RIGHT:
128
+ if is_right_choice_exist(current_choice):
129
+ current_choice[0] += 1
130
+ elif is_right_exist(current_choice):
131
+ rows = len(groups[name_of_pos_group(current_choice[0] + 1)]) - 1
132
+ current_choice = [current_choice[0] + 1, rows]
133
+ if key in LEFT:
134
+ if is_left_choice_exist(current_choice):
135
+ current_choice[0] -= 1
136
+ elif is_left_exist(current_choice):
137
+ rows = len(groups[name_of_pos_group(current_choice[0] - 1)]) - 1
138
+ current_choice = [current_choice[0] - 1, rows]
139
+ if key in ENTER:
140
+ edit_config(name_of_position(current_choice))
141
+ exit()
142
+ if key in EXIT:
143
+ exit(0)
144
+
145
+ draw_menu()
146
+
147
+ wrapper(main)
148
+
@@ -0,0 +1,13 @@
1
+ Metadata-Version: 2.4
2
+ Name: edco
3
+ Version: 1.0
4
+ Summary: EDCO - EDit COnfigs, make your configuration easier
5
+ Author-email: Sevaed <seva.romanovsky@gmail.com>
6
+ License: MIT
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Classifier: Operating System :: OS Independent
10
+ Requires-Python: >=3.8
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE
13
+ Dynamic: license-file
@@ -0,0 +1,18 @@
1
+ LICENSE
2
+ MANIFEST.in
3
+ README.md
4
+ pyproject.toml
5
+ edco/__init__.py
6
+ edco/__main__.py
7
+ edco/commands.py
8
+ edco/data.py
9
+ edco/pyrightconfig.json
10
+ edco/tui.py
11
+ edco.egg-info/PKG-INFO
12
+ edco.egg-info/SOURCES.txt
13
+ edco.egg-info/dependency_links.txt
14
+ edco.egg-info/entry_points.txt
15
+ edco.egg-info/top_level.txt
16
+ edco/completions/_config
17
+ edco/completions/config
18
+ edco/completions/config.fish
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ edco = edco.__main__:main
@@ -0,0 +1 @@
1
+ edco
@@ -0,0 +1,33 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "edco" # уникальное имя пакета в PyPI
7
+ version = "1.0"
8
+ description = "EDCO - EDit COnfigs, make your configuration easier"
9
+ readme = "README.md"
10
+ requires-python = ">=3.8"
11
+ authors = [{name="Sevaed", email="seva.romanovsky@gmail.com"}]
12
+ license = {text="MIT"}
13
+ classifiers = [
14
+ "Programming Language :: Python :: 3",
15
+ "License :: OSI Approved :: MIT License",
16
+ "Operating System :: OS Independent",
17
+ ]
18
+ dependencies = [] # перечислите ваши зависимости, если они есть
19
+
20
+ [project.scripts]
21
+ edco = "edco.__main__:main" # точка входа для `reco`
22
+
23
+ [tool.setuptools]
24
+ include-package-data = true
25
+
26
+ [tool.setuptools.packages.find]
27
+ where = ["."]
28
+ include = ["edco", "edco.*"]
29
+
30
+ [tool.setuptools.package-data]
31
+ "edco" = ["pyrightconfig.json"]
32
+ "edco.completions" = ["*"] # чтобы включить все файлы автодополнения
33
+
edco-1.0/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+