aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeonard Kugis <leonard@kug.is>2023-03-21 19:57:18 +0100
committerLeonard Kugis <leonard@kug.is>2023-03-21 19:57:18 +0100
commitb05c4000100be8effb3e458a1dfeea948c216ce6 (patch)
treeac5aaa80de7e8eb375001d7fb1ed2dd817a05039
parent54d51264aacba7fe8839f4ef0707fc1aaf561a89 (diff)
Implemented difference between base and file-dir
-rw-r--r--file-tagger.py8
-rw-r--r--gui.py29
2 files changed, 22 insertions, 15 deletions
diff --git a/file-tagger.py b/file-tagger.py
index 2391212..2b76947 100644
--- a/file-tagger.py
+++ b/file-tagger.py
@@ -63,7 +63,7 @@ def tmsu_init(base):
logger = logging.getLogger(__name__)
if not os.path.exists(os.path.join(base, ".tmsu")):
logger.info("TMSU database does not exist, creating ...")
- proc = Popen(["tmsu", "init"], cwd=base)
+ proc = subprocess.Popen(["tmsu", "init"], cwd=base)
proc.wait()
logger.debug("TMSU returncode: {}".format(proc.returncode))
if proc.returncode != 0:
@@ -128,7 +128,7 @@ def walk(args):
logger.info("Walking files ...")
mime = magic.Magic(mime=True)
- files = [os.path.abspath(os.path.join(dp, f)) for dp, dn, filenames in os.walk(args["base"]) for f in filenames]
+ files = [os.path.abspath(os.path.join(dp, f)) for dp, dn, filenames in os.walk(args["file_dir"]) for f in filenames]
logger.debug("Files: {}".format(files))
logger.info("Number of files found: {}".format(len(files)))
@@ -206,7 +206,8 @@ def walk(args):
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Tag multiple files using TMSU.')
- parser.add_argument('-b', '--base', nargs='?', default='./test', type=dir_path, help='Base directory for walking (default: %(default)s)')
+ parser.add_argument('-b', '--base', nargs='?', default='.', type=dir_path, help='Base directory with database (default: %(default)s)')
+ parser.add_argument('-f', '--file-dir', nargs='?', default='.', type=dir_path, help='File directory for walking (default: %(default)s)')
parser.add_argument('-g', '--gui', nargs='?', const=1, default=False, type=bool, help='Show main GUI (default: %(default)s)')
parser.add_argument('--predict-images', nargs='?', const=1, default=False, type=bool, help='Use prediction for image tagging (default: %(default)s)')
parser.add_argument('--predict-images-top', nargs='?', const=1, default=10, type=int, help='Defines how many top prediction keywords should be used (default: %(default)s)')
@@ -228,6 +229,7 @@ if __name__ == "__main__":
args = {
"base": args.base,
+ "file_dir": args.file_dir,
"gui": args.gui,
"predict_images": args.predict_images,
"predict_images_top": args.predict_images_top,
diff --git a/gui.py b/gui.py
index 9bd6c2a..d84aa0a 100644
--- a/gui.py
+++ b/gui.py
@@ -11,6 +11,7 @@ class GuiMain(object):
self.__master.title("file-tagger")
self.__args = args
self.__base = StringVar(self.__master, value=args["base"])
+ self.__file_dir = StringVar(self.__master, value=args["file_dir"])
self.__predict_images = BooleanVar(self.__master, value=args["predict_images"])
self.__predict_images_top = StringVar(self.__master, value=str(args["predict_images_top"]))
self.__gui_tag = BooleanVar(self.__master, value=args["gui_tag"])
@@ -19,22 +20,26 @@ class GuiMain(object):
validate_number = (self.__master.register(self.__validate_number))
- Label(self.__master, text="Base directory for walking:").grid(row=0, column=0)
+ Label(self.__master, text="Base directory with database:").grid(row=0, column=0)
Entry(self.__master, textvariable=self.__base).grid(row=0, column=1, columnspan=2)
- Button(self.__master, text="Browse", command=self.__browse).grid(row=0, column=3)
- Checkbutton(self.__master, text="Use prediction for image tagging", variable=self.__predict_images).grid(row=1, column=0, columnspan=4, sticky=W)
- Label(self.__master, text="Number of top results:").grid(row=2, column=0)
- Entry(self.__master, textvariable=self.__predict_images_top, validate='all', validatecommand=(validate_number, '%P')).grid(row=2, column=1, columnspan=1)
- Checkbutton(self.__master, text="Show GUI for tagging", variable=self.__gui_tag).grid(row=3, column=0, columnspan=4, sticky=W)
- Checkbutton(self.__master, text="Open all files with system default", variable=self.__open_system).grid(row=4, column=0, columnspan=4, sticky=W)
- Label(self.__master, text="Start at index:").grid(row=5, column=0)
- Entry(self.__master, textvariable=self.__index, validate='all', validatecommand=(validate_number, '%P')).grid(row=5, column=1, columnspan=1)
- Button(self.__master, text="Start", command=self.__master.destroy).grid(row=6, column=0, columnspan=4)
+ Button(self.__master, text="Browse", command=lambda: self.__browse(self.__base)).grid(row=0, column=3)
+ Label(self.__master, text="File directory for walking:").grid(row=1, column=0)
+ Entry(self.__master, textvariable=self.__file_dir).grid(row=1, column=1, columnspan=2)
+ Button(self.__master, text="Browse", command=lambda: self.__browse(self.__file_dir)).grid(row=1, column=3)
+ Checkbutton(self.__master, text="Use prediction for image tagging", variable=self.__predict_images).grid(row=2, column=0, columnspan=4, sticky=W)
+ Label(self.__master, text="Number of top results:").grid(row=3, column=0)
+ Entry(self.__master, textvariable=self.__predict_images_top, validate='all', validatecommand=(validate_number, '%P')).grid(row=3, column=1, columnspan=1)
+ Checkbutton(self.__master, text="Show GUI for tagging", variable=self.__gui_tag).grid(row=4, column=0, columnspan=4, sticky=W)
+ Checkbutton(self.__master, text="Open all files with system default", variable=self.__open_system).grid(row=5, column=0, columnspan=4, sticky=W)
+ Label(self.__master, text="Start at index:").grid(row=6, column=0)
+ Entry(self.__master, textvariable=self.__index, validate='all', validatecommand=(validate_number, '%P')).grid(row=6, column=1, columnspan=1)
+ Button(self.__master, text="Start", command=self.__master.destroy).grid(row=7, column=0, columnspan=4)
def loop(self):
self.__master.mainloop()
self.__args["base"] = self.__base.get()
+ self.__args["file_dir"] = self.__file_dir.get()
self.__args["predict_images"] = self.__predict_images.get()
self.__args["predict_images_top"] = int(self.__predict_images_top.get())
self.__args["gui_tag"] = self.__gui_tag.get()
@@ -42,9 +47,9 @@ class GuiMain(object):
self.__args["index"] = int(self.__index.get())
return self.__args
- def __browse(self):
+ def __browse(self, filepath):
filename = filedialog.askdirectory()
- self.__base.set(filename)
+ filepath.set(filename)
def __validate_number(self, P):
if str.isdigit(P) or P == "":