Using folders "Copies" and "Par label", hopefully
This commit is contained in:
+23
-5
@@ -20,17 +20,35 @@ if len(sys.argv) < 2:
|
||||
path_arg = sys.argv[1]
|
||||
files = []
|
||||
INPUT_DIR = ""
|
||||
COPIES_DIR = ""
|
||||
|
||||
if os.path.isfile(path_arg) and path_arg.lower().endswith('.pdf'):
|
||||
INPUT_DIR = os.path.dirname(path_arg)
|
||||
COPIES_DIR = os.path.abspath(os.path.dirname(path_arg))
|
||||
# If the file is inside a "Copies" folder, set INPUT_DIR to the parent
|
||||
if os.path.basename(COPIES_DIR).lower() == 'copies':
|
||||
INPUT_DIR = os.path.dirname(COPIES_DIR)
|
||||
else:
|
||||
INPUT_DIR = COPIES_DIR
|
||||
files = [os.path.basename(path_arg)]
|
||||
elif os.path.isdir(path_arg):
|
||||
INPUT_DIR = path_arg
|
||||
files = sorted([f for f in os.listdir(INPUT_DIR) if f.lower().endswith('.pdf') and
|
||||
"nonc" not in f.lower()])
|
||||
# Support passing either the base dir or the Copies dir directly
|
||||
abs_path = os.path.abspath(path_arg)
|
||||
if os.path.basename(abs_path).lower() == 'copies':
|
||||
COPIES_DIR = abs_path
|
||||
INPUT_DIR = os.path.dirname(abs_path)
|
||||
else:
|
||||
INPUT_DIR = abs_path
|
||||
COPIES_DIR = os.path.join(INPUT_DIR, 'Copies')
|
||||
|
||||
if os.path.exists(COPIES_DIR):
|
||||
files = sorted([f for f in os.listdir(COPIES_DIR) if f.lower().endswith('.pdf') and
|
||||
"nonc" not in f.lower()])
|
||||
else:
|
||||
sys.exit(f"Error: Could not find 'Copies' directory inside {INPUT_DIR}")
|
||||
else:
|
||||
sys.exit("Error: Input must be a directory or a PDF file.")
|
||||
|
||||
|
||||
OUTPUT_DIR = os.path.join(INPUT_DIR, 'Cutleft')
|
||||
|
||||
if not os.path.exists(OUTPUT_DIR):
|
||||
@@ -90,7 +108,7 @@ pdf_cache_lock = threading.Lock()
|
||||
|
||||
@lru_cache(maxsize=3)
|
||||
def _get_pdf_pages_cached(filename):
|
||||
pdf_path = os.path.join(INPUT_DIR, filename)
|
||||
pdf_path = os.path.join(COPIES_DIR, filename)
|
||||
return convert_from_path(pdf_path)
|
||||
|
||||
def get_pdf_pages(filename):
|
||||
|
||||
Reference in New Issue
Block a user