Rename dozo to ordigi

This commit is contained in:
Cédric Leporcq 2021-08-13 21:11:24 +02:00
parent 4cec0b8d90
commit f88255e3c5
21 changed files with 80 additions and 81 deletions

View File

@ -9,12 +9,12 @@ from datetime import datetime
import click import click
from send2trash import send2trash from send2trash import send2trash
from dozo import constants from ordigi import constants
from dozo import config from ordigi import config
from dozo.filesystem import FileSystem from ordigi.filesystem import FileSystem
from dozo.database import Db from ordigi.database import Db
from dozo.media.media import Media, get_all_subclasses from ordigi.media.media import Media, get_all_subclasses
from dozo.summary import Summary from ordigi.summary import Summary
FILESYSTEM = FileSystem() FILESYSTEM = FileSystem()
@ -46,7 +46,7 @@ def get_logger(verbose, debug):
logging.debug('This message should appear on the console') logging.debug('This message should appear on the console')
logging.info('So should this') logging.info('So should this')
logging.getLogger('asyncio').setLevel(level) logging.getLogger('asyncio').setLevel(level)
logger = logging.getLogger('dozo') logger = logging.getLogger('ordigi')
logger.level = level logger.level = level
return logger return logger
@ -82,7 +82,7 @@ def get_logger(verbose, debug):
def _sort(debug, dry_run, destination, copy, exclude_regex, filter_by_ext, ignore_tags, def _sort(debug, dry_run, destination, copy, exclude_regex, filter_by_ext, ignore_tags,
max_deep, remove_duplicates, reset_cache, verbose, paths): max_deep, remove_duplicates, reset_cache, verbose, paths):
"""Sort files or directories by reading their EXIF and organizing them """Sort files or directories by reading their EXIF and organizing them
according to config.ini preferences. according to ordigi.conf preferences.
""" """
if copy: if copy:
@ -148,7 +148,7 @@ def _sort(debug, dry_run, destination, copy, exclude_regex, filter_by_ext, ignor
@click.option('--debug', default=False, is_flag=True, @click.option('--debug', default=False, is_flag=True,
help='Override the value in constants.py with True.') help='Override the value in constants.py with True.')
def _generate_db(path, debug): def _generate_db(path, debug):
"""Regenerate the hash.json database which contains all of the sha256 signatures of media files. The hash.json file is located at ~/.dozo/. """Regenerate the hash.json database which contains all of the sha256 signatures of media files.
""" """
constants.debug = debug constants.debug = debug
result = Result() result = Result()

View File

@ -1,7 +1,7 @@
"""Load config file as a singleton.""" """Load config file as a singleton."""
from configparser import RawConfigParser from configparser import RawConfigParser
from os import path from os import path
from dozo import constants from ordigi import constants
def write(conf_file, config): def write(conf_file, config):

View File

@ -8,8 +8,15 @@ from sys import version_info
#: If True, debug messages will be printed. #: If True, debug messages will be printed.
debug = False debug = False
#: Directory in which to store Dozo settings. #Ordigi settings directory.
application_directory = '{}/.dozo'.format(path.expanduser('~')) if 'XDG_CONFIG_HOME' in environ:
confighome = environ['XDG_CONFIG_HOME']
elif 'APPDATA' in environ:
confighome = environ['APPDATA']
else:
confighome = path.join(environ['HOME'], '.config')
application_directory = path.join(confighome, 'ordigi')
default_path = '{%Y-%m-%b}/{album}|{city}|{"Unknown Location"}' default_path = '{%Y-%m-%b}/{album}|{city}|{"Unknown Location"}'
default_name = '{%Y-%m-%d_%H-%M-%S}-{name}-{title}.%l{ext}' default_name = '{%Y-%m-%d_%H-%M-%S}-{name}-{title}.%l{ext}'
default_geocoder = 'Nominatim' default_geocoder = 'Nominatim'
@ -23,7 +30,7 @@ location_db = 'location.json'
# TODO will be removed eventualy later # TODO will be removed eventualy later
# location_db = '{}/location.json'.format(application_directory) # location_db = '{}/location.json'.format(application_directory)
# Dozo installation directory. # Ordigi installation directory.
script_directory = path.dirname(path.dirname(path.abspath(__file__))) script_directory = path.dirname(path.dirname(path.abspath(__file__)))
#: Accepted language in responses from MapQuest #: Accepted language in responses from MapQuest
@ -32,4 +39,4 @@ accepted_language = 'en'
# check python version, required in filesystem.py to trigger appropriate method # check python version, required in filesystem.py to trigger appropriate method
python_version = version_info.major python_version = version_info.major
CONFIG_FILE = '%s/config.ini' % application_directory CONFIG_FILE = f'{application_directory}/ordigi.conf'

View File

@ -1,5 +1,5 @@
""" """
Methods for interacting with information Dozo caches about stored media. Methods for interacting with database files
""" """
from builtins import map from builtins import map
from builtins import object from builtins import object
@ -12,23 +12,17 @@ from math import radians, cos, sqrt
from shutil import copyfile from shutil import copyfile
from time import strftime from time import strftime
from dozo import constants from ordigi import constants
class Db(object): class Db(object):
"""A class for interacting with the JSON files created by Dozo.""" """A class for interacting with the JSON files database."""
def __init__(self, target_dir): def __init__(self, target_dir):
# verify that the application directory (~/.dozo) exists,
# else create it
# if not os.path.exists(constants.application_directory):
# os.makedirs(constants.application_directory)
# Create dir for target database # Create dir for target database
dirname = os.path.join(target_dir, '.dozo') dirname = os.path.join(target_dir, '.ordigi')
# Legacy dir
# dirname = constants.application_directory
if not os.path.exists(dirname): if not os.path.exists(dirname):
try: try:

View File

@ -14,12 +14,12 @@ import shutil
import time import time
from datetime import datetime, timedelta from datetime import datetime, timedelta
from dozo import constants from ordigi import constants
from dozo import geolocation from ordigi import geolocation
from dozo.media.media import get_media_class, get_all_subclasses from ordigi.media.media import get_media_class, get_all_subclasses
from dozo.media.photo import Photo from ordigi.media.photo import Photo
from dozo.summary import Summary from ordigi.summary import Summary
class FileSystem(object): class FileSystem(object):
@ -129,7 +129,7 @@ class FileSystem(object):
# Create a list of compiled regular expressions to match against the file path # Create a list of compiled regular expressions to match against the file path
compiled_regex_list = [re.compile(regex) for regex in exclude_regex_list] compiled_regex_list = [re.compile(regex) for regex in exclude_regex_list]
for dirname, dirnames, filenames in os.walk(path): for dirname, dirnames, filenames in os.walk(path):
if dirname == os.path.join(path, '.dozo'): if dirname == os.path.join(path, '.ordigi'):
continue continue
for filename in filenames: for filename in filenames:
# If file extension is in `extensions` # If file extension is in `extensions`
@ -535,7 +535,7 @@ class FileSystem(object):
subdirs = '' subdirs = ''
for dirname, dirnames, filenames, level in self.walklevel(path, for dirname, dirnames, filenames, level in self.walklevel(path,
self.max_deep): self.max_deep):
if dirname == os.path.join(path, '.dozo'): if dirname == os.path.join(path, '.ordigi'):
continue continue
subdirs = os.path.join(subdirs, os.path.basename(dirname)) subdirs = os.path.join(subdirs, os.path.basename(dirname))
@ -675,7 +675,7 @@ class FileSystem(object):
has_errors = False has_errors = False
path = self.check_path(path) path = self.check_path(path)
for dirname, dirnames, filenames, level in self.walklevel(path, None): for dirname, dirnames, filenames, level in self.walklevel(path, None):
if dirname == os.path.join(path, '.dozo'): if dirname == os.path.join(path, '.ordigi'):
continue continue
if dirname.find('similar_to') == 0: if dirname.find('similar_to') == 0:
continue continue
@ -738,7 +738,7 @@ class FileSystem(object):
has_errors = False has_errors = False
path = self.check_path(path) path = self.check_path(path)
for dirname, dirnames, filenames, level in self.walklevel(path, None): for dirname, dirnames, filenames, level in self.walklevel(path, None):
if dirname == os.path.join(path, '.dozo'): if dirname == os.path.join(path, '.ordigi'):
continue continue
if dirname.find('similar_to') == 0: if dirname.find('similar_to') == 0:
continue continue

View File

@ -8,8 +8,8 @@ import geopy
from geopy.geocoders import Nominatim from geopy.geocoders import Nominatim
import logging import logging
from dozo import constants from ordigi import constants
from dozo.config import load_config, get_geocoder from ordigi.config import load_config, get_geocoder
__KEY__ = None __KEY__ = None
__DEFAULT_LOCATION__ = 'Unknown Location' __DEFAULT_LOCATION__ = 'Unknown Location'

View File

@ -1,6 +1,6 @@
""" """
The audio module contains classes specifically for dealing with audio files. The audio module contains classes specifically for dealing with audio files.
The :class:`Audio` class inherits from the :class:`~dozo.media.Media` The :class:`Audio` class inherits from the :class:`~ordigi.media.Media`
class. class.
.. moduleauthor:: Jaisen Mathai <jaisen@jmathai.com> .. moduleauthor:: Jaisen Mathai <jaisen@jmathai.com>

View File

@ -1,7 +1,7 @@
""" """
Base :class:`Media` class for media objects that are tracked by Dozo. Base :class:`Media` class for media objects
The Media class provides some base functionality used by all the media types. The Media class provides some base functionality used by all the media types.
Sub-classes (:class:`~dozo.media.Audio`, :class:`~dozo.media.Photo`, and :class:`~dozo.media.Video`). Sub-classes (:class:`~ordigi.media.Audio`, :class:`~ordigi.media.Photo`, and :class:`~ordigi.media.Video`).
""" """
import mimetypes import mimetypes
@ -12,7 +12,7 @@ import logging
# load modules # load modules
from dateutil.parser import parse from dateutil.parser import parse
import re import re
from dozo.exiftool import ExifTool, ExifToolCaching from ordigi.exiftool import ExifTool, ExifToolCaching
class Media(): class Media():

View File

@ -6,10 +6,10 @@ from pathlib import Path
import shutil import shutil
import tempfile import tempfile
from dozo import config from ordigi import config
from dozo.exiftool import _ExifToolProc from ordigi.exiftool import _ExifToolProc
DOZO_PATH = Path(__file__).parent.parent ORDIGI_PATH = Path(__file__).parent.parent
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def reset_singletons(): def reset_singletons():
@ -18,8 +18,8 @@ def reset_singletons():
def copy_sample_files(): def copy_sample_files():
src_path = tempfile.mkdtemp(prefix='dozo-src') src_path = tempfile.mkdtemp(prefix='ordigi-src')
paths = Path(DOZO_PATH, 'samples/test_exif').glob('*') paths = Path(ORDIGI_PATH, 'samples/test_exif').glob('*')
file_paths = [x for x in paths if x.is_file()] file_paths = [x for x in paths if x.is_file()]
for file_path in file_paths: for file_path in file_paths:
source_path = Path(src_path, file_path.name) source_path = Path(src_path, file_path.name)
@ -30,7 +30,7 @@ def copy_sample_files():
@pytest.fixture(scope="module") @pytest.fixture(scope="module")
def conf_path(): def conf_path():
tmp_path = tempfile.mkdtemp(prefix='dozo-') tmp_path = tempfile.mkdtemp(prefix='ordigi-')
conf = RawConfigParser() conf = RawConfigParser()
conf['Path'] = { conf['Path'] = {
'day_begins': '4', 'day_begins': '4',
@ -40,7 +40,7 @@ def conf_path():
conf['Geolocation'] = { conf['Geolocation'] = {
'geocoder': 'Nominatium' 'geocoder': 'Nominatium'
} }
conf_path = Path(tmp_path, "dozo.conf") conf_path = Path(tmp_path, "ordigi.conf")
config.write(conf_path, conf) config.write(conf_path, conf)
yield conf_path yield conf_path

View File

@ -4,7 +4,7 @@ import shutil
import tempfile import tempfile
from unittest import mock from unittest import mock
from dozo import config from ordigi import config
# Helpers # Helpers
import random import random

View File

@ -2,7 +2,7 @@ import pytest
CONTENT = "content" CONTENT = "content"
class TestDozo: class TestOrdigi:
@pytest.mark.skip() @pytest.mark.skip()
def test__sort(self): def test__sort(self):
assert 0 assert 0

View File

@ -1,8 +1,8 @@
import json import json
import pytest import pytest
import dozo.exiftool import ordigi.exiftool
from dozo.exiftool import get_exiftool_path from ordigi.exiftool import get_exiftool_path
TEST_FILE_ONE_KEYWORD = "samples/images/wedding.jpg" TEST_FILE_ONE_KEYWORD = "samples/images/wedding.jpg"
TEST_FILE_BAD_IMAGE = "samples/images/badimage.jpeg" TEST_FILE_BAD_IMAGE = "samples/images/badimage.jpeg"
@ -103,86 +103,86 @@ if exiftool is None:
def test_get_exiftool_path(): def test_get_exiftool_path():
exiftool = dozo.exiftool.get_exiftool_path() exiftool = ordigi.exiftool.get_exiftool_path()
assert exiftool is not None assert exiftool is not None
def test_version(): def test_version():
exif = dozo.exiftool.ExifTool(TEST_FILE_ONE_KEYWORD) exif = ordigi.exiftool.ExifTool(TEST_FILE_ONE_KEYWORD)
assert exif.version is not None assert exif.version is not None
assert isinstance(exif.version, str) assert isinstance(exif.version, str)
def test_read(): def test_read():
exif = dozo.exiftool.ExifTool(TEST_FILE_ONE_KEYWORD) exif = ordigi.exiftool.ExifTool(TEST_FILE_ONE_KEYWORD)
assert exif.data["File:MIMEType"] == "image/jpeg" assert exif.data["File:MIMEType"] == "image/jpeg"
assert exif.data["EXIF:ISO"] == 160 assert exif.data["EXIF:ISO"] == 160
assert exif.data["IPTC:Keywords"] == "wedding" assert exif.data["IPTC:Keywords"] == "wedding"
def test_singleton(): def test_singleton():
exif1 = dozo.exiftool.ExifTool(TEST_FILE_ONE_KEYWORD) exif1 = ordigi.exiftool.ExifTool(TEST_FILE_ONE_KEYWORD)
exif2 = dozo.exiftool.ExifTool(TEST_FILE_MULTI_KEYWORD) exif2 = ordigi.exiftool.ExifTool(TEST_FILE_MULTI_KEYWORD)
assert exif1._process.pid == exif2._process.pid assert exif1._process.pid == exif2._process.pid
def test_pid(): def test_pid():
exif1 = dozo.exiftool.ExifTool(TEST_FILE_ONE_KEYWORD) exif1 = ordigi.exiftool.ExifTool(TEST_FILE_ONE_KEYWORD)
assert exif1.pid == exif1._process.pid assert exif1.pid == exif1._process.pid
def test_exiftoolproc_process(): def test_exiftoolproc_process():
exif1 = dozo.exiftool.ExifTool(TEST_FILE_ONE_KEYWORD) exif1 = ordigi.exiftool.ExifTool(TEST_FILE_ONE_KEYWORD)
assert exif1._exiftoolproc.process is not None assert exif1._exiftoolproc.process is not None
def test_exiftoolproc_exiftool(): def test_exiftoolproc_exiftool():
exif1 = dozo.exiftool.ExifTool(TEST_FILE_ONE_KEYWORD) exif1 = ordigi.exiftool.ExifTool(TEST_FILE_ONE_KEYWORD)
assert exif1._exiftoolproc.exiftool == dozo.exiftool.get_exiftool_path() assert exif1._exiftoolproc.exiftool == ordigi.exiftool.get_exiftool_path()
def test_as_dict(): def test_as_dict():
exif1 = dozo.exiftool.ExifTool(TEST_FILE_ONE_KEYWORD) exif1 = ordigi.exiftool.ExifTool(TEST_FILE_ONE_KEYWORD)
exifdata = exif1.asdict() exifdata = exif1.asdict()
assert exifdata["XMP:TagsList"] == "wedding" assert exifdata["XMP:TagsList"] == "wedding"
def test_as_dict_normalized(): def test_as_dict_normalized():
exif1 = dozo.exiftool.ExifTool(TEST_FILE_ONE_KEYWORD) exif1 = ordigi.exiftool.ExifTool(TEST_FILE_ONE_KEYWORD)
exifdata = exif1.asdict(normalized=True) exifdata = exif1.asdict(normalized=True)
assert exifdata["xmp:tagslist"] == "wedding" assert exifdata["xmp:tagslist"] == "wedding"
assert "XMP:TagsList" not in exifdata assert "XMP:TagsList" not in exifdata
def test_as_dict_no_tag_groups(): def test_as_dict_no_tag_groups():
exif1 = dozo.exiftool.ExifTool(TEST_FILE_ONE_KEYWORD) exif1 = ordigi.exiftool.ExifTool(TEST_FILE_ONE_KEYWORD)
exifdata = exif1.asdict(tag_groups=False) exifdata = exif1.asdict(tag_groups=False)
assert exifdata["TagsList"] == "wedding" assert exifdata["TagsList"] == "wedding"
def test_json(): def test_json():
exif1 = dozo.exiftool.ExifTool(TEST_FILE_ONE_KEYWORD) exif1 = ordigi.exiftool.ExifTool(TEST_FILE_ONE_KEYWORD)
exifdata = json.loads(exif1.json()) exifdata = json.loads(exif1.json())
assert exifdata[0]["XMP:TagsList"] == "wedding" assert exifdata[0]["XMP:TagsList"] == "wedding"
def test_str(): def test_str():
exif1 = dozo.exiftool.ExifTool(TEST_FILE_ONE_KEYWORD) exif1 = ordigi.exiftool.ExifTool(TEST_FILE_ONE_KEYWORD)
assert "file: " in str(exif1) assert "file: " in str(exif1)
assert "exiftool: " in str(exif1) assert "exiftool: " in str(exif1)
def test_exiftool_terminate(): def test_exiftool_terminate():
""" Test that exiftool process is terminated when exiftool.terminate() is called """ """ Test that exiftool process is terminated when exiftool.terminate() is called """
exif1 = dozo.exiftool.ExifTool(TEST_FILE_ONE_KEYWORD) exif1 = ordigi.exiftool.ExifTool(TEST_FILE_ONE_KEYWORD)
assert dozo.exiftool.exiftool_is_running() assert ordigi.exiftool.exiftool_is_running()
dozo.exiftool.terminate_exiftool() ordigi.exiftool.terminate_exiftool()
assert not dozo.exiftool.exiftool_is_running() assert not ordigi.exiftool.exiftool_is_running()
# verify we can create a new instance after termination # verify we can create a new instance after termination
exif2 = dozo.exiftool.ExifTool(TEST_FILE_ONE_KEYWORD) exif2 = ordigi.exiftool.ExifTool(TEST_FILE_ONE_KEYWORD)
assert exif2.asdict()["IPTC:Keywords"] == "wedding" assert exif2.asdict()["IPTC:Keywords"] == "wedding"

View File

@ -8,11 +8,11 @@ from sys import platform
from time import sleep from time import sleep
from .conftest import copy_sample_files from .conftest import copy_sample_files
from dozo import constants from ordigi import constants
from dozo.database import Db from ordigi.database import Db
from dozo.filesystem import FileSystem from ordigi.filesystem import FileSystem
from dozo.media.media import Media from ordigi.media import Media
from dozo.exiftool import ExifToolCaching, exiftool_is_running, terminate_exiftool from ordigi.exiftool import ExifToolCaching, exiftool_is_running, terminate_exiftool
@pytest.mark.skip() @pytest.mark.skip()

View File

@ -6,14 +6,12 @@ import shutil
import tempfile import tempfile
from .conftest import copy_sample_files from .conftest import copy_sample_files
from dozo import constants from ordigi import constants
from dozo.media.media import Media from ordigi.media import Media
from dozo.media.audio import Audio from ordigi.images import Images
from dozo.media.photo import Photo from ordigi.exiftool import ExifTool, ExifToolCaching
from dozo.media.video import Video
from dozo.exiftool import ExifTool, ExifToolCaching
DOZO_PATH = Path(__file__).parent.parent ORDIGI_PATH = Path(__file__).parent.parent
CACHING = True CACHING = True
class TestMetadata: class TestMetadata: