developer-assistant 0.2.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.
Files changed (25) hide show
  1. developer_assistant-0.2.0/DA/Interface.py +241 -0
  2. developer_assistant-0.2.0/DA/Modules/__init__.py +0 -0
  3. developer_assistant-0.2.0/DA/Modules/config_manager.py +126 -0
  4. developer_assistant-0.2.0/DA/Modules/opener.py +31 -0
  5. developer_assistant-0.2.0/DA/Modules/projects_manager.py +120 -0
  6. developer_assistant-0.2.0/DA/Modules/version_logic.py +315 -0
  7. developer_assistant-0.2.0/DA/Templates/changelog_template.txt +6 -0
  8. developer_assistant-0.2.0/DA/Templates/entry_template.txt +3 -0
  9. developer_assistant-0.2.0/DA/Templates/header_template.txt +1 -0
  10. developer_assistant-0.2.0/DA/__init__.py +0 -0
  11. developer_assistant-0.2.0/DA/default/Test-Project.ini +5 -0
  12. developer_assistant-0.2.0/DA/default/default-changelog.md +6 -0
  13. developer_assistant-0.2.0/DA/default/default-memory.ini +9 -0
  14. developer_assistant-0.2.0/DA/intro.md +62 -0
  15. developer_assistant-0.2.0/LICENSE +9 -0
  16. developer_assistant-0.2.0/PKG-INFO +134 -0
  17. developer_assistant-0.2.0/README.md +121 -0
  18. developer_assistant-0.2.0/developer_assistant.egg-info/PKG-INFO +134 -0
  19. developer_assistant-0.2.0/developer_assistant.egg-info/SOURCES.txt +23 -0
  20. developer_assistant-0.2.0/developer_assistant.egg-info/dependency_links.txt +1 -0
  21. developer_assistant-0.2.0/developer_assistant.egg-info/entry_points.txt +2 -0
  22. developer_assistant-0.2.0/developer_assistant.egg-info/requires.txt +4 -0
  23. developer_assistant-0.2.0/developer_assistant.egg-info/top_level.txt +1 -0
  24. developer_assistant-0.2.0/pyproject.toml +23 -0
  25. developer_assistant-0.2.0/setup.cfg +4 -0
