-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path__init__.py
More file actions
232 lines (175 loc) · 6.46 KB
/
Copy path__init__.py
File metadata and controls
232 lines (175 loc) · 6.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# Python.py
# Import some useful modules
import importlib
# Define the main "Python" class
class Python(object):
def __init__(self):
# Define the variables of the class
self.Define_Variables()
# Define the "Python" dictionary
self.Define_Python_Dictionary()
# Update the "Modules.json" file
self.Update_Modules_File()
def Define_Variables(self):
# Import the "JSON" class
from Utility.JSON import JSON as JSON
# Instance it and add it to the current class
self.JSON = JSON()
# Import the "folders" dictionary from the "JSON" class
self.folders = self.JSON.folders
# ---------- #
# Get the dictionary of Python modules
self.modules = self.JSON.To_Python(self.folders["Python"]["Modules"]["Modules"])
# Define a list of utility classes to not import
do_not_import = [
"System"
]
# Iterate through the list of utility classes
for class_title in self.modules["Utility"]["List"]:
# If the class is not already inside the self class (Python)
if hasattr(self, class_title) == False:
# If the class title is not inside the list of utility classes to not import
# And it is is not inside the list of optional classes
if (
class_title not in do_not_import and
class_title not in self.modules["Utility"]["Optional"]
):
# Import the module of the class
module = importlib.import_module("." + class_title, "Utility")
# Get the class object inside the module
class_object = getattr(module, class_title)
# If the class title is not "Modules"
if class_title != "Modules":
# Run the class object to define its attributes
class_object = class_object()
# Add the class object to the root class
setattr(self, class_title, class_object)
# ---------- #
# Define the module dictionary and the module folders and files
self.Modules(class_object = self)
# ---------- #
# Import the switches dictionary from the "Global Switches" class
self.switches = self.Global_Switches.switches["Global"]
# ---------- #
# Define the "Language" class as the same class inside the "JSON" class
self.Language = self.JSON.Language
# Import some attributes from the "Language" class
# Import the "languages" dictionary
self.languages = self.Language.languages
# Import the "language" dictionary
self.language = self.Language.language
# Import the "separators" dictionary
self.separators = self.Language.separators
# ---------- #
# Import the "folders" dictionary from the "Folder" class
self.folders = self.Folder.folders
# ---------- #
# Get the current date from the "Date" class
self.date = self.Date.date
# ---------- #
# Define the "Texts" dictionary
self.texts = self.JSON.To_Python(self.module["Files"]["Texts"])
# Define the "Language texts" dictionary
self.language_texts = self.Language.Item(self.texts)
def Define_Python_Dictionary(self):
# Define the root "Python" dictionary
self.python = {
"Folders": {
"root": self.folders["Python"]["root"]
},
"Files": {
"Python": {}
}
}
# Define a list of folder names
folder_names = [
"Modules",
"Files",
]
# Iterate through that list
for folder_name in folder_names:
# Define and create the folder
self.python["Folders"][folder_name] = {
"root": self.python["Folders"]["root"] + folder_name + "/"
}
self.Folder.Create(self.python["Folders"][folder_name]["root"])
# Define and create the "Utility" folder
self.python["Folders"][folder_name]["Utility"] = {
"root": self.python["Folders"][folder_name]["root"] + "Utility/"
}
self.Folder.Create(self.python["Folders"][folder_name]["Utility"]["root"])
# Define the "Modules.json" file
self.python["Files"]["Modules"] = self.python["Folders"]["Modules"]["root"] + "Modules.json"
self.File.Create(self.python["Files"]["Modules"])
# Define the "Python" files folder
self.python["Folders"]["Files"]["Python"] = {
"root": self.python["Folders"]["Files"]["root"] + "Python/"
}
# Define the "Code templates" folder
self.python["Folders"]["Files"]["Python"]["Code templates"] = {
"root": self.python["Folders"]["Files"]["Python"]["root"] + "Code templates/"
}
# ---------- #
# Get the "Modules" dictionary
self.python["Modules"] = {
"Types": {
"List": [
"Utility",
"Usage"
],
"Dictionary": {}
},
"File": self.python["Files"]["Modules"],
"Dictionary": self.JSON.To_Python(self.python["Files"]["Modules"])
}
# Iterate through the module types list
for module_type in self.python["Modules"]["Types"]["List"]:
# Create the module type dictionary
module_type = {
"Name": module_type,
"Folders": {}
}
# Iterate through the list of folder names
for key in folder_names:
# Define the root folder
folder = self.python["Folders"][key]["root"]
# If the module type is "Utility"
if module_type["Name"] == "Utility":
folder = self.python["Folders"][key]["Utility"]["root"]
# Add the folder to the "Folders" dictionary
module_type["Folders"][key] = {
"root": folder
}
# Add the module type dictionary to the root dictionary
self.python["Modules"]["Types"]["Dictionary"][module_type["Name"]] = module_type
# Create a shortcut to the "Modules" dictionary
self.modules = self.python["Modules"]["Dictionary"]
# ---------- #
# Define the list of code templates
code_templates = [
"Root",
"Main class",
"Sub-class"
]
# Define the root folder
folder = self.python["Folders"]["Files"]["Python"]["Code templates"]["root"]
# Define a file for each code template
for template in code_templates:
# Define and create the file
file = folder + template + ".txt"
self.File.Create(file)
# Add it to the "Templates" dictionary
self.python["Templates"][template] = self.File.Contents(file)["string"]
def Update_Modules_File(self):
# Iterate through the module types list
for module_type in self.python["Modules"]["Types"]["Dictionary"].values():
# Get the module folders
folders = self.Folder.Contents(module_type["Folders"]["Modules"]["root"])["folder"]["names"]
# If the module is "Usage"
if module_type["Name"] == "Usage":
# Remove the "Utility" folder from the list
folders.remove("Utility")
# Update the list of modules for the current module type
self.python["Modules"]["Dictionary"][module_type["Name"]]["List"] = folders
# Update the "Modules.json" file with the updated modules list
self.JSON.Edit(self.python["Modules"]["File"], self.python["Modules"]["Dictionary"])