forked from potsda.mn/mobilizon
Detect if Python3 is installed before launching PythonPort Genserver
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
df21729ba0
commit
ea276fbe73
|
@ -51,7 +51,6 @@ defmodule Mobilizon do
|
||||||
# workers
|
# workers
|
||||||
Guardian.DB.Token.SweeperServer,
|
Guardian.DB.Token.SweeperServer,
|
||||||
ActivityPub.Federator,
|
ActivityPub.Federator,
|
||||||
Mobilizon.PythonWorker,
|
|
||||||
TzWorld.Backend.DetsWithIndexCache,
|
TzWorld.Backend.DetsWithIndexCache,
|
||||||
cachex_spec(:feed, 2500, 60, 60, &Feed.create_cache/1),
|
cachex_spec(:feed, 2500, 60, 60, &Feed.create_cache/1),
|
||||||
cachex_spec(:ics, 2500, 60, 60, &ICalendar.create_cache/1),
|
cachex_spec(:ics, 2500, 60, 60, &ICalendar.create_cache/1),
|
||||||
|
@ -73,6 +72,13 @@ defmodule Mobilizon do
|
||||||
] ++
|
] ++
|
||||||
task_children(@env)
|
task_children(@env)
|
||||||
|
|
||||||
|
children =
|
||||||
|
if Mobilizon.PythonPort.python_exists?() do
|
||||||
|
children ++ [Mobilizon.PythonWorker]
|
||||||
|
else
|
||||||
|
children
|
||||||
|
end
|
||||||
|
|
||||||
ErrorReporting.configure()
|
ErrorReporting.configure()
|
||||||
|
|
||||||
# Only attach the telemetry logger when we aren't in an IEx shell
|
# Only attach the telemetry logger when we aren't in an IEx shell
|
||||||
|
|
|
@ -3,10 +3,8 @@ defmodule Mobilizon.Service.Export.Participants.ODS do
|
||||||
Export a list of participants to ODS
|
Export a list of participants to ODS
|
||||||
"""
|
"""
|
||||||
|
|
||||||
alias Mobilizon.Events
|
alias Mobilizon.{Events, Export, PythonPort, PythonWorker}
|
||||||
alias Mobilizon.Events.Event
|
alias Mobilizon.Events.Event
|
||||||
alias Mobilizon.Export
|
|
||||||
alias Mobilizon.PythonWorker
|
|
||||||
alias Mobilizon.Storage.Repo
|
alias Mobilizon.Storage.Repo
|
||||||
alias Mobilizon.Web.Gettext, as: GettextBackend
|
alias Mobilizon.Web.Gettext, as: GettextBackend
|
||||||
import Mobilizon.Web.Gettext, only: [gettext: 2]
|
import Mobilizon.Web.Gettext, only: [gettext: 2]
|
||||||
|
@ -91,7 +89,7 @@ defmodule Mobilizon.Service.Export.Participants.ODS do
|
||||||
|
|
||||||
@spec dependencies_ok? :: boolean
|
@spec dependencies_ok? :: boolean
|
||||||
def dependencies_ok? do
|
def dependencies_ok? do
|
||||||
PythonWorker.has_module("pyexcel_ods3")
|
PythonPort.python_exists?() && PythonWorker.has_module("pyexcel_ods3")
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec enabled? :: boolean
|
@spec enabled? :: boolean
|
||||||
|
|
|
@ -3,10 +3,8 @@ defmodule Mobilizon.Service.Export.Participants.PDF do
|
||||||
Export a list of participants to PDF
|
Export a list of participants to PDF
|
||||||
"""
|
"""
|
||||||
|
|
||||||
alias Mobilizon.Events
|
alias Mobilizon.{Events, Export, PythonPort, PythonWorker}
|
||||||
alias Mobilizon.Events.Event
|
alias Mobilizon.Events.Event
|
||||||
alias Mobilizon.Export
|
|
||||||
alias Mobilizon.PythonWorker
|
|
||||||
alias Mobilizon.Storage.Repo
|
alias Mobilizon.Storage.Repo
|
||||||
alias Mobilizon.Web.ExportView
|
alias Mobilizon.Web.ExportView
|
||||||
alias Mobilizon.Web.Gettext, as: GettextBackend
|
alias Mobilizon.Web.Gettext, as: GettextBackend
|
||||||
|
@ -105,7 +103,7 @@ defmodule Mobilizon.Service.Export.Participants.PDF do
|
||||||
|
|
||||||
@spec dependencies_ok? :: boolean
|
@spec dependencies_ok? :: boolean
|
||||||
def dependencies_ok? do
|
def dependencies_ok? do
|
||||||
PythonWorker.has_module("weasyprint")
|
PythonPort.python_exists?() && PythonWorker.has_module("weasyprint")
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec enabled? :: boolean
|
@spec enabled? :: boolean
|
||||||
|
|
|
@ -5,15 +5,23 @@ defmodule Mobilizon.PythonPort do
|
||||||
|
|
||||||
use Export.Python
|
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 """
|
@doc """
|
||||||
## Parameters
|
## Parameters
|
||||||
- path: directory to include in python path
|
- path: directory to include in python path
|
||||||
"""
|
"""
|
||||||
@spec python_instance(String.t()) :: pid
|
@spec python_instance(String.t()) :: pid
|
||||||
def python_instance(path) do
|
def python_instance(path) do
|
||||||
python = "/usr/bin/python3"
|
{:ok, pid} = Python.start(python: python_path(), python_path: path)
|
||||||
|
|
||||||
{:ok, pid} = Python.start(python: python, python_path: path)
|
|
||||||
|
|
||||||
pid
|
pid
|
||||||
end
|
end
|
||||||
|
@ -25,4 +33,12 @@ defmodule Mobilizon.PythonPort do
|
||||||
def call_python(pid, module, function, arguments \\ []) do
|
def call_python(pid, module, function, arguments \\ []) do
|
||||||
Python.call(pid, module, function, arguments)
|
Python.call(pid, module, function, arguments)
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue