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

PrinterInterface.select_file() doesn't work with relative paths #2601

Closed
michaelnew opened this issue Apr 20, 2018 · 3 comments
Closed

PrinterInterface.select_file() doesn't work with relative paths #2601

michaelnew opened this issue Apr 20, 2018 · 3 comments
Labels
bug Issue describes a bug done Done but not yet released

Comments

@michaelnew
Copy link
Contributor

michaelnew commented Apr 20, 2018

What were you doing?

I'm writing a plugin that can select prints and start print jobs. I have a path to a local file, i.e.
test_scripts/test1.gcode
and I'm trying to select it and start it printing with
self._printer.select_file("test_scripts/test1.gcode", False, True)
but it fails to select it with InvalidFileLocation

If I use the full path it selects the file and starts the print just fine:
self._printer.select_file("/home/pi/.octoprint/uploads/test_scripts/test1.gcode", False, True)

What did you expect to happen?

The docs show this:
path (str) – The path to select for printing. Either an absolute path or relative path to a local file in the uploads folder or a filename on the printer’s SD card.
so I expected the relative path to just work.

Am I supposed to specify that the path is relative somehow, or does the function just try to interpret a path with a leading / as absolute and a path without / as relative? If relative paths aren't supposed to work they way I think they are, what's the recommended way of getting the path to the uploads folder? Hardcoding obviously isn't a good solution.

What happened instead?

InvalidFileLocation

Did the same happen when running OctoPrint in safe mode?

I'm working inside a plugin, so safe mode is a no-go. I'm not sure of a good way to create a test case without a plugin.

Version of OctoPrint

OctoPrint 1.4.0.dev979+g58f73f3

Operating System running OctoPrint

OctoPi 0.14.0

Printer model & used firmware incl. version

Custom built RepRap monstrosity running Smoothieware.

Browser and version of browser, operating system running browser

Browser: Chromium 65.0.3325.181 (Official Build) Arch Linux (64-bit)
OS: Arch Linux x86_64
Kernel: 4.15.15-1-ARCH

Link to octoprint.log

https://gist.github.com/michaelnew/977bb253e7370ef44e879cc298f184c5

Link to contents of terminal tab or serial.log

Link to contents of Javascript console in the browser

Screenshot(s)/video(s) showing the problem:

I have read the FAQ.

@GitIssueBot
Copy link

Hi @michaelnew,

It looks like there is some information missing from your bug report that will be needed in order to solve the problem. Read the Contribution Guidelines which will provide you with a template to fill out here so that your bug report is ready to be investigated (I promise I'll go away then too!).

If you did not intend to report a bug but wanted to request a feature or brain storm about some kind of development, please take special note of the title format to use as described in the Contribution Guidelines.

Please do not abuse the bug tracker as a support forum - that can be found at discourse.octoprint.org. Go there for any kind of issues with network connectivity, webcam functionality, printer detection or any other kind of such support requests or general questions.

Also make sure you are at the right place - this is the bug tracker of the official version of OctoPrint, not the Raspberry Pi image OctoPi nor any unbundled third party OctoPrint plugins or unofficial versions. Make sure too that you have read through the Frequently Asked Questions and searched the existing tickets for your problem - try multiple search terms please.

I'm marking this one now as needing some more information. Please understand that if you do not provide that information within the next two weeks (until 2018-05-04 21:10 UTC) I'll close this ticket so it doesn't clutter the bug tracker. This is nothing personal, so please just be considerate and help the maintainers solve this problem quickly by following the guidelines linked above. Remember, the less time the devs have to spend running after information on tickets, the more time they have to actually solve problems and add awesome new features. Thank you!

Best regards,
~ Your friendly GitIssueBot

PS: I'm just an automated script, not a human being, so don't expect any replies from me :) Your ticket is read by humans too, I'm just not one of them.

