benstanfish / TimelapsePy

Library for simplifying and automating time lapse photography using a Raspberry Pi and camera. Can also use ffmpeg to convert images to mp4 if desired.
Creative Commons Zero v1.0 Universal
2 stars 1 forks source link

Folders are not being created #3

Open Deses opened 1 year ago

Deses commented 1 year ago
2023-07-30 16:21:03,835 - TimelapsePy - ERROR - Error at division
Traceback (most recent call last):
  File "/home/pi/timelapses/TimelapsePy/timelapse.py", line 60, in <module>
    save_dir = util.get_preferred_path(users.directory_name_for_images,
  File "/home/pi/timelapses/TimelapsePy/tutilities.py", line 122, in get_preferred_path
    path = build_path(os.path.join(os.path.join(os.path.expanduser('~'),'Pictures'), directory_name), iterate_name)
  File "/home/pi/timelapses/TimelapsePy/tutilities.py", line 95, in build_path
    os.mkdir(path)
FileNotFoundError: [Errno 2] No such file or directory: '/home/pi/Pictures/timelapse_images'

That's because in a default headless Pi installation, there are no default folders like Pictures and Downloads. If I create the Pictures folder it works, tho.

I would not hardcode the Pictures folder anyway, for instance I don't want to store the pics there.

Deses commented 1 year ago

I suggest you use

from pathlib import Path
Path("/my/directory").mkdir(parents=True, exist_ok=True)

To create folders.

Also, it would make everything much simpler if the usersettings file asked for the absolute path of the folder, no need for check if USB folder exists, define an external_drive_name variable, and so on.

benstanfish commented 1 year ago

I'll add the ability to specific an absolute path. If that is not provided, I will revert to default paths: first on a user-specified external drive, then locally. I'll also fix the /Pictures and /Videos bug on headless setups. More to come.

Deses commented 1 year ago

I see where the need of an external drive can come in handy, but again a headless Pi without the desktop environment doesn't automatically mount external media, you have to SSH in and mount it manually to your desired folder. That's why I suggested not bothering with that and just let the user manually type the full path.

Here are the changes I made for myself, if you want to take a look: https://github.com/benstanfish/TimelapsePy/commit/39274e05ce84f34194d38fdcd5e397e9571ed6ac

In any way, I'll probably re-add the USB functionality once you do it the way you like it.