RhetTbull / osxphotos

Python app to work with pictures and associated metadata from Apple Photos on macOS. Also includes a package to provide programmatic access to the Photos library, pictures, and metadata.
MIT License
2.17k stars 100 forks source link

output lines are being broken running from crontab with verbose, timestamp and post-function options #661

Closed oPromessa closed 2 months ago

oPromessa commented 2 years ago

Describe the bug In a combination of running osxphotos with > log.txt 2>&1 from MAC's crontab using verbose, timestamp and post-function output lines are being broken when. Is it maybe post-function?

On vi with line numbers you can see the output...

  37 2022-03-26 20:14:01.328694 -- Loaded options from file
   38 /Users/MSP/Pictures/Pictures/Apps/colibri.toml
   39 2022-03-26 20:14:01.329267 -- osxphotos version 0.47.5
   40 2022-03-26 20:14:01.329718 -- exiftool path: /usr/local/bin/exiftool
   41 2022-03-26 20:14:01.330219 -- Warning: export database '/Users/Shared/Pictures/Logs/.osxphotos_export.db' is in a different directory than export destination '/Volumes/photo-1/Family.Photos'
   42 2022-03-26 20:14:21.505409 -- Using export database
   43 /Users/MSP/Pictures/Pictures/Logs/.osxphotos_export.db
   44 2022-03-26 20:14:21.507023 -- Processing database /Users/Shared/Pictures/iPhoto
   45 Shared Library.photoslibrary/database/photos.db
   46 2022-03-26 20:14:21.508024 -- Processing database /Users/Shared/Pictures/iPhoto
   47 Shared Library.photoslibrary/database/Photos.sqlite
   48 2022-03-26 20:14:21.508381 -- Database locked, creating temporary copy.
(...)
   65 2022-03-26 20:14:49.103487 -- Exporting 84818 photos to
   66 /Volumes/photo-1/Family.Photos...
   67 2022-03-26 20:14:49.129804 -- Exporting P2260341.JPG (P2260341.JPG) as
   68 P2260341.JPG (1/84818)
   69 2022-03-26 20:14:49.598969 -- Skipped up to date file
   70 /Volumes/photo-1/Family.Photos/(...)/P2260341.JPG
   71 2022-03-26 20:14:49.600358 -- Calling post-function post.py::post_touch
(...)
   80 2022-03-26 20:14:49.711429 -- Exporting P8100408.JPG (P8100408.JPG) as
   81 P8100408.JPG (3/84818)
   82 2022-03-26 20:14:49.712125 -- Skipping original version of P8100408.JPG
   83 2022-03-26 20:14:49.713454 -- Exporting edited version of P8100408.JPG

To Reproduce Steps to reproduce the behavior:

  1. What' the full command line you used with osxphotos?
    • The crontab executes a file with the following command line
      osxphotos export "${DSTFOLDER}" --exportdb ${FOLDER}/.osxphotos_export.db --load-config ${WORKFOLDER}/colibri.toml --post-function post.py::post_touch >> ${LOGFILE} 2>&1
    • contents of colibri.toml
      [export]
      cleanup = true
      db = "/Users/Shared/Pictures/iPhoto Shared Library.photoslibrary"
      description_template = "Album:{album,}{newline}Description:{descr,}"
      directory = "{album[/,.|:,.]}"
      #dry_run = true
      exiftool = true
      exiftool_merge_keywords = true
      exiftool_merge_persons = true
      keyword_template = [ "{keyword}", "{label}", "{searchinfo.activity?activity:{searchinfo.activity},}", "{searchinfo.venue_type?venue_type:{searchinfo.venue_type},}", ]
      not_hidden = true
      ramdb = true
      report = "/Users/Shared/Pictures/Logs/colibri.csv"
      retry = 2
      skip_bursts = true
      skip_live = true
      skip_original_if_edited = true
      strip = true
      timestamp = true
      touch_file = true
      update = true
      verbose = true
    • post.py
      
      """ Example function for use with osxphotos export --post-function option """

from osxphotos import PhotoInfo, ExportResults (...)

def post_touch( photo: PhotoInfo, results: ExportResults, verbose: callable, **kwargs): (...)

for filename in results.exported:
    if photo.date.year < 1970:
        touch_date = photo.date.strftime("%Y-%m-%dT%H:%M:%S")
        verbose(f"post_touch: {filename} photo with date {touch_date}")
        print(f"touch -d {touch_date} \"{filename}\"")

3. What was the error output?

**Expected behavior**
As previously was excepting the line per line output. Would it have to do with the `--theme`new feature I'm not using. 

**Screenshots**
N/A

**Desktop (please complete the following information):**
 - OS: 12.3
 - osxphotos version (`osxphotos --version`): 0.47.5

**Additional context**
N/A
RhetTbull commented 2 years ago

This was introduced with the addition of colored output and --theme. I'm using a rich.console.Console to print verbose output instead of click.echo. When the console object detects it's not writing to a terminal, it assumes line width is 80 and wraps texts. I think the preferred behavior should be to never wrap text (that's what \n is for). I'll work on a fix to set the terminal width to a huge number so it never wraps (I already do this for testing as the wrapped text breaks the test suite)

See here: https://github.com/RhetTbull/osxphotos/blob/93de53da5105798fff567c1bf6d032384165380d/osxphotos/cli/verbose.py#L83-L84

RhetTbull commented 2 years ago

I think this is fixed in v0.47.6.

oPromessa commented 1 year ago

Hello there. On version 0.54.4 I'm having a similar issue, but this time without the verbose.

In a combination of running osxphotos with > log.txt 2>&1 from MAC's crontab using verbose, timestamp and post-function output lines are being broken when. Is it maybe post-function?

Command line on the crontab

osxphotos export "${DSTFOLDER}" --exportdb ${FOLDER}/.osxphotos_export.db --load-config ${WORKFOLDER}/colibri.toml >> ${LOGFILE} 2>&1

TOML file being used

[export]
cleanup = true
db = "/Users/Shared/Pictures/iPhoto Shared Library.photoslibrary"
description_template = "Album:{album,}{newline}Description:{descr,}"
directory = "{album|filter(startswith 1|2)[/,.|:,.]}"
exiftool = true
exiftool_merge_keywords = true
exiftool_merge_persons = true
keyword_template = [ "{keyword}", "{label}", "{searchinfo.activity?activity:{searchinfo.activity},}", "{searchinfo.venue_type?venue_type:{searchinfo.venue_type},}", ]
no_progress = true
not_hidden = true
ramdb = true
retry = 2 
skip_bursts = true
skip_live = true
skip_original_if_edited = true
strip = true
timestamp = true
touch_file = true
update = true

output with broken lines.

RhetTbull commented 1 year ago

I'll take a look when I get a chance.

oPromessa commented 2 months ago

No longer using crontab. Closing this issue.