@@ -0,0 +1,241 @@
1
+ import os, sys
2
+ import time
3
+ import platform
4
+ import subprocess
5
+ import shutil
6
+ from pathlib import Path
7
+ from termcolor import colored
8
+ from rich.progress import track
9
+ from rich.console import Console
10
+ from rich.markdown import Markdown
11
+
12
+ from DA.Modules.projects_manager import ProjectsManager
13
+ from DA.Modules.config_manager import ConfigManager
14
+ from DA.Modules.opener import Opener
15
+ from importlib import resources
16
+
17
+ class Interface:
18
+ def __init__(self, color="light_blue"):
19
+ self.version = "0.2.0"
20
+ title = f"DA - {self.version}"
21
+
22
+ if platform.system() == "Windows":
23
+ os.system(f'title {title}')
24
+ else:
25
+ print(f'\33]0;{title}\a', end='', flush=True)
26
+
27
+ self.config = ConfigManager('memory.ini')
28
+
29
+ first_run = False
30
+ if not self.config.memory_ini.exists():
31
+ self.local_init()
32
+ self.config = ConfigManager('memory.ini')
33
+ first_run = True
34
+
35
+ self.projects_manager = ProjectsManager()
36
+
37
+ self.memory = self.config.load_memory()
38
+ self.color = self.memory.get('color') or color
39
+
40
+ #==Reusables==
41
+ self.header = (colored(" Developer Assistant ", f"{self.color}"))
42
+ self.clear_screen = 'cls' if platform.system() == 'Windows' else 'clear'
43
+ self.user_path = os.environ.get('USERPROFILE') or os.environ.get('HOME', 'User')
44
+
45
+ if first_run:
46
+ self.intro()
47
+
48
+ self.load()
49
+
50
+ def load(self):
51
+ temp_log = Path(__file__).parent / "CHANGELOG.tmp"
52
+
53
+ if os.path.exists(temp_log):
54
+ while True:
55
+ os.system(self.clear_screen)
56
+ print(colored(f"Temporary changelog detected in:\n{temp_log}\n", "yellow"))
57
+ print(colored("D", "light_red") + "elete or " + colored("K", "light_red") + "eep?\n")
58
+ choice = input(f"{self.user_path}> ").lower()
59
+ if choice == "d":
60
+ os.remove(temp_log)
61
+ break
62
+ elif choice == "k":
63
+ break
64
+ else:
65
+ print(colored("\nPlease make a valid choice.", "light_red"))
66
+ time.sleep(1.5)
67
+
68
+ os.system(self.clear_screen)
69
+ message = (colored("Developer Assistant Ver. ", attrs=["bold"]) + (colored(self.version, f"{self.color}", attrs=["bold"])))
70
+ status = (colored("Loading, please wait... ", attrs=["blink"]))
71
+
72
+ print(message.center(85))
73
+ print("")
74
+ print(status.center(73))
75
+
76
+ for i in track(range(20)):
77
+ time.sleep(0.10)
78
+
79
+ self.menu()
80
+
81
+ def menu(self):
82
+ while True:
83
+ os.system(self.clear_screen)
84
+ print("Main menu")
85
+ print(self.header.center(127, "="))
86
+ print("\nE. Exit\n")
87
+ print("1. Projects")
88
+ print("2. Settings\n")
89
+
90
+ choice = input(f"{self.user_path}> ").strip()
91
+
92
+ if choice.lower() == "e":
93
+ os.system(self.clear_screen)
94
+ print(self.header.center(127, "="))
95
+ print("Bye!")
96
+ time.sleep(2)
97
+ raise SystemExit
98
+
99
+ elif choice == "1":
100
+ self.projects()
101
+
102
+ elif choice == "2":
103
+ self.settings()
104
+ else:
105
+ print("")
106
+ print(colored("Unknown option...", "light_red", attrs=["blink"]))
107
+ time.sleep(2)
108
+
109
+ def projects(self):
110
+ config = ConfigManager('memory.ini')
111
+ self.memory = config.load_memory()
112
+ while True:
113
+ os.system(self.clear_screen)
114
+ print("Main menu / Projects")
115
+ print(self.header.center(127, "="))
116
+ print("E. Back\n")
117
+ print(colored("1. The last project:", attrs=["underline"]))
118
+ print(colored(self.memory.get('last_project'), f"{self.color}"))
119
+ print("\n2. Start a new project.\n")
120
+ print(colored("Continue a project.", attrs=["underline"]))
121
+ print("Pinned:")
122
+ print("a. " + colored(self.memory.get('pinned_project'), f"{self.color}"))
123
+ print("b. " + colored(self.memory.get('pinned_project1'), f"{self.color}"))
124
+ print("c. " + colored(self.memory.get('pinned_project2'), f"{self.color}"))
125
+
126
+ print("")
127
+ choice = input(f"{self.user_path}> ").strip()
128
+
129
+ if choice.lower() == "e":
130
+ return
131
+
132
+ elif choice == "1":
133
+ project = self.memory.get('last_project')
134
+ if not project:
135
+ print(colored("\nLast project has not been defined...", "light_red", attrs=["blink"]))
136
+ time.sleep(2)
137
+ else:
138
+ self.projects_manager.load_project(f"{project}")
139
+
140
+ elif choice == "2":
141
+ self.projects_manager.new_project()
142
+
143
+ elif choice.lower() in ("a", "b", "c"):
144
+ #==If the pinned project is empty, return an error message==
145
+ options_map = {
146
+ 'a': 'pinned_project',
147
+ 'b': 'pinned_project1',
148
+ 'c': 'pinned_project2'
149
+ }
150
+ key = options_map.get(choice.lower())
151
+ project_name = self.memory.get(key)
152
+ if project_name == "":
153
+ print("")
154
+ print(colored(f"Project '{choice}' has not been defined...", "light_red", attrs=["blink"]))
155
+ time.sleep(2)
156
+ else:
157
+ project = self.memory.get(key)
158
+ self.projects_manager.load_project(f"{project}")
159
+
160
+ else:
161
+ print("")
162
+ print(colored("Unknown option...", "light_red", attrs=["blink"]))
163
+ time.sleep(2)
164
+
165
+ def settings(self):
166
+ while True:
167
+ os.system(self.clear_screen)
168
+ print("Main menu / Settings")
169
+ print(self.header.center(127, "="))
170
+ print("E. Back\n")
171
+ print(colored("Configuration options", attrs=["underline"]))
172
+ print("1. Edit pinned projects [WIP]")
173
+ print("2. Change program's color [WIP]\n")
174
+ print(colored("Other options", attrs=["underline"]))
175
+ print("3. Open memory.ini manually")
176
+ print("4. Open the Projects folder")
177
+ print("5. Open the Templates folder\n")
178
+
179
+ choice = input(f"{self.user_path}> ").strip()
180
+
181
+ if choice.lower() == "e":
182
+ return
183
+ elif choice == "1":
184
+ pass
185
+ elif choice == "2":
186
+ pass
187
+ elif choice == "3":
188
+ Opener.open(self.config.memory_ini)
189
+ elif choice == "4":
190
+ Opener.open(self.config.projects_folder)
191
+ elif choice == "5":
192
+ Opener.open(self.config.templates_folder)
193
+ else:
194
+ print("")
195
+ print(colored("Unknown option...", "light_red", attrs=["blink"]))
196
+ time.sleep(2)
197
+
198
+ def local_init(self):
199
+ default_files = resources.files("DA.default")
200
+ dest = self.config.memory_ini
201
+
202
+ for item in default_files.iterdir():
203
+ if item.name == "default-memory.ini":
204
+ shutil.copy(item, dest)
205
+
206
+ self.config.projects_folder.mkdir(parents=True, exist_ok=True)
207
+ # Add Test-Project
208
+ dest = self.config.projects_folder
209
+ for item in default_files.iterdir():
210
+ if item.name == "Test-Project.ini":
211
+ shutil.copy(item, dest)
212
+
213
+ def intro(self):
214
+ os.system(self.clear_screen)
215
+ print(colored("Welcome to the Developer Assistant\n", f"{self.color}", attrs=["bold"]))
216
+ print("Here's everything you need to get started:\n")
217
+
218
+ time.sleep(2)
219
+
220
+ readme_content = resources.files("DA").joinpath("intro.md").read_text()
221
+
222
+ MARKDOWN = readme_content
223
+ console = Console()
224
+ md = Markdown(MARKDOWN)
225
+ console.print(md)
226
+
227
+ input("\nContinue..." + colored("[Enter]", f"{self.color}"))
228
+
229
+ self.menu()
230
+
231
+ def main():
232
+ try:
233
+ app = Interface()
234
+ app.run()
235
+ except KeyboardInterrupt:
236
+ print("\n\n" + colored("Execution interrupted by the user. Exiting...", "magenta", attrs=["bold"]))
237
+ time.sleep(2)
238
+ sys.exit(0)
239
+
240
+ if __name__ == "__main__":
241
+ main()
File without changes
@@ -0,0 +1,126 @@
1
+ import configparser
2
+ from pathlib import Path
3
+ import shutil
4
+ import time
5
+
6
+ from platformdirs import user_config_path
7
+
8
+ from importlib import resources
9
+
10
+ class ConfigManager:
11
+ def __init__(self, config_file):
12
+ self.config = configparser.ConfigParser()
13
+
14
+ #==Path setup==
15
+ self.internal_dir = Path(__file__).resolve().parents[1]
16
+ self.global_dir = user_config_path("da-ui")
17
+ self.global_dir.mkdir(parents=True, exist_ok=True)
18
+
19
+ #==Specific targets==
20
+ self.memory_ini = self.global_dir / 'memory.ini'
21
+ self.projects_folder = self.global_dir / "Projects"
22
+ self.templates_folder = self.global_dir / "Templates"
23
+ self.new_project_ini = self.projects_folder / config_file
24
+
25
+ self.migrate_old_data()
26
+
27
+ #==Update last_project in memory.ini==
28
+ self.update_last_project = Path(config_file).stem
29
+
30
+ self.config.read(self.memory_ini)
31
+
32
+ def migrate_old_data(self):
33
+ old_memory = self.internal_dir / "memory.ini"
34
+ old_projects = self.internal_dir / "Projects"
35
+
36
+ if old_memory.exists() and not self.memory_ini.exists():
37
+ shutil.move(str(old_memory), str(self.memory_ini))
38
+ print(f"Migrated memory.ini to {self.global_dir}")
39
+ time.sleep(2)
40
+
41
+ if old_projects.exists() and not self.projects_folder.exists():
42
+ shutil.move(str(old_projects), str(self.projects_folder))
43
+ print(f"Migrated Projects folder to {self.global_dir}")
44
+ time.sleep(2)
45
+
46
+ if not self.templates_folder.exists():
47
+ default_templates = resources.files("DA.Templates")
48
+ user_templates = self.templates_folder
49
+
50
+ user_templates.mkdir(parents=True, exist_ok=True)
51
+
52
+ for item in default_templates.iterdir():
53
+ dest = user_templates / item.name
54
+ if not dest.exists():
55
+ shutil.copy(item, dest)
56
+
57
+ print(f"Copied default Templates to {self.global_dir}")
58
+ time.sleep(2)
59
+
60
+ def load_memory(self):
61
+ prj = self.config['ITEMS']
62
+ return {
63
+ 'last_project': prj.get('last_project'),
64
+ 'pinned_project': prj.get('pinned_project'),
65
+ 'pinned_project1': prj.get('pinned_project1'),
66
+ 'pinned_project2': prj.get('pinned_project2'),
67
+ 'color': self.config.get("CONFIG", "color")
68
+ }
69
+
70
+ def update_memory(self, category: str, variable: str, value: str):
71
+ memory_parser = configparser.ConfigParser()
72
+ memory_parser.read(self.memory_ini)
73
+
74
+ memory_parser.set(category, variable, value)
75
+ with open(self.memory_ini, "w", encoding="utf-8") as f:
76
+ memory_parser.write(f)
77
+ return
78
+
79
+ def project_ini(self):
80
+ #==Create new project ini==
81
+ project_parser = configparser.ConfigParser()
82
+ project_parser["SETTINGS"] = self.data
83
+
84
+ with open(self.new_project_ini, "w", encoding="utf-8") as f:
85
+ project_parser.write(f)
86
+
87
+ #==Update last_project in memory.ini==
88
+ memory_parser = configparser.ConfigParser()
89
+ memory_parser.read(self.memory_ini)
90
+
91
+ memory_parser.set("ITEMS", "last_project", self.update_last_project)
92
+ with open(self.memory_ini, "w", encoding="utf-8") as f:
93
+ memory_parser.write(f)
94
+ return
95
+
96
+ def load_project(self):
97
+ #==Return project ini variables==
98
+ project_parser = configparser.ConfigParser()
99
+ project_parser.read(self.new_project_ini)
100
+ '''
101
+ try:
102
+ prj = project_parser['SETTINGS']
103
+ except KeyError:
104
+ print(f"\nCan't find {self.new_project_ini}")
105
+ time.sleep(2)
106
+ return
107
+ '''
108
+ prj = project_parser['SETTINGS']
109
+ return {
110
+ 'path': prj.get('path'),
111
+ 'changelog': prj.get('changelog'),
112
+ 'version': prj.get('version'),
113
+ 'cloud': prj.get('cloud')
114
+ }
115
+
116
+ def update_project(self, variable: str, value: str):
117
+ project_parser = configparser.ConfigParser()
118
+ project_parser.read(self.new_project_ini)
119
+
120
+ project_parser.set("SETTINGS", variable, value)
121
+ with open(self.new_project_ini, "w", encoding="utf-8") as f:
122
+ project_parser.write(f)
123
+ return
124
+
125
+ if __name__ == "__main__":
126
+ ConfigManager()
@@ -0,0 +1,31 @@
1
+ from termcolor import colored
2
+ import subprocess
3
+ import platform
4
+ import os
5
+ import time
6
+
7
+ class Opener:
8
+ @staticmethod
9
+ def open(path):
10
+ #==Check if path exists==
11
+ if not os.path.exists(path):
12
+ print(colored("\nThis path does not exist.", "light_red"))
13
+ time.sleep(1.5)
14
+ return
15
+ #==Open if exists==
16
+ else:
17
+ system = platform.system()
18
+ if system == "Windows":
19
+ subprocess.Popen(['explorer', path])
20
+ elif system == "Darwin":
21
+ subprocess.Popen(['open', path])
22
+ else:
23
+ subprocess.Popen(
24
+ ['xdg-open', path],
25
+ stdout=subprocess.DEVNULL,
26
+ stderr=subprocess.DEVNULL
27
+ )
28
+ return
29
+
30
+ if __name__ == "__main__":
31
+ Opener()
@@ -0,0 +1,120 @@
1
+ import os, sys
2
+ import time
3
+ from termcolor import colored
4
+ import subprocess
5
+ import platform
6
+ from pathlib import Path
7
+
8
+ from DA.Modules.config_manager import ConfigManager
9
+ from DA.Modules.version_logic import VersionLogic
10
+ from DA.Modules.opener import Opener
11
+
12
+ class ProjectsManager:
13
+ def __init__(self, color="light_blue"):
14
+ os.system('title Developer Assistant')
15
+ self.version = "1.0.0-alpha"
16
+
17
+ self.config = ConfigManager('memory.ini')
18
+ self.memory = self.config.load_memory()
19
+ self.color = self.memory.get('color') or color
20
+
21
+ #==Reusables==
22
+ self.header = (colored(" Developer Assistant ", f"{self.color}"))
23
+ self.clear_screen = 'cls' if platform.system() == 'Windows' else 'clear'
24
+ self.user_path = os.environ.get('USERPROFILE') or os.environ.get('HOME', 'User')
25
+
26
+ def new_project(self):
27
+ os.system(self.clear_screen)
28
+ print(self.header.center(127, "="))
29
+ print("E. Abort/back\n")
30
+
31
+ name = input("Enter new project name: ")
32
+ if name.lower() == "e":
33
+ return
34
+
35
+ print("")
36
+ path = input("Enter project path: ")
37
+
38
+ print("")
39
+ changelog = input("Project changelog path: ")
40
+
41
+ print("")
42
+ version = input("Current project version: ")
43
+
44
+ print("")
45
+ cloud = input("Cloud service (OneDrive/Azure/Dropbox/Google Drive): ")
46
+
47
+ print("")
48
+ confirm = input("Confirm(Y) or abort(E): ")
49
+ if confirm.lower() == "e":
50
+ return
51
+
52
+ elif confirm.lower() == "y":
53
+ self.new_manager = ConfigManager(f"{name}.ini")
54
+ self.new_manager.data = {
55
+ "path": path,
56
+ "changelog": changelog,
57
+ "version": version,
58
+ "cloud": cloud
59
+ }
60
+ self.new_manager.project_ini()
61
+
62
+ return
63
+
64
+ else:
65
+ print("")
66
+ print(colored("Unknown option, try again...", "light_red", attrs=["blink"]))
67
+ time.sleep(2)
68
+ return
69
+
70
+ def load_project(self, project):
71
+ while True:
72
+ chosen_project = f"{project}"
73
+ self.load_manager = ConfigManager(f"{project}.ini")
74
+ try:
75
+ self.setting = self.load_manager.load_project()
76
+ except KeyError:
77
+ print(colored(f"\nCan't find {chosen_project}.ini", "light_red"))
78
+ time.sleep(2)
79
+ return
80
+
81
+ self.version_logic = VersionLogic()
82
+
83
+ project_ini_path = self.load_manager.projects_folder / f"{chosen_project}.ini"
84
+
85
+ os.system(self.clear_screen)
86
+ print("Main menu / Projects / Project menu")
87
+ print(self.header.center(127, "="))
88
+ print("E. Back\n")
89
+ print(colored("Chosen project:", attrs=["underline"]))
90
+ print(colored(chosen_project, f"{self.color}"))
91
+ print("\n1. Open project folder.")
92
+ print("2. Update the changelog.")
93
+ print("3. Backup to the cloud. [WIP]")
94
+ print("4. Open project configurations.\n")
95
+
96
+ choice = input(f"{self.user_path}> ").strip()
97
+
98
+ if choice.lower() == "e":
99
+ return
100
+
101
+ elif choice == "1":
102
+ path = self.setting.get('path')
103
+ folder = Path(path)
104
+ Opener.open(folder)
105
+
106
+ elif choice == "2":
107
+ self.version_logic.project_menu(chosen_project)
108
+
109
+ # elif choice == "3":
110
+
111
+ elif choice == "4":
112
+ Opener.open(project_ini_path)
113
+
114
+ else:
115
+ print("")
116
+ print(colored("Unknown option...", "light_red", attrs=["blink"]))
117
+ time.sleep(2)
118
+
119
+ if __name__ == "__main__":
120
+ ProjectsManager()