Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port to non-MacOS platforms #1026

Merged
merged 6 commits into from
May 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion osxphotos/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
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 .phototables import PhotoTables
Expand All @@ -25,6 +24,10 @@
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
19 changes: 11 additions & 8 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 .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
45 changes: 27 additions & 18 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 .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,
show,
sync,
timewarp,
uuid,
]

for command in commands:
cli_main.add_command(command)
5 changes: 5 additions & 0 deletions osxphotos/cli/cli_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import click
import contextlib
from textwrap import dedent

from ..utils import is_macos
from .common import OSXPHOTOS_HIDDEN, print_version
from .param_types import *

Expand Down Expand Up @@ -642,6 +644,9 @@ def _add_options(wrapped):
),
}

if not is_macos:
del _QUERY_PARAMETERS_DICT["--selected"]


def QUERY_OPTIONS(
wrapped=None, *, exclude: list[str] | None = None
Expand Down
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"
41 changes: 24 additions & 17 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 @@ -851,7 +855,6 @@ def export(
retry,
save_config,
screenshot,
selected,
selfie,
shared,
sidecar,
Expand Down Expand Up @@ -883,6 +886,7 @@ def export(
verbose_flag,
xattr_template,
year,
selected=False, # Isn't provided on unsupported platforms
# debug, # debug, watch, breakpoint handled in cli/__init__.py
# watch,
# breakpoint,
Expand Down Expand Up @@ -1111,7 +1115,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 @@ -1325,7 +1332,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 @@ -1713,7 +1720,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