Skip to content

Commit

Permalink
Port to non-MacOS platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdkon committed Apr 1, 2023
1 parent 2c4d0f4 commit 5473dbd
Show file tree
Hide file tree
Showing 50 changed files with 771 additions and 365 deletions.
5 changes: 4 additions & 1 deletion osxphotos/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@
from .personinfo import PersonInfo
from .photoexporter import ExportOptions, ExportResults, PhotoExporter
from .photoinfo import PhotoInfo
from .photosalbum import PhotosAlbum, PhotosAlbumPhotoScript
from .photosdb import PhotosDB
from .photosdb._photosdb_process_comments import CommentInfo, LikeInfo
from .phototemplate import PhotoTemplate
from .placeinfo import PlaceInfo
from .queryoptions import QueryOptions
from .scoreinfo import ScoreInfo
from .searchinfo import SearchInfo
from .utils import is_macos

if is_macos:
from .photosalbum import PhotosAlbum, PhotosAlbumPhotoScript

# configure logging; every module in osxphotos should use this logger
logging.basicConfig(
Expand Down
21 changes: 12 additions & 9 deletions osxphotos/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from rich import print
from rich.traceback import install as install_traceback

from osxphotos.utils import is_macos
from osxphotos.debug import (
debug_breakpoint,
debug_watch,
Expand Down Expand Up @@ -44,9 +45,7 @@
print("Debugging enabled", file=sys.stderr)

from .about import about
from .add_locations import add_locations
from .albums import albums
from .batch_edit import batch_edit
from .cli import cli_main
from .cli_commands import (
abort,
Expand All @@ -67,7 +66,6 @@
from .exportdb import exportdb
from .grep import grep
from .help import help
from .import_cli import import_cli
from .info import info
from .install_uninstall_run import install, run, uninstall
from .keywords import keywords
Expand All @@ -76,19 +74,24 @@
from .list import _list_libraries, list_libraries
from .orphans import orphans
from .persons import persons
from .photo_inspect import photo_inspect
from .places import places
from .query import query
from .repl import repl
from .show_command import show
from .snap_diff import diff, snap
from .sync import sync
from .theme import theme
from .timewarp import timewarp
from .tutorial import tutorial
from .uuid import uuid
from .version import version

if is_macos:
from .add_locations import add_locations
from .batch_edit import batch_edit
from .import_cli import import_cli
from .photo_inspect import photo_inspect
from .query import query
from .show_command import show
from .sync import sync
from .timewarp import timewarp
from .uuid import uuid

install_traceback()

__all__ = [
Expand Down
7 changes: 5 additions & 2 deletions osxphotos/cli/add_locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
import datetime

import click
import photoscript

import osxphotos
from osxphotos.queryoptions import IncompatibleQueryOptions, query_options_from_kwargs
from osxphotos.utils import pluralize
from osxphotos.utils import assert_macos, pluralize

from .cli_params import QUERY_OPTIONS, THEME_OPTION, TIMESTAMP_OPTION, VERBOSE_OPTION
from .click_rich_echo import rich_click_echo as echo
Expand All @@ -18,6 +17,10 @@
from .rich_progress import rich_progress
from .verbose import get_verbose_console, verbose_print

assert_macos()

import photoscript


def get_location(
photos: list[osxphotos.PhotoInfo], idx: int, window: datetime.timedelta
Expand Down
6 changes: 5 additions & 1 deletion osxphotos/cli/batch_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@
import sys

import click
import photoscript

import osxphotos
from osxphotos.phototemplate import RenderOptions
from osxphotos.sqlitekvstore import SQLiteKVStore
from osxphotos.utils import assert_macos

assert_macos()

import photoscript

from .cli_commands import echo, echo_error, selection_command, verbose
from .kvstore import kvstore
Expand Down
49 changes: 29 additions & 20 deletions osxphotos/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@

from osxphotos._constants import PROFILE_SORT_KEYS
from osxphotos._version import __version__
from osxphotos.utils import is_macos

from .about import about
from .add_locations import add_locations
from .albums import albums
from .batch_edit import batch_edit
from .cli_params import DB_OPTION, DEBUG_OPTIONS, JSON_OPTION, VERSION_OPTION
from .common import OSXPHOTOS_HIDDEN
from .debug_dump import debug_dump
Expand All @@ -24,27 +23,31 @@
from .exportdb import exportdb
from .grep import grep
from .help import help
from .import_cli import import_cli
from .info import info
from .install_uninstall_run import install, run, uninstall
from .keywords import keywords
from .labels import labels
from .list import list_libraries
from .orphans import orphans
from .persons import persons
from .photo_inspect import photo_inspect
from .places import places
from .query import query
from .repl import repl
from .show_command import show
from .snap_diff import diff, snap
from .sync import sync
from .theme import theme
from .timewarp import timewarp
from .tutorial import tutorial
from .uuid import uuid
from .version import version

if is_macos:
from .add_locations import add_locations
from .batch_edit import batch_edit
from .import_cli import import_cli
from .photo_inspect import photo_inspect
from .query import query
from .show_command import show
from .sync import sync
from .timewarp import timewarp
from .uuid import uuid


# Click CLI object & context settings
class CLI_Obj:
Expand Down Expand Up @@ -106,11 +109,9 @@ def at_exit():


# install CLI commands
for command in [
commands = [
about,
add_locations,
albums,
batch_edit,
debug_dump,
diff,
docs_command,
Expand All @@ -120,27 +121,35 @@ def at_exit():
exportdb,
grep,
help,
import_cli,
info,
install,
keywords,
labels,
list_libraries,
orphans,
persons,
photo_inspect,
places,
query,
repl,
run,
show,
snap,
sync,
theme,
timewarp,
tutorial,
uninstall,
uuid,
version,
]:
]

if is_macos:
commands += [
add_locations,
batch_edit,
import_cli,
photo_inspect,
query,
show,
sync,
timewarp,
uuid,
]

for command in commands:
cli_main.add_command(command)
39 changes: 27 additions & 12 deletions osxphotos/cli/darkmode.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@
"""Detect dark mode on MacOS >= 10.14"""
"""Detect dark mode on MacOS >= 10.14 or fake it elsewhere"""

import objc
import Foundation
from osxphotos.utils import is_macos


def theme():
with objc.autorelease_pool():
user_defaults = Foundation.NSUserDefaults.standardUserDefaults()
system_theme = user_defaults.stringForKey_("AppleInterfaceStyle")
return "dark" if system_theme == "Dark" else "light"
if is_macos:
import objc
import Foundation


def is_dark_mode():
return theme() == "dark"
def theme():
with objc.autorelease_pool():
user_defaults = Foundation.NSUserDefaults.standardUserDefaults()
system_theme = user_defaults.stringForKey_("AppleInterfaceStyle")
return "dark" if system_theme == "Dark" else "light"


def is_light_mode():
return theme() == "light"
def is_dark_mode():
return theme() == "dark"


def is_light_mode():
return theme() == "light"
else:
def theme():
return "light"


def is_dark_mode():
return theme() == "dark"


def is_light_mode():
return theme() == "light"
39 changes: 23 additions & 16 deletions osxphotos/cli/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@
from typing import Iterable, List, Optional, Tuple

import click
from osxmetadata import (
MDITEM_ATTRIBUTE_DATA,
MDITEM_ATTRIBUTE_SHORT_NAMES,
OSXMetaData,
Tag,
)
from osxmetadata.constants import _TAGS_NAMES

import osxphotos
from osxphotos._constants import (
Expand Down Expand Up @@ -47,26 +40,37 @@
from osxphotos.debug import is_debug
from osxphotos.exiftool import get_exiftool_path
from osxphotos.export_db import ExportDB, ExportDBInMemory
from osxphotos.fileutil import FileUtil, FileUtilNoOp, FileUtilShUtil
from osxphotos.fileutil import FileUtilMacOS, FileUtilNoOp, FileUtilShUtil
from osxphotos.path_utils import is_valid_filepath, sanitize_filename, sanitize_filepath
from osxphotos.photoexporter import ExportOptions, ExportResults, PhotoExporter
from osxphotos.photoinfo import PhotoInfoNone
from osxphotos.photokit import (
check_photokit_authorization,
request_photokit_authorization,
)
from osxphotos.photosalbum import PhotosAlbum
from osxphotos.phototemplate import PhotoTemplate, RenderOptions
from osxphotos.queryoptions import load_uuid_from_file, query_options_from_kwargs
from osxphotos.uti import get_preferred_uti_extension
from osxphotos.utils import (
format_sec_to_hhmmss,
get_macos_version,
is_macos,
normalize_fs_path,
pluralize,
under_test,
)

if is_macos:
from osxmetadata import (
MDITEM_ATTRIBUTE_DATA,
MDITEM_ATTRIBUTE_SHORT_NAMES,
OSXMetaData,
Tag,
)
from osxmetadata.constants import _TAGS_NAMES

from osxphotos.photokit import (
check_photokit_authorization,
request_photokit_authorization,
)
from osxphotos.photosalbum import PhotosAlbum

from .cli_commands import logger
from .cli_params import (
DB_ARGUMENT,
Expand Down Expand Up @@ -1110,7 +1114,10 @@ def export(

verbose(f"osxphotos version: {__version__}")
verbose(f"Python version: {sys.version}")
verbose(f"Platform: {platform.platform()}, {'.'.join(get_macos_version())}")
if is_macos:
verbose(f"Platform: {platform.platform()}, {'.'.join(get_macos_version())}")
else:
verbose(f"Platform: {platform.platform()}")
verbose(f"Verbose level: {verbose_flag}")

# validate options
Expand Down Expand Up @@ -1324,7 +1331,7 @@ def export(
if ramdb
else ExportDB(dbfile=export_db_path, export_dir=dest)
)
fileutil = FileUtilShUtil if alt_copy else FileUtil
fileutil = FileUtilShUtil if alt_copy or not is_macos else FileUtilMacOS

if verbose:
if export_db.was_created:
Expand Down Expand Up @@ -1711,7 +1718,7 @@ def export_photo(
keyword_template=None,
description_template=None,
export_db=None,
fileutil=FileUtil,
fileutil=FileUtilShUtil,
dry_run=None,
touch_file=None,
edited_suffix="_edited",
Expand Down
Loading

0 comments on commit 5473dbd

Please sign in to comment.