@GitIssueBot GitIssueBot added incomplete Issue template has not been fully filled out, no further processing until fixed triage This issue needs triage and removed incomplete Issue template has not been fully filled out, no further processing until fixed labels Apr 20, 2018
foosel added a commit that referenced this issue Apr 24, 2018
  * properly handle relative paths for selection
  * properly handle absolute paths for recovery data comparison

Fixes #2601
@foosel
Copy link
Member

foosel commented Apr 24, 2018

Am I supposed to specify that the path is relative somehow, or does the function just try to interpret a path with a leading / as absolute and a path without / as relative?

No, the system should detect stuff correctly without you having to do anything special. This is were the magic happens.

What confuses me is that it does so just fine over here on select_file with a relative path (tested with and without leading subfolder) without any InvalidFileLocation errors, but it fails later when trying to actually open the file with an IOError (which I've just fixed in 30a523b). What's the exact stack trace that you get in your plugin?

If relative paths aren't supposed to work they way I think they are, what's the recommended way of getting the path to the uploads folder? Hardcoding obviously isn't a good solution.

self._settings.global_get_basefolder("uploads") should provide you with the upload base folder (note that you need to add the SettingsPlugin mixin for this property to be injected). If you os.path.join that with the file name, you should get what you hard coded for now. That hopefully should work as a work around until I can fix the bug in the next stable release.

@foosel foosel added bug Issue describes a bug done Done but not yet released and removed triage This issue needs triage labels Apr 24, 2018
@foosel foosel added this to the 1.3.9 milestone Apr 24, 2018
@michaelnew
Copy link
Contributor Author

michaelnew commented Apr 24, 2018

Well, I must be going crazy, because the error I'm getting is, in fact, an IOError.

2018-04-24 21:08:04,850 - octoprint.plugin - ERROR - Error while calling plugin print_queue
Traceback (most recent call last):
  File "/home/pi/oprint/local/lib/python2.7/site-packages/OctoPrint-1.4.0.dev979_g58f73f3-py2.7.egg/octoprint/plugin/__init__.py", line 225, in call_plugin
    result = getattr(plugin, method)(*args, **kwargs)
  File "/home/pi/Octoprint-Print-Queue/octoprint_print_queue/__init__.py", line 120, in on_event
    self._printer.select_file("test0.gcode", False, False)
  File "/home/pi/oprint/local/lib/python2.7/site-packages/OctoPrint-1.4.0.dev979_g58f73f3-py2.7.egg/octoprint/server/__init__.py", line 386, in wrapper
    return f(*args, **kwargs)
  File "/home/pi/oprint/local/lib/python2.7/site-packages/OctoPrint-1.4.0.dev979_g58f73f3-py2.7.egg/octoprint/printer/standard.py", line 441, in select_file
    tags=kwargs.get("tags", set()) | {"trigger:printer.select_file"})
  File "/home/pi/oprint/local/lib/python2.7/site-packages/OctoPrint-1.4.0.dev979_g58f73f3-py2.7.egg/octoprint/util/comm.py", line 1133, in selectFile
    self._currentFile = PrintingGcodeFileInformation(filename, offsets_callback=self.getOffsets, current_tool_callback=self.getCurrentTool)
  File "/home/pi/oprint/local/lib/python2.7/site-packages/OctoPrint-1.4.0.dev979_g58f73f3-py2.7.egg/octoprint/util/comm.py", line 3519, in __init__
    raise IOError("File %s does not exist" % self._filename)
IOError: File test0.gcode does not exist

I think I may have been getting InvalidFileLocation while I was playing around with the paths trying to make it work, and since the stack trace is wrapped up in a tornado.access error I didn't notice it changed. Anyway, sorry about that.

I wasn't able to run the maintenance branch because this happened (I'm guessing it's related to different dependency versions), but I was able to cherry pick that commit onto the devel branch and everything works perfectly now. So... 🎉

Also thanks for the help on self._settings.global_get_basefolder("uploads"). I'll use that as a workaround until the fix hits release.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue describes a bug done Done but not yet released
Projects
None yet
Development

No branches or pull requests

3 participants