Added hidden --debug option to cmd_line
This commit is contained in:
@@ -44,18 +44,26 @@ _PHOTOS_5_VERSION = "6000"
|
||||
# which major version operating systems have been tested
|
||||
_TESTED_OS_VERSIONS = ["12", "13", "14", "15"]
|
||||
|
||||
# set _debug = True to enable debug output
|
||||
_debug = False
|
||||
# set _DEBUG = True to enable debug output
|
||||
_DEBUG = False
|
||||
|
||||
logging.basicConfig(
|
||||
level=logging.DEBUG,
|
||||
format="%(asctime)s - %(levelname)s - %(filename)s - %(lineno)d - %(message)s",
|
||||
)
|
||||
|
||||
if not _debug:
|
||||
if not _DEBUG:
|
||||
logging.disable(logging.DEBUG)
|
||||
|
||||
|
||||
def _debug(debug):
|
||||
""" Enable or disable debug logging """
|
||||
if debug:
|
||||
logging.disable(logging.NOTSET)
|
||||
else:
|
||||
logging.disable(logging.DEBUG)
|
||||
|
||||
|
||||
def _get_os_version():
|
||||
# returns tuple containing OS version
|
||||
# e.g. 10.13.6 = (10, 13, 6)
|
||||
@@ -194,6 +202,7 @@ class PhotosDB:
|
||||
try:
|
||||
os.remove(f)
|
||||
except Exception as e:
|
||||
logging.debug(f"exception {e} removing {f}")
|
||||
pass
|
||||
# print(f"WARNING: Unable to remove tmp file {e}")
|
||||
# raise e
|
||||
@@ -362,6 +371,8 @@ class PhotosDB:
|
||||
raise Exception
|
||||
|
||||
self._tmp_files.extend(tmp_files)
|
||||
logging.debug(self._tmp_files)
|
||||
|
||||
return tmp
|
||||
|
||||
def _open_sql_file(self, file):
|
||||
@@ -654,7 +665,7 @@ class PhotosDB:
|
||||
# remove temporary files
|
||||
self._cleanup_tmp_files()
|
||||
|
||||
if _debug:
|
||||
if _DEBUG:
|
||||
logging.debug("Faces:")
|
||||
logging.debug(pformat(self._dbfaces_uuid))
|
||||
|
||||
@@ -839,8 +850,9 @@ class PhotosDB:
|
||||
for row in c:
|
||||
i = i + 1
|
||||
uuid = row[0]
|
||||
if _debug:
|
||||
if _DEBUG:
|
||||
logging.debug(f"i = {i:d}, uuid = '{uuid}")
|
||||
|
||||
self._dbphotos[uuid] = {}
|
||||
self._dbphotos[uuid]["modelID"] = None
|
||||
self._dbphotos[uuid]["masterUuid"] = None
|
||||
@@ -940,7 +952,7 @@ class PhotosDB:
|
||||
else:
|
||||
self._dbphotos[uuid]["isMissing"] = 0
|
||||
|
||||
if _debug:
|
||||
if _DEBUG:
|
||||
logging.debug(pformat(self._dbphotos))
|
||||
|
||||
# add faces and keywords to photo data
|
||||
@@ -971,7 +983,7 @@ class PhotosDB:
|
||||
conn.close()
|
||||
self._cleanup_tmp_files()
|
||||
|
||||
if _debug:
|
||||
if _DEBUG:
|
||||
logging.debug("Faces:")
|
||||
logging.debug(pformat(self._dbfaces_uuid))
|
||||
|
||||
|
||||
@@ -7,12 +7,13 @@ import yaml
|
||||
|
||||
import osxphotos
|
||||
|
||||
# TODO: add query for description, name (contains text)
|
||||
# TODO: add "--any" to search any field (e.g. keyword, description, name contains "wedding") (add case insensitive option)
|
||||
|
||||
|
||||
class CLI_Obj:
|
||||
def __init__(self, db=None, json=False):
|
||||
def __init__(self, db=None, json=False, debug=False):
|
||||
if debug:
|
||||
osxphotos._debug(True)
|
||||
self.photosdb = osxphotos.PhotosDB(dbfile=db)
|
||||
self.json = json
|
||||
|
||||
@@ -35,9 +36,10 @@ CTX_SETTINGS = dict(help_option_names=["-h", "--help"])
|
||||
default=False,
|
||||
help="Print output in JSON format",
|
||||
)
|
||||
@click.option("--debug", required=False, is_flag=True, default=False, hidden=True)
|
||||
@click.pass_context
|
||||
def cli(ctx, db, json):
|
||||
ctx.obj = CLI_Obj(db=db, json=json)
|
||||
def cli(ctx, db, json, debug):
|
||||
ctx.obj = CLI_Obj(db=db, json=json, debug=debug)
|
||||
|
||||
|
||||
@cli.command()
|
||||
@@ -136,7 +138,9 @@ def dump(cli_obj):
|
||||
multiple=True,
|
||||
help="search for TEXT in description of photo",
|
||||
)
|
||||
@click.option("--no-description", is_flag=True, help="search for photos with no description")
|
||||
@click.option(
|
||||
"--no-description", is_flag=True, help="search for photos with no description"
|
||||
)
|
||||
@click.option(
|
||||
"-i",
|
||||
"--ignore-case",
|
||||
@@ -223,11 +227,11 @@ def query(
|
||||
elif name and no_name:
|
||||
# can't search for both name and no_name
|
||||
print(cli.commands["query"].get_help(ctx))
|
||||
return
|
||||
return
|
||||
elif description and no_description:
|
||||
# can't search for both description and no_description
|
||||
print(cli.commands["query"].get_help(ctx))
|
||||
return
|
||||
return
|
||||
else:
|
||||
photos = cli_obj.photosdb.photos(
|
||||
keywords=keyword, persons=person, albums=album, uuid=uuid
|
||||
|
||||
Reference in New Issue
Block a user