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
|
plan.svg
|
||||||
data/file_rules_custom.json
|
data/file_rules_custom.json
|
||||||
app.log
|
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
|
from tkinter import filedialog as fd
|
||||||
|
|
||||||
debug_mode = False
|
debug_mode = False
|
||||||
custom_rules_path = "%/Temp/file_rules_custom.json"
|
custom_rules_path = "%/Gull/file_rules_custom.json"
|
||||||
|
|
||||||
def set_debug_mode(value):
|
def set_debug_mode(value):
|
||||||
global debug_mode
|
global debug_mode
|
||||||
|
|
@ -22,15 +22,16 @@ def set_debug_mode(value):
|
||||||
debug_mode = value
|
debug_mode = value
|
||||||
|
|
||||||
def setup_log():
|
def setup_log():
|
||||||
import sys
|
from sys import stdout
|
||||||
|
|
||||||
log.basicConfig(
|
log.basicConfig(
|
||||||
filename="app.log",
|
filename=ut.parse_dir("%/Gull/app.log"),
|
||||||
filemode="w",
|
filemode="w",
|
||||||
level=log.DEBUG,
|
level=log.DEBUG,
|
||||||
format="{asctime}: [{levelname}] {message}",
|
format="{asctime}: [{levelname}] {message}",
|
||||||
style="{")
|
style="{")
|
||||||
|
|
||||||
log.getLogger().addHandler(log.StreamHandler(sys.stdout)) # Console
|
log.getLogger().addHandler(log.StreamHandler(stdout)) # Console
|
||||||
log.info("App started")
|
log.info("App started")
|
||||||
|
|
||||||
class App(tk.Tk):
|
class App(tk.Tk):
|
||||||
|
|
@ -124,7 +125,9 @@ class App(tk.Tk):
|
||||||
|
|
||||||
def select_mode_from_list(self, event):
|
def select_mode_from_list(self, event):
|
||||||
key = ""
|
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():
|
for k, v in self.fm.filemodes.items():
|
||||||
if v["name"] == value:
|
if v["name"] == value:
|
||||||
key = k
|
key = k
|
||||||
|
|
@ -161,9 +164,9 @@ class App(tk.Tk):
|
||||||
for v in result: stats[v[0]] += 1
|
for v in result: stats[v[0]] += 1
|
||||||
mb.showinfo("Task",
|
mb.showinfo("Task",
|
||||||
f"Successfully processed {len(result)} files in total.\n"
|
f"Successfully processed {len(result)} files in total.\n"
|
||||||
+ f"Moved {stats["move"]} files.\n"
|
+ f"Moved {stats['move']} files.\n"
|
||||||
+ f"Copied {stats["copy"]} files.\n"
|
+ f"Copied {stats['copy']} files.\n"
|
||||||
+ f"Deleted {stats["delete"]} files.\n")
|
+ f"Deleted {stats['delete']} files.\n")
|
||||||
|
|
||||||
def run_backup(self):
|
def run_backup(self):
|
||||||
result = mb.askyesno("Backup", "Ready to back up all files?")
|
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 os
|
||||||
import time
|
import time
|
||||||
import json
|
import json
|
||||||
|
import pathlib
|
||||||
import appdirs as ad
|
import appdirs as ad
|
||||||
|
|
||||||
KILOBYTES = 1024
|
KILOBYTES = 1024
|
||||||
|
|
@ -61,11 +62,13 @@ def get_appdata_dir(dir=""):
|
||||||
"""Returns the joined appdata directory."""
|
"""Returns the joined appdata directory."""
|
||||||
return os.path.join(ad.user_data_dir(None, False), dir)
|
return os.path.join(ad.user_data_dir(None, False), dir)
|
||||||
|
|
||||||
def parse_dir(dir=""):
|
def parse_dir(path=""):
|
||||||
"""Checks if a directory exists, and if it is special."""
|
"""Converts and creates a directory (can be full file path)."""
|
||||||
if dir[0] == "~": # Denotes the current user directory
|
if path[0] == "~": # Denotes the current user directory
|
||||||
dir = get_user_dir(dir.lstrip("~/"))
|
path = get_user_dir(path.lstrip("~/"))
|
||||||
elif dir[0] == "%": # Denotes the local appdata directory
|
elif path[0] == "%": # Denotes the local appdata directory
|
||||||
dir = get_appdata_dir(dir.lstrip("%/"))
|
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