Detect if Python3 is installed before launching PythonPort Genserver

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2021-11-08 12:14:13 +01:00
parent df21729ba0
commit ea276fbe73
4 changed files with 30 additions and 12 deletions

View File

@@ -5,15 +5,23 @@ defmodule Mobilizon.PythonPort do
use Export.Python
@python_path "/usr/bin/python3"
@doc """
Whether Python3 is installed
"""
@spec python_exists? :: boolean
def python_exists? do
File.exists?(python_path())
end
@doc """
## Parameters
- path: directory to include in python path
"""
@spec python_instance(String.t()) :: pid
def python_instance(path) do
python = "/usr/bin/python3"
{:ok, pid} = Python.start(python: python, python_path: path)
{:ok, pid} = Python.start(python: python_path(), python_path: path)
pid
end
@@ -25,4 +33,12 @@ defmodule Mobilizon.PythonPort do
def call_python(pid, module, function, arguments \\ []) do
Python.call(pid, module, function, arguments)
end
@spec python_path :: String.t()
defp python_path do
case get_in(Application.get_env(:mobilizon, __MODULE__), [:path]) do
path when is_binary(path) -> path
nil -> @python_path
end
end
end