Find correct python executable (#1156)

* find correct python executable
For script scrapers using python, both python and python3 are valid depending on the OS and running environment. To save users from having any issues, this change will find the correct executable for them.

Co-authored-by: bnkai <bnkai@users.noreply.github.com>
This commit is contained in:
SpedNSFW
2021-03-03 08:01:01 +11:00
committed by GitHub
parent 1850a2b533
commit bde5d07afb
3 changed files with 26 additions and 1 deletions

View File

@@ -30,6 +30,13 @@ func newScriptScraper(scraper scraperTypeConfig, config config, globalConfig Glo
func (s *scriptScraper) runScraperScript(inString string, out interface{}) error { func (s *scriptScraper) runScraperScript(inString string, out interface{}) error {
command := s.scraper.Script command := s.scraper.Script
if command[0] == "python" || command[0] == "python3" {
executable, err := findPythonExecutable()
if err == nil {
command[0] = executable
}
}
cmd := exec.Command(command[0], command[1:]...) cmd := exec.Command(command[0], command[1:]...)
cmd.Dir = filepath.Dir(s.config.path) cmd.Dir = filepath.Dir(s.config.path)
@@ -184,3 +191,19 @@ func (s *scriptScraper) scrapeMovieByURL(url string) (*models.ScrapedMovie, erro
return &ret, err return &ret, err
} }
func findPythonExecutable() (string, error) {
_, err := exec.LookPath("python3")
if err != nil {
_, err = exec.LookPath("python")
if err != nil {
return "", err
}
return "python", nil
}
return "python3", nil
}

View File

@@ -1,4 +1,5 @@
### 🎨 Improvements ### 🎨 Improvements
* Resolve python executable to `python3` or `python` for python script scrapers.
* Add `url` field to `URLReplace`, and make `queryURLReplace` available when scraping by URL. * Add `url` field to `URLReplace`, and make `queryURLReplace` available when scraping by URL.
* Make logging format consistent across platforms and include full timestamp. * Make logging format consistent across platforms and include full timestamp.
* Remember gallery images view mode. * Remember gallery images view mode.

View File

@@ -85,7 +85,8 @@ script:
- query - query
``` ```
This configuration would execute `python iafdScrape.py query`. Stash will find the correct python executable for your system, either `python` or `python3`. So for example. this configuration could execute `python iafdScrape.py query` or `python3 iafdScrape.py query`.
`python3` will be looked for first and if it's not found, we'll check for `python`. In the case neither are found, you will get an error.
Stash sends data to the script process's `stdin` stream and expects the output to be streamed to the `stdout` stream. Any errors and progress messages should be output to `stderr`. Stash sends data to the script process's `stdin` stream and expects the output to be streamed to the `stdout` stream. Any errors and progress messages should be output to `stderr`.