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

delete_file() does not delete file #157

Closed
n2o opened this issue Jul 5, 2023 · 9 comments
Closed

delete_file() does not delete file #157

n2o opened this issue Jul 5, 2023 · 9 comments

Comments

@n2o
Copy link

n2o commented Jul 5, 2023

Your system
Raspberry Pi 4

What version of Python are you using?
python 3.9.2

What version of libgphoto2 have you installed?

How have you installed (or attempted to install) python-gphoto2?
Yes, installed version 2.3.4 via pip

Your problem
As far as I can see, there is no possibility to call the function capture-image-and-download. So I want to take a picture, download it and delete it afterwards. But when I call file_delete() as in your example, nothing happens.

That's the relevant function. Taking picture, setting settings etc. works as expected, but the file_delete()-function does simply do nothing and return None.

I am using a Sony a6500 camera.

        file_path = CAMERA.capture(gp.GP_CAPTURE_IMAGE)
        target = os.path.join(BILDER_PI, f"{timestamp}.jpg")
        camera_file = CAMERA.file_get(
            file_path.folder, file_path.name, gp.GP_FILE_TYPE_NORMAL)
        camera_file.save(target)
        CAMERA.file_delete(file_path.folder, file_path.name)

I initialize the camera with this code:

def init_camera() -> gp.Camera:
    while True:
        try:
            cam: gp.Camera = gp.check_result(gp.gp_camera_new())
            gp.check_result(gp.gp_camera_init(cam))
        except gp.GPhoto2Error as ex:
            if ex.code == gp.GP_ERROR_MODEL_NOT_FOUND:
                log.error(
                    "Could not find camera")
                time.sleep(2)
                continue
            raise
        return cam

Do you have any ideas on this?

Thanks!

@n2o
Copy link
Author

n2o commented Jul 5, 2023

Also, I tried your list_files-Function to see the local files on the camera, but this always returns an empty array.

def list_files(camera, path="/"):
    result = []
    # get files
    for name, value in camera.folder_list_files(path):
        result.append(os.path.join(path, name))
    # read folders
    folders = []
    for name, value in camera.folder_list_folders(path):
        folders.append(name)
    # recurse over subfolders
    for name in folders:
        result.extend(list_files(camera, os.path.join(path, name)))
    return result

@jim-easterbrook
Copy link
Owner

Very strange. I have no experience with Sony cameras, but I would expect this to work. Camera.file_delete isn't expected to return anything - it should raise an exception if gp_camera_file_delete (which it calls) returns an error. I assume by "nothing happens" you mean the image file remains on the camera SD card.

Check you have libusb1 installed - libusb0 is known to be problematic with some cameras. Other than that I have nothing to suggest.

BTW you can find out what version of libgphoto2 you are using with python -m gphoto2.

@jim-easterbrook
Copy link
Owner

PS Do you set the camera capture target (i.e. SD card or RAM) before calling list_files? I don't know if it matters or not, but it might be worth checking.

@n2o n2o changed the title Delete file does nothing Delete file does not delete file Jul 5, 2023
@n2o n2o changed the title Delete file does not delete file delete_file() does not delete file Jul 5, 2023
@n2o
Copy link
Author

n2o commented Jul 5, 2023

Hi, thanks for the reply. Yes, it simply does not delete the file, I changed the title of this issue :-)

The output of python -m gphoto2:

python-gphoto2 version: 2.3.4
libgphoto2 version: ['2.5.27', 'standard camlibs', 'gcc', 'ltdl', 'EXIF']
libgphoto2_port version: ['0.12.0', 'iolibs: disk ptpip serial usb1 usbdiskdirect usbscsi', 'gcc', 'ltdl', 'EXIF', 'USB', 'serial without locking']
python-gphoto2 examples: /usr/local/lib/python3.9/dist-packages/gphoto2/examples

I tried the capturetarget-option, but it seems, that I can't change it 🤔

image

I have libusb-1.0.24-3 installed.

Still images are stored on the camera 😞

@jim-easterbrook
Copy link
Owner

Setting the capture target may only last for the duration of a libgphoto2 session (i.e. until exit() or the camera is reset). But as it's already set to card+sdram then it's probably not the problem.

Libgphoto2 2.5.27 isn't ridiculously old (released Feb 2021). The release notes for 2.5.28 include "Sony: mark all widgets as read-write again, read-only logic was not 100% correct" which might explain your capture target setting problem. I can't find anything relevant to deleting pictures though.

@jim-easterbrook
Copy link
Owner

Have you tried listing files and deleting files with the gphoto2 command? gphoto2 -v will show which version of libghoto2 it's using - it isn't necessarily the same as used by python-gphoto2.

@n2o
Copy link
Author

n2o commented Jul 5, 2023

Ah, good point. gphoto2 can't even list my files via CLI. Maybe it's just a Sony thing. For my Customer we use Nikon cameras and it works on these cameras. I have no Nikon available currently, which is why I have to work on a Sony camera.

Strange, that this function does not work on a Sony camera.

$ gphoto2 --list-files
There is no file in folder '/'.
$ gphoto2 -v
gphoto2 2.5.27

Copyright (c) 2000-2021 Marcus Meissner and others

gphoto2 comes with NO WARRANTY, to the extent permitted by law. You may
redistribute copies of gphoto2 under the terms of the GNU General Public
License. For more information about these matters, see the files named COPYING.

This version of gphoto2 is using the following software versions and options:
gphoto2         2.5.27         gcc, popt(m), exif, cdk, aa, jpeg, readline
libgphoto2      2.5.27         standard camlibs, gcc, ltdl, EXIF
libgphoto2_port 0.12.0         iolibs: disk ptpip serial usb1 usbdiskdirect usbscsi, gcc, ltdl, EXIF, USB, serial without locking

@n2o
Copy link
Author

n2o commented Aug 10, 2023

Actually it seems like a problem with the Sony camera. I tested it on Nikon cameras, which worked as I expected it. Thanks for your help, so I'm closing this and leaving it with "My Sony a6500 simply does not support this" :-)

@n2o n2o closed this as completed Aug 10, 2023
@jim-easterbrook
Copy link
Owner

Just spotted this comment on a libgphoto2 bug report: "For Sony cameras, in pc control mode there is no folder access. It is only accessible in MTP/PTP mode." It might be relevant.
gphoto/libgphoto2#798

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants