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

local:///path is causing xml to save to C:\ and triggering permission denied errors #126

Closed
jcormier opened this issue Mar 16, 2020 · 9 comments · Fixed by #128
Closed
Milestone

Comments

@jcormier
Copy link
Contributor

Describe the bug
Running example code using miniconda environment. Camera returns "local:///criticallink_systemgentl.xml;0;0" and harvesters tries to save the xml to the c:/ directory. Tried changing the directory by setting "HARVESTERS_XML_FILE_DIR=c:/Users/jcormier/Documents" but had no effect to reported error

Expected behavior
Expect xml to be saved to cwd() or not saved

Screenshots

(base) C:\Users\jcormier>conda activate gentl_37
(gentl_37) C:\Users\jcormier\Documents>set HARVESTERS_XML_FILE_DIR=c://Users//jcormier//Documents
(gentl_37) C:\Users\jcormier>set PATH=c:\Program Files\Critical Link LLC\Gentle Viewer\bin;%PATH%
(gentl_37) C:\Users\jcormier\Documents>python snap.py
2020-03-16 10:29:48,886 - harvesters - INFO - Added c:\Program Files\Critical Link LLC\Gentle Viewer\bin\GenTL.dll to the CTI file list.
2020-03-16 10:29:48,886 - harvesters - INFO - Discarded the device information list.
2020-03-16 10:29:48,890 - harvesters - INFO - Initialized GenTL Producer, c:\Program Files\Critical Link LLC\Gentle Viewer\bin\GenTL.dll.
2020-03-16 10:29:48,890 - harvesters - INFO - Opened System module, criticallink/gentl.dll.
2020-03-16 10:29:48,891 - harvesters - INFO - Opened Interface module, Simulated.
2020-03-16 10:29:48,894 - harvesters - INFO - Opened Interface module, U3V.
2020-03-16 10:29:49,072 - harvesters - INFO - Updated the device information list.
[(id_='1EF80000050A', vendor='Critical Link LLC', model='MityCAM-3U5MGXS', tl_type='U3V', user_defined_name=None, serial_number='1290', version='1.0')]
2020-03-16 10:29:49,148 - harvesters - INFO - Opened Device module, 1EF80000050A.
2020-03-16 10:29:49,149 - harvesters - INFO - URL: local:///criticallink_systemgentl.xml;0;3075
Traceback (most recent call last):
  File "snap.py", line 26, in <module>
    ia = h.create_image_acquirer(list_index=0)
  File "C:\Users\jcormier\.conda\envs\gentl_37\lib\site-packages\harvesters\core.py", line 2721, in create_image_acquirer
    file_path=file_path
  File "C:\Users\jcormier\.conda\envs\gentl_37\lib\site-packages\harvesters\core.py", line 1486, in __init__
    xml_dir=self._xml_dir
  File "C:\Users\jcormier\.conda\envs\gentl_37\lib\site-packages\harvesters\core.py", line 2491, in _get_port_connected_node_map
    port=port, file_path=file_path, logger=logger, xml_dir=xml_dir
  File "C:\Users\jcormier\.conda\envs\gentl_37\lib\site-packages\harvesters\core.py", line 2419, in _retrieve_file_path
    binary_data=binary_data
  File "C:\Users\jcormier\.conda\envs\gentl_37\lib\site-packages\harvesters\core.py", line 2473, in _save_file
    with open(file_path, mode) as f:
PermissionError: [Errno 13] Permission denied: 'c:///criticallink_systemgentl.xml'
2020-03-16 10:29:49,157 - harvesters - INFO - Started resetting the Harvester object.
2020-03-16 10:29:49,158 - harvesters - INFO - Removed the all CTI file from the list.
2020-03-16 10:29:49,160 - harvesters - INFO - Discarded the device information list.
2020-03-16 10:29:49,160 - harvesters - INFO - Closed Interface module, Simulated.
2020-03-16 10:29:49,162 - harvesters - INFO - Closed Interface module, U3V.
2020-03-16 10:29:50,162 - harvesters - INFO - Closed System module, criticallink/gentl.dll.
2020-03-16 10:29:50,163 - harvesters - INFO - Closed c:\Program Files\Critical Link LLC\Gentle Viewer\bin\GenTL.dll.
2020-03-16 10:29:50,165 - harvesters - INFO - Completed resetting the Harvester object.

Desktop (please complete the following information):

  • OS: Windows 10
  • Python: 3.7
  • Harvester: 1.1.0
  • GenTL Producer: Critical Link
  • Camera: Critical Link
@jcormier
Copy link
Contributor Author

It seems like at one point saving this file was optional. 88151ca

@jcormier
Copy link
Contributor Author

Looks like if the path isn't set, its supposed to create a temp directory, adding print statements to _save_file, mkdtemp seems to be returning None

    print("save_file")
    print(file_dir)  # None
    if file_dir is not None:
        # Create the directory if it didn't exist:
        if not os.path.exists(file_dir):
            os.makedirs(file_dir)
    else:
        file_dir = tempfile.mkdtemp(
            prefix=datetime.now().strftime('%Y%m%d%H%M%S_'),
        )

    print(file_dir)  # None
    #
    print(file_name) # ///criticallink_systemgentl.xml
    file_path = os.path.join(file_dir, file_name)
    print(file_path) # c:///criticallink_systemgentl.xml

if I set HARVESTERS_XML_FILE_DIR=c:/Users/jcormier/Documents, I still get the same output path. Though it would seem our local path from the camera is confusing os.path.join. Should slashes be stripped from a "local:" path?

    print("save_file")
    print(file_dir)  # c://Users//jcormier//Documents
    if file_dir is not None:
        # Create the directory if it didn't exist:
        if not os.path.exists(file_dir):
            os.makedirs(file_dir)
    else:
        file_dir = tempfile.mkdtemp(
            prefix=datetime.now().strftime('%Y%m%d%H%M%S_'),
        )

    print(file_dir)  # c://Users//jcormier//Documents
    #
    print(file_name) # ///criticallink_systemgentl.xml
    file_path = os.path.join(file_dir, file_name)
    print(file_path) # c:///criticallink_systemgentl.xml

@jcormier
Copy link
Contributor Author

Making the following change, allows the script to continue whether HARVESTERS_XML_FILE_DIR is set or not.

file_path = os.path.join(file_dir, file_name.strip("/"))

@jcormier
Copy link
Contributor Author

Though I think it really should be done under if location == 'local': in _retrieve_file_path

possibly related to #121

@jcormier
Copy link
Contributor Author

According to the GenICam standard 1.4, the /// after local should be a valid configuration.

4.1.2.1 Module Register Map (Recommended)
A URL in the form “local:[///]filename.extension;address;length[?SchemaVersion=x.x.x]”
indicates that the XML description file is located in the module’s virtual register map. The
square brackets are optional.

@jcormier
Copy link
Contributor Author

        if location == 'local':
            file_name, address, size = others.split(';')
            address = int(address, 16)
            # Remove optional /// after local: See section 4.1.2 in GenTL v1.4 Standard
            file_name = file_name.lstrip('/')

@kazunarikudo
Copy link
Member

@jcormier Thank you for the feedback. Okay, I will take a look at the detail and merge the suggested changeset into the trunk. However, does not the suggested changeset resolve the permission issue, does it? /Kazunari

@kazunarikudo kazunarikudo added this to the 1.1.1 milestone Mar 16, 2020
@kazunarikudo
Copy link
Member

@jcormier Just to make it sure, could you tell me the location where you launch the Python script? In addition, it would be nice if you could show me the command you executed. Thanks.

@jcormier
Copy link
Contributor Author

That should all be in the original post. The traceback triggered when calling create_image_acquirer(). And the permission denied was because it was trying to write directly to the C:/ drive which it shouldn't be doing. But the local:///path was getting interpreted as access file in the root directory.

@jcormier jcormier changed the title Saving xml to C:\ is causing permission denied errors local:///path is causing xml to save to C:\ and triggering permission denied errors Mar 17, 2020
jcormier added a commit to jcormier/harvesters that referenced this issue Mar 17, 2020
Fixes: genicam#126

According to the GenICam standard 1.4, the /// after local: should be a valid configuration.  But we need to strip it out so it doesn't affect saving the file on the local machine.

4.1.2.1 Module Register Map (Recommended)
A URL in the form “local:[///]filename.extension;address;length[?SchemaVersion=x.x.x]”
indicates that the XML description file is located in the module’s virtual register map. The
square brackets are optional.
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

Successfully merging a pull request may close this issue.

2 participants