Fixed a few file path bugs
This commit is contained in:
parent
380212e2be
commit
0459bab847
3 changed files with 22 additions and 15 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -5,3 +5,4 @@ venv_linux/
|
|||
plan.svg
|
||||
data/file_rules_custom.json
|
||||
app.log
|
||||
requirements.txt
|
||||
|
|
|
|||
19
app.py
19
app.py
|
|
@ -12,7 +12,7 @@ from tkinter import messagebox as mb
|
|||
from tkinter import filedialog as fd
|
||||
|
||||
debug_mode = False
|
||||
custom_rules_path = "%/Temp/file_rules_custom.json"
|
||||
custom_rules_path = "%/Gull/file_rules_custom.json"
|
||||
|
||||
def set_debug_mode(value):
|
||||
global debug_mode
|
||||
|
|
@ -22,15 +22,16 @@ def set_debug_mode(value):
|
|||
debug_mode = value
|
||||
|
||||
def setup_log():
|
||||
import sys
|
||||
from sys import stdout
|
||||
|
||||
log.basicConfig(
|
||||
filename="app.log",
|
||||
filename=ut.parse_dir("%/Gull/app.log"),
|
||||
filemode="w",
|
||||
level=log.DEBUG,
|
||||
format="{asctime}: [{levelname}] {message}",
|
||||
style="{")
|
||||
|
||||
log.getLogger().addHandler(log.StreamHandler(sys.stdout)) # Console
|
||||
log.getLogger().addHandler(log.StreamHandler(stdout)) # Console
|
||||
log.info("App started")
|
||||
|
||||
class App(tk.Tk):
|
||||
|
|
@ -124,7 +125,9 @@ class App(tk.Tk):
|
|||
|
||||
def select_mode_from_list(self, event):
|
||||
key = ""
|
||||
value = self.w_list.get(self.w_list.curselection())
|
||||
sel = self.w_list.curselection()
|
||||
if len(sel) == 0: return
|
||||
value = self.w_list.get(sel)
|
||||
for k, v in self.fm.filemodes.items():
|
||||
if v["name"] == value:
|
||||
key = k
|
||||
|
|
@ -161,9 +164,9 @@ class App(tk.Tk):
|
|||
for v in result: stats[v[0]] += 1
|
||||
mb.showinfo("Task",
|
||||
f"Successfully processed {len(result)} files in total.\n"
|
||||
+ f"Moved {stats["move"]} files.\n"
|
||||
+ f"Copied {stats["copy"]} files.\n"
|
||||
+ f"Deleted {stats["delete"]} files.\n")
|
||||
+ f"Moved {stats['move']} files.\n"
|
||||
+ f"Copied {stats['copy']} files.\n"
|
||||
+ f"Deleted {stats['delete']} files.\n")
|
||||
|
||||
def run_backup(self):
|
||||
result = mb.askyesno("Backup", "Ready to back up all files?")
|
||||
|
|
|
|||
17
utils.py
17
utils.py
|
|
@ -5,6 +5,7 @@ __author__ = "Gull"
|
|||
import os
|
||||
import time
|
||||
import json
|
||||
import pathlib
|
||||
import appdirs as ad
|
||||
|
||||
KILOBYTES = 1024
|
||||
|
|
@ -61,11 +62,13 @@ def get_appdata_dir(dir=""):
|
|||
"""Returns the joined appdata directory."""
|
||||
return os.path.join(ad.user_data_dir(None, False), dir)
|
||||
|
||||
def parse_dir(dir=""):
|
||||
"""Checks if a directory exists, and if it is special."""
|
||||
if dir[0] == "~": # Denotes the current user directory
|
||||
dir = get_user_dir(dir.lstrip("~/"))
|
||||
elif dir[0] == "%": # Denotes the local appdata directory
|
||||
dir = get_appdata_dir(dir.lstrip("%/"))
|
||||
def parse_dir(path=""):
|
||||
"""Converts and creates a directory (can be full file path)."""
|
||||
if path[0] == "~": # Denotes the current user directory
|
||||
path = get_user_dir(path.lstrip("~/"))
|
||||
elif path[0] == "%": # Denotes the local appdata directory
|
||||
path = get_appdata_dir(path.lstrip("%/"))
|
||||
|
||||
return dir
|
||||
pathlib.Path(os.path.split(path)[0]).mkdir(parents=True, exist_ok=True)
|
||||
|
||||
return path
|
||||
Loading…
Add table
Add a link
Reference in a new issue