Compare commits
No commits in common. "07859d66827f2b7a37b712300fa3dc6e21c08df5" and "4dcda1961470fcfee238151fe9049b7908bce374" have entirely different histories.
07859d6682
...
4dcda19614
@ -1,8 +1,9 @@
|
||||
from os import path, getcwd, listdir, mkdir, makedirs, rename
|
||||
import re
|
||||
|
||||
def read_config(filepath, root_directory="."):
|
||||
if not path.isfile(filepath): return False
|
||||
def read_config(filepath):
|
||||
if not path.isfile(filepath):
|
||||
raise FileNotFoundError(f"read_config: Invalid filepath {filepath}")
|
||||
|
||||
file = open(filepath, 'r')
|
||||
keys = {}
|
||||
@ -11,7 +12,7 @@ def read_config(filepath, root_directory="."):
|
||||
match = re.match(r". = /?([a-z-A-ZöÖäÄüÜ0-9/: _-]+/)*[a-zA-ZöÖäÄüÜ0-9/: _-]+/?", line)
|
||||
if match:
|
||||
key, value = line.split(" = ")
|
||||
keys[key] = root_directory + "/" + value
|
||||
keys[key] = value
|
||||
return keys
|
||||
|
||||
def write_config(filepath, keys):
|
||||
|
@ -3,8 +3,9 @@
|
||||
import curses as c
|
||||
import ueberzug.lib.v0 as uz
|
||||
|
||||
import os
|
||||
from os import path, getcwd, listdir, makedirs, rename
|
||||
<<<<<<< HEAD
|
||||
|
||||
from os import path, getcwd, listdir, mkdir, makedirs, rename
|
||||
import subprocess
|
||||
|
||||
if __name__ == "__main__": # make relative imports work as described here: https://peps.python.org/pep-0366/#proposed-change
|
||||
@ -14,9 +15,7 @@ if __name__ == "__main__": # make relative imports work as described here: http
|
||||
filepath = path.realpath(path.abspath(__file__))
|
||||
sys.path.insert(0, path.dirname(path.dirname(filepath)))
|
||||
|
||||
from .configs import read_config, select_config
|
||||
|
||||
import argparse
|
||||
from .configs import read_config, write_config, select_config, create_config
|
||||
|
||||
settings = {
|
||||
"q": "quit",
|
||||
@ -220,8 +219,6 @@ class Sorter:
|
||||
for k, v in self.keys.items():
|
||||
if i >= self.win_y - KEYS_BEGIN - FOOTER_HEIGHT: # dont write into footer
|
||||
break
|
||||
# show only last part
|
||||
v = v.split("/")[-1]
|
||||
if k == self.pressed_key:
|
||||
self.window.addnstr(KEYS_BEGIN + i, 0, f" {k}: {v}", SIDEBAR_WIDTH, c.A_STANDOUT)
|
||||
else:
|
||||
@ -246,34 +243,37 @@ class Sorter:
|
||||
print(f"Quitting imgsort {version}")
|
||||
exit(0)
|
||||
|
||||
|
||||
def __del__(self):
|
||||
self.window.clear()
|
||||
self.window.refresh()
|
||||
c.endwin()
|
||||
|
||||
|
||||
|
||||
def main():
|
||||
# set working directory
|
||||
print("""
|
||||
===================================================================================================
|
||||
Image Sorter
|
||||
===================================================================================================
|
||||
""")
|
||||
config_dir = os.path.join(os.environ.get("XDG_CONFIG_HOME", os.path.expanduser("~/.config")), "imgsort")
|
||||
print(f"""===================================================================================================
|
||||
imgsort {version} - Image Sorter
|
||||
===================================================================================================""")
|
||||
# set directories
|
||||
config_dir = os.path.join(os.environ.get("XDG_CONFIG_HOME", os.path.expanduser("~/.config")), "regina")
|
||||
# check if environment variables are set and use them if they are
|
||||
if 'IMGSOSRT_CONFIG_DIR' in os.environ: config_dir = os.environ['IMGSORT_CONFIG_DIR']
|
||||
|
||||
parser = argparse.ArgumentParser("imgsort")
|
||||
parser.add_argument("-c", "--config", action="store", help="name of the config file in ($IMGSORT_CONFIG_DIR > $XDG_CONFIG_HOME/imgsort > ~/.config/imgsort)")
|
||||
parser.add_argument("-i", "--sort-dir", action="store", help="the directory where the folders from the config will be created")
|
||||
parser = argparse.ArgumentParser(prog="imgsort")
|
||||
parser.add_argument("--config", "-c", action="store", help="name or path of config file", metavar="config file")
|
||||
parser.add_argument("--dir", "-d", action="store", help="working directory", metavar="working directory")
|
||||
args = parser.parse_args()
|
||||
|
||||
wd = getcwd();
|
||||
|
||||
if args.sort_dir:
|
||||
args.sort_dir = path.abspath(args.sort_dir)
|
||||
# working directory
|
||||
if args.dir:
|
||||
if not path.isdir(args.dir):
|
||||
parser.error(f"invalid working directory: {args.wdir}")
|
||||
wd = path.abspath(args.dir)
|
||||
os.chdir(wd)
|
||||
else:
|
||||
args.sort_dir = getcwd()
|
||||
wd = getcwd()
|
||||
|
||||
# configuration
|
||||
if args.config:
|
||||
@ -284,12 +284,16 @@ Image Sorter
|
||||
if not path.isfile(config_path):
|
||||
parser.error(f"invalid configuration path/name:'{config_path}'/'{args.config}'")
|
||||
else:
|
||||
args.config = select_config()
|
||||
config_path = select_config()
|
||||
print(config_path)
|
||||
if config_path is not None:
|
||||
config = read_config(config_path)
|
||||
else:
|
||||
config = create_config()
|
||||
|
||||
config = read_config(args.config, root_directory=args.sort_dir)
|
||||
if not config:
|
||||
print("Error reading the config:")
|
||||
print(" Config Name:", args.config)
|
||||
print(" Config Name:", config_path)
|
||||
print(" Config:", config)
|
||||
exit(1)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user