Skip to content

Commit 6f3c8fc

Browse files
committed
bugfixes, changed config.ini structure ,naming of functions
1 parent 13e40e7 commit 6f3c8fc

6 files changed

Lines changed: 46 additions & 34 deletions

File tree

config.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[Settings]
2-
SEARCH_PATHS = C:\Users\Wreck\Downloads\,I:\Downloads,J:\Downloads
3-
EXTRACTABLE_EXTENSIONS = zip|rar
2+
SEARCH_PATHS = C:\Users\Wreck\Downloads\,I:\Downloads,J:\Downloads,G:\testfolder
3+
EXTRACTABLE_EXTENSIONS = zip, rar, 7z, tar, gz, bzip2, iso, img, dmg
44
DAYS_UNTIL_DELETION = 14
55
START_WITH_WINDOWS = true
66
MAX_LOG_SIZE_MB = 2

wfc/config.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
ENCODING = "utf-8"
99

1010

11-
def get_config_values() -> Tuple[list[str], str, int, bool, int]:
11+
def _get_config_values() -> Tuple[list[str], str, int, bool, int]:
1212
if not os.path.exists(paths.CONFIG_PATH):
1313
logger.log(
1414
logger.ERROR,
@@ -19,10 +19,20 @@ def get_config_values() -> Tuple[list[str], str, int, bool, int]:
1919
config = configparser.ConfigParser()
2020
config.read(paths.CONFIG_PATH, encoding=ENCODING)
2121

22-
search_paths = config[SECTION_NAME]["SEARCH_PATHS"].split(",")
23-
extractable_extensions = config[SECTION_NAME]["EXTRACTABLE_EXTENSIONS"]
22+
search_paths = (
23+
config[SECTION_NAME]["SEARCH_PATHS"]
24+
.replace(" ", "")
25+
.removesuffix(",")
26+
.split(",")
27+
)
28+
extractable_extensions = (
29+
config[SECTION_NAME]["EXTRACTABLE_EXTENSIONS"]
30+
.replace(" ", "")
31+
.removesuffix(",")
32+
.replace(",", "|")
33+
)
2434
days_until_deletion = int(config[SECTION_NAME]["DAYS_UNTIL_DELETION"])
25-
start_with_windows = bool(config[SECTION_NAME]["START_WITH_WINDOWS"])
35+
start_with_windows = config[SECTION_NAME]["START_WITH_WINDOWS"].lower() == "true"
2636
max_log_size_mb = int(config[SECTION_NAME]["MAX_LOG_SIZE_MB"])
2737

2838
return (
@@ -34,4 +44,4 @@ def get_config_values() -> Tuple[list[str], str, int, bool, int]:
3444
)
3545

3646

37-
data = get_config_values()
47+
data = _get_config_values()

wfc/file.py

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
TESTMODE = True
1212

1313

14-
def get_things_to_delete() -> (
14+
def _get_things_to_delete() -> (
1515
Tuple[List[Tuple[str, float, str]], List[Tuple[str, float, str]]]
1616
):
1717
(
@@ -36,33 +36,33 @@ def get_things_to_delete() -> (
3636

3737
if (
3838
os.path.isdir(item_path)
39-
and get_days_since_creation(item_path) > days_until_deletion
39+
and _get_days_since_creation(item_path) > days_until_deletion
4040
):
41-
_folder_results.append((item_path, get_size_bytes(item_path), "age"))
41+
_folder_results.append((item_path, _get_size_bytes(item_path), "age"))
4242
if os.path.isfile(item_path):
43-
if re.match(pattern, item) and has_extracted_folder(item_path):
43+
if re.match(pattern, item) and _has_extracted_folder(item_path):
4444
_file_results.append(
4545
(
4646
item_path,
47-
get_size_bytes(item_path),
47+
_get_size_bytes(item_path),
4848
"unpacked",
4949
)
5050
)
5151
continue
52-
if get_days_since_creation(item_path) > days_until_deletion:
53-
_file_results.append((item_path, get_size_bytes(item_path), "age"))
52+
if _get_days_since_creation(item_path) > days_until_deletion:
53+
_file_results.append((item_path, _get_size_bytes(item_path), "age"))
5454

5555
return _file_results, _folder_results
5656

5757

58-
def bytes_to_string(bytes_size: float) -> str:
58+
def _bytes_to_string(bytes_size: float) -> str:
5959
if bytes_size >= 1024**3:
6060
return f"{bytes_size / 1024**3:.2f} GB"
6161
else:
6262
return f"{bytes_size / 1024**2:.2f} MB"
6363

6464

65-
def get_size_bytes(path: str) -> float:
65+
def _get_size_bytes(path: str) -> float:
6666
return_size_bytes = 0
6767
if os.path.isfile(path):
6868
return_size_bytes = os.path.getsize(path)
@@ -75,7 +75,7 @@ def get_size_bytes(path: str) -> float:
7575
return return_size_bytes
7676

7777

78-
def get_days_since_creation(path: str) -> int:
78+
def _get_days_since_creation(path: str) -> int:
7979
if os.path.isfile(path):
8080
creation_time = os.path.getctime(path)
8181
elif os.path.isdir(path):
@@ -88,12 +88,12 @@ def get_days_since_creation(path: str) -> int:
8888
return (current_date - creation_date).days
8989

9090

91-
def has_extracted_folder(file_path: str) -> bool:
91+
def _has_extracted_folder(file_path: str) -> bool:
9292
folder_path = os.path.splitext(file_path)[0]
9393
return os.path.isdir(folder_path)
9494

9595

96-
def delete_file_or_folder(path: str, isfile: bool):
96+
def _delete_file_or_folder(path: str, isfile: bool):
9797
if TESTMODE:
9898
return
9999
with contextlib.suppress(FileNotFoundError):
@@ -103,7 +103,7 @@ def delete_file_or_folder(path: str, isfile: bool):
103103
shutil.rmtree(path)
104104

105105

106-
def handle_startup() -> None:
106+
def _handle_startup() -> None:
107107
(
108108
_,
109109
_,
@@ -114,6 +114,8 @@ def handle_startup() -> None:
114114

115115
if start_with_windows:
116116
registry.add_to_autostart()
117+
else:
118+
registry.remove_from_autostart()
117119

118120
max_log_size_bytes = max_log_size_mb * 1024 * 1024
119121
if (
@@ -125,9 +127,9 @@ def handle_startup() -> None:
125127

126128

127129
def process_things():
128-
handle_startup()
130+
_handle_startup()
129131

130-
things_to_delete = get_things_to_delete()
132+
things_to_delete = _get_things_to_delete()
131133
files_to_delete, folders_to_delete = things_to_delete
132134

133135
bytes_to_delete = 0
@@ -152,17 +154,17 @@ def process_things():
152154

153155
logger.log(
154156
logger.INFO,
155-
f"{type_label}: {basename} SIZE: {bytes_to_string(size_bytes)} REASON: {reason}",
157+
f"{type_label}: {basename} SIZE: {_bytes_to_string(size_bytes)} REASON: {reason}",
156158
)
157159

158160
bytes_to_delete += size_bytes
159-
delete_file_or_folder(path, is_file)
161+
_delete_file_or_folder(path, is_file)
160162

161-
if bytes_to_delete <= 0:
163+
if bytes_to_delete == 0.0:
162164
logger.show_summary()
163165
else:
164166
popup.show_notification(
165-
f"Deleted {bytes_to_string(bytes_to_delete)} from your computer.",
167+
f"Deleted {_bytes_to_string(bytes_to_delete)} from your computer.",
166168
f"{len(files_to_delete)} files and {len(folders_to_delete)} folders.\n"
167169
+ f"{amount_reason_unpacked} files already unpacked, {amount_reason_age} too old ({config.data[2]} days)",
168170
)

wfc/logger.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def show_summary():
2929
if "Program startup" in line:
3030
continue
3131

32-
timestamp, _, size, _ = extract_line_data(line)
32+
timestamp, _, size, _ = _extract_line_data(line)
3333
if timestamp == "":
3434
continue
3535
timestamp_datetime = datetime.strptime(timestamp, DATE_FORMAT)
@@ -44,7 +44,7 @@ def show_summary():
4444
)
4545

4646

47-
def extract_line_data(line) -> Tuple[str, str, str, str]:
47+
def _extract_line_data(line) -> Tuple[str, str, str, str]:
4848
# sourcery skip: extract-method, inline-variable, remove-unnecessary-else
4949
# Define regular expressions to match different parts of the log line
5050
timestamp_regex = r"(\d{2}\.\d{2}\.\d{4} \d{2}:\d{2}:\d{2})"

wfc/paths.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
import sys
33

44

5-
def get_base_path() -> str:
5+
def _get_base_path() -> str:
66
if getattr(sys, "frozen", False):
77
module_dir = os.path.dirname(sys.executable)
88
else:
99
module_dir = os.path.dirname(os.path.abspath(__file__))
10-
return strip_package_name_from_path(module_dir)
10+
return _strip_package_name_from_path(module_dir)
1111

1212

13-
def strip_package_name_from_path(path) -> str:
13+
def _strip_package_name_from_path(path) -> str:
1414
suffix = "wfc" # Removed the backslash for platform independence
1515
return path[: -len(suffix)] if path.endswith(suffix) else path
1616

@@ -23,7 +23,7 @@ def strip_package_name_from_path(path) -> str:
2323
LOG_FILE_NAME = "wfc.log"
2424
ICON_FILE_NAME = "clean.ico"
2525

26-
BASE_PATH = get_base_path()
26+
BASE_PATH = _get_base_path()
2727
EXE_PATH = os.path.join(BASE_PATH, EXE_FILE_NAME)
2828

2929
CONFIG_PATH = os.path.join(BASE_PATH, CONFIG_FILE_NAME)

wfc/popup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
RECYCLE_BIN_BUTTON_TXT = "Open Recycle Bin"
88

99

10-
def tray_clicked(button: dict):
10+
def _tray_clicked(button: dict):
1111
button_name_pressed = button["arguments"].split(":")[1].strip()
1212
if button_name_pressed == LOG_BUTTON_TXT:
1313
os.startfile(paths.LOG_PATH)
@@ -25,7 +25,7 @@ def show_notification(title: str, message: str):
2525
message,
2626
audio={"silent": "true"},
2727
duration="long",
28-
on_click=lambda args: tray_clicked(args),
28+
on_click=lambda args: _tray_clicked(args),
2929
buttons=[LOG_BUTTON_TXT, RECYCLE_BIN_BUTTON_TXT],
3030
icon=icon,
3131
)

0 commit comments

Comments
 (0)