initial commit of new version
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
from avdb.db import DBOps, DBConnection
|
||||
|
||||
def process_single_file(db_ops, file_path):
|
||||
"""
|
||||
Process a single image file.
|
||||
|
||||
Args:
|
||||
db_ops (DBOps): An instance of DBOps for database operations.
|
||||
file_path (str): Path to the image file.
|
||||
"""
|
||||
print(f"Processing file: {file_path}")
|
||||
db_ops.process_image_analysis(file_path)
|
||||
|
||||
def process_directory(db_ops, directory_path):
|
||||
"""
|
||||
Process all image files in a directory.
|
||||
|
||||
Args:
|
||||
db_ops (DBOps): An instance of DBOps for database operations.
|
||||
directory_path (str): Path to the directory containing image files.
|
||||
"""
|
||||
print(f"Processing directory: {directory_path}")
|
||||
for root, _, files in os.walk(directory_path):
|
||||
# print(files)
|
||||
# print(root)
|
||||
for file in files:
|
||||
m = re.match(r'img_\d{4}\.jpeg', file.lower())
|
||||
if m is not None:
|
||||
file_path = os.path.join(root, file)
|
||||
process_single_file(db_ops, file_path)
|
||||
|
||||
def main():
|
||||
# Parse command-line arguments
|
||||
parser = argparse.ArgumentParser(description="Run image analysis for a single file or all files in a directory.")
|
||||
parser.add_argument("path", help="Path to a single image file or a directory containing image files.")
|
||||
parser.add_argument("--dbname", default="testdb", help="Name of the database to use (default: testdb).")
|
||||
args = parser.parse_args()
|
||||
|
||||
# Initialize database connection and operations
|
||||
with DBConnection(args.dbname).get_connection() as db_conn:
|
||||
db_ops = DBOps(db_conn)
|
||||
|
||||
# Determine if the path is a file or directory
|
||||
if os.path.isfile(args.path):
|
||||
process_single_file(db_ops, args.path)
|
||||
elif os.path.isdir(args.path):
|
||||
process_directory(db_ops, args.path)
|
||||
else:
|
||||
print(f"Error: Path '{args.path}' does not exist.")
|
||||
sys.exit(1)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user