Added hidden --debug option to cmd_line

This commit is contained in:
Rhet Turnbull
2019-11-30 23:08:49 -08:00
parent eb563ad297
commit 9c32d77b2c
2 changed files with 30 additions and 14 deletions

View File

@@ -44,15 +44,23 @@ _PHOTOS_5_VERSION = "6000"
# which major version operating systems have been tested # which major version operating systems have been tested
_TESTED_OS_VERSIONS = ["12", "13", "14", "15"] _TESTED_OS_VERSIONS = ["12", "13", "14", "15"]
# set _debug = True to enable debug output # set _DEBUG = True to enable debug output
_debug = False _DEBUG = False
logging.basicConfig( logging.basicConfig(
level=logging.DEBUG, level=logging.DEBUG,
format="%(asctime)s - %(levelname)s - %(filename)s - %(lineno)d - %(message)s", 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) logging.disable(logging.DEBUG)
@@ -194,6 +202,7 @@ class PhotosDB:
try: try:
os.remove(f) os.remove(f)
except Exception as e: except Exception as e:
logging.debug(f"exception {e} removing {f}")
pass pass
# print(f"WARNING: Unable to remove tmp file {e}") # print(f"WARNING: Unable to remove tmp file {e}")
# raise e # raise e
@@ -362,6 +371,8 @@ class PhotosDB:
raise Exception raise Exception
self._tmp_files.extend(tmp_files) self._tmp_files.extend(tmp_files)
logging.debug(self._tmp_files)
return tmp return tmp
def _open_sql_file(self, file): def _open_sql_file(self, file):
@@ -654,7 +665,7 @@ class PhotosDB:
# remove temporary files # remove temporary files
self._cleanup_tmp_files() self._cleanup_tmp_files()
if _debug: if _DEBUG:
logging.debug("Faces:") logging.debug("Faces:")
logging.debug(pformat(self._dbfaces_uuid)) logging.debug(pformat(self._dbfaces_uuid))
@@ -839,8 +850,9 @@ class PhotosDB:
for row in c: for row in c:
i = i + 1 i = i + 1
uuid = row[0] uuid = row[0]
if _debug: if _DEBUG:
logging.debug(f"i = {i:d}, uuid = '{uuid}") logging.debug(f"i = {i:d}, uuid = '{uuid}")
self._dbphotos[uuid] = {} self._dbphotos[uuid] = {}
self._dbphotos[uuid]["modelID"] = None self._dbphotos[uuid]["modelID"] = None
self._dbphotos[uuid]["masterUuid"] = None self._dbphotos[uuid]["masterUuid"] = None
@@ -940,7 +952,7 @@ class PhotosDB:
else: else:
self._dbphotos[uuid]["isMissing"] = 0 self._dbphotos[uuid]["isMissing"] = 0
if _debug: if _DEBUG:
logging.debug(pformat(self._dbphotos)) logging.debug(pformat(self._dbphotos))
# add faces and keywords to photo data # add faces and keywords to photo data
@@ -971,7 +983,7 @@ class PhotosDB:
conn.close() conn.close()
self._cleanup_tmp_files() self._cleanup_tmp_files()
if _debug: if _DEBUG:
logging.debug("Faces:") logging.debug("Faces:")
logging.debug(pformat(self._dbfaces_uuid)) logging.debug(pformat(self._dbfaces_uuid))

View File

@@ -7,12 +7,13 @@ import yaml
import osxphotos 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) # TODO: add "--any" to search any field (e.g. keyword, description, name contains "wedding") (add case insensitive option)
class CLI_Obj: 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.photosdb = osxphotos.PhotosDB(dbfile=db)
self.json = json self.json = json
@@ -35,9 +36,10 @@ CTX_SETTINGS = dict(help_option_names=["-h", "--help"])
default=False, default=False,
help="Print output in JSON format", help="Print output in JSON format",
) )
@click.option("--debug", required=False, is_flag=True, default=False, hidden=True)
@click.pass_context @click.pass_context
def cli(ctx, db, json): def cli(ctx, db, json, debug):
ctx.obj = CLI_Obj(db=db, json=json) ctx.obj = CLI_Obj(db=db, json=json, debug=debug)
@cli.command() @cli.command()
@@ -136,7 +138,9 @@ def dump(cli_obj):
multiple=True, multiple=True,
help="search for TEXT in description of photo", 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( @click.option(
"-i", "-i",
"--ignore-case", "--ignore-case",