Skip to content

Commit d6cb645

Browse files
memory usage improvements!
1 parent 9dd7ebd commit d6cb645

14 files changed

Lines changed: 496 additions & 605 deletions

__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ def _up(path: str) -> str:
5555
from pmma.python_src.events import *
5656
from pmma.python_src.error import *
5757
from pmma.python_src.noise import *
58-
from pmma.python_src.image import *
5958
from pmma.python_src.audio import *
6059
from pmma.python_src.video import *
6160
from pmma.python_src.shapes import *

python_src/events.py

Lines changed: 310 additions & 310 deletions
Large diffs are not rendered by default.

python_src/executor.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
import subprocess as _subprocess
2-
import threading as _threading
1+
from subprocess import run as _subprocess__run
2+
from subprocess import CalledProcessError as _subprocess__CalledProcessError
3+
from subprocess import Popen as _subprocess__Popen
4+
from subprocess import PIPE as _subprocess__PIPE
5+
from threading import Thread as _threading__Thread
36

47
from pmma.python_src.constants import Constants as _Constants
58
from pmma.python_src.general import get_operating_system as _get_operating_system
@@ -36,7 +39,7 @@ def run(self, command, blocking=True, hide_window=True):
3639
self._exit_code = None
3740
self._result = None
3841

39-
self._thread = _threading.Thread(target=self._run, args=(command, hide_window,))
42+
self._thread = _threading__Thread(target=self._run, args=(command, hide_window,))
4043
self._thread.name = "Executor:Execution_Thread"
4144
if blocking is False:
4245
self._thread.daemon = True
@@ -54,9 +57,9 @@ def _run(self, command, hide_window):
5457
try:
5558
if command_type == list or command_type == tuple:
5659
if hide_window and _get_operating_system() == _Constants.WINDOWS:
57-
result = _subprocess.run(command, capture_output=True, text=True, creationflags=_Constants.CREATE_NO_WINDOW)
60+
result = _subprocess__run(command, capture_output=True, text=True, creationflags=_Constants.CREATE_NO_WINDOW)
5861
else:
59-
result = _subprocess.run(command, capture_output=True, text=True)
62+
result = _subprocess__run(command, capture_output=True, text=True)
6063
else:
6164
self._logger.log_development("You are not using an array of arguments as your command. \
6265
This has the potential to be less secure, especially when using the user's input as a \
@@ -65,13 +68,13 @@ def _run(self, command, hide_window):
6568
its arguments, leading to unsecure commands being run on the host system!")
6669

6770
if hide_window and _get_operating_system() == _Constants.WINDOWS:
68-
result = _subprocess.run(command, shell=True, capture_output=True, text=True, creationflags=_Constants.CREATE_NO_WINDOW)
71+
result = _subprocess__run(command, shell=True, capture_output=True, text=True, creationflags=_Constants.CREATE_NO_WINDOW)
6972
else:
70-
result = _subprocess.run(command, shell=True, capture_output=True, text=True)
73+
result = _subprocess__run(command, shell=True, capture_output=True, text=True)
7174

7275
self._result = result.stdout
7376
self._exit_code = result.returncode
74-
except _subprocess.CalledProcessError as result:
77+
except _subprocess__CalledProcessError as result:
7578
self._result = result.output
7679
self._exit_code = result.returncode
7780

@@ -124,7 +127,7 @@ def run(self, command, hide_window=True):
124127
self._exit_code = None
125128
self._result = ""
126129

127-
self._thread = _threading.Thread(target=self._update_result, args=(command, hide_window,))
130+
self._thread = _threading__Thread(target=self._update_result, args=(command, hide_window,))
128131
self._thread.daemon = True
129132
self._thread.name = "AdvancedExecutor:Execution_Thread"
130133
self._thread.start()
@@ -156,9 +159,9 @@ def _run(self, command, hide_window):
156159
command_type = type(command)
157160
if command_type == list or command_type == tuple:
158161
if hide_window and _get_operating_system() == _Constants.WINDOWS:
159-
process = _subprocess.Popen(command, stdout=_subprocess.PIPE, text=True, creationflags=_Constants.CREATE_NO_WINDOW)
162+
process = _subprocess__Popen(command, stdout=_subprocess__PIPE, text=True, creationflags=_Constants.CREATE_NO_WINDOW)
160163
else:
161-
process = _subprocess.Popen(command, stdout=_subprocess.PIPE, text=True)
164+
process = _subprocess__Popen(command, stdout=_subprocess__PIPE, text=True)
162165
else:
163166
self._logger.log_development("You are not using an array of arguments as your command. \
164167
This has the potential to be less secure, especially when using the user's input as a \
@@ -167,9 +170,9 @@ def _run(self, command, hide_window):
167170
its arguments, leading to unsecure commands being run on the host system!")
168171

169172
if hide_window and _get_operating_system() == _Constants.WINDOWS:
170-
process = _subprocess.Popen(command, stdout=_subprocess.PIPE, shell=True, text=True, creationflags=_Constants.CREATE_NO_WINDOW)
173+
process = _subprocess__Popen(command, stdout=_subprocess__PIPE, shell=True, text=True, creationflags=_Constants.CREATE_NO_WINDOW)
171174
else:
172-
process = _subprocess.Popen(command, stdout=_subprocess.PIPE, shell=True, text=True)
175+
process = _subprocess__Popen(command, stdout=_subprocess__PIPE, shell=True, text=True)
173176

174177
result = ""
175178
while True:

python_src/file.py

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
import os as _os
2-
import shutil as _shutil
1+
from os import path as _os__path
2+
from os import mkdir as _os__mkdir
3+
from os import remove as _os__remove
4+
from os import rename as _os__rename
5+
from os import walk as _os__walk
6+
from os import sep as _os__sep
7+
from shutil import move as _shutil__move
38

4-
import send2trash as _send2trash
9+
from send2trash import send2trash as _send2trash__send2trash
510

611
from pmma.python_src.constants import Constants as _Constants
712

@@ -16,8 +21,8 @@ def path_builder(*args):
1621
"""
1722
result = ""
1823
for arg in args:
19-
if result != "" and _os.path.exists(result) is False:
20-
_os.mkdir(result)
24+
if result != "" and _os__path.exists(result) is False:
25+
_os__mkdir(result)
2126

2227
result += arg
2328
result += _Constants.PATH_SEPARATOR
@@ -46,7 +51,7 @@ def exists(self):
4651
"""
4752
🟩 **R** -
4853
"""
49-
return _os.path.exists(self._file_path)
54+
return _os__path.exists(self._file_path)
5055

5156
def get_path(self):
5257
"""
@@ -58,7 +63,7 @@ def get_directory(self):
5863
"""
5964
🟩 **R** -
6065
"""
61-
return _os.path.dirname(self._file_path)
66+
return _os__path.dirname(self._file_path)
6267

6368
def get_file_name_and_type(self):
6469
"""
@@ -82,28 +87,28 @@ def move(self, new_path):
8287
"""
8388
🟩 **R** -
8489
"""
85-
_shutil.move(self._file_path, new_path)
90+
_shutil__move(self._file_path, new_path)
8691
self._file_path = new_path
8792

8893
def delete(self):
8994
"""
9095
🟩 **R** -
9196
"""
92-
_os.remove(self._file_path)
97+
_os__remove(self._file_path)
9398

9499
def recycle(self):
95100
"""
96101
🟩 **R** -
97102
"""
98-
_send2trash.send2trash(self._file_path)
103+
_send2trash__send2trash(self._file_path)
99104

100105
def rename(self, new_name):
101106
"""
102107
🟩 **R** -
103108
"""
104109
file_type = self.get_file_type()
105-
new_file_path = _os.path.dirname(self._file_path) + _Constants.PATH_SEPARATOR + new_name + "." + file_type
106-
_os.rename(self._file_path, new_file_path)
110+
new_file_path = _os__path.dirname(self._file_path) + _Constants.PATH_SEPARATOR + new_name + "." + file_type
111+
_os__rename(self._file_path, new_file_path)
107112
self._file_path = new_file_path
108113

109114
def read(self):
@@ -185,9 +190,9 @@ def scan(self):
185190
self._file_matrix = {}
186191
construction_matrix = {}
187192
for location in self._locations:
188-
for root, subdirs, files in _os.walk(location):
193+
for root, subdirs, files in _os__walk(location):
189194
for file in files:
190-
file_path = _os.path.join(root, file)
195+
file_path = _os__path.join(root, file)
191196
if file not in construction_matrix:
192197
construction_matrix[file] = File(file_path)
193198
else: # duplicate name resolver
@@ -196,8 +201,8 @@ def scan(self):
196201

197202
new_file = file_path
198203

199-
original_file_split = original_file.split(_os.sep)
200-
new_file_split = new_file.split(_os.sep)
204+
original_file_split = original_file.split(_os__sep)
205+
new_file_split = new_file.split(_os__sep)
201206

202207
original_identifier = original_file_split[-1]
203208
new_identifier = new_file_split[-1]
@@ -206,8 +211,8 @@ def scan(self):
206211
del new_file_split[-1]
207212

208213
while original_identifier == new_identifier:
209-
original_identifier = original_file_split[-1] + _os.sep + original_identifier
210-
new_identifier = new_file_split[-1] + _os.sep + new_identifier
214+
original_identifier = original_file_split[-1] + _os__sep + original_identifier
215+
new_identifier = new_file_split[-1] + _os__sep + new_identifier
211216

212217
del original_file_split[-1]
213218
del new_file_split[-1]

0 commit comments

Comments
 (0)