1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Mix.Pleroma do
17 @cachex_children ["object", "user"]
18 @doc "Common functions to be reused in mix tasks"
20 Pleroma.Config.Holder.save_default()
21 Application.put_env(:phoenix, :serve_endpoints, false, persistent: true)
23 if Pleroma.Config.get(:env) != :test do
24 Application.put_env(:logger, :console, level: :debug)
27 adapter = Application.get_env(:tesla, :adapter)
30 if adapter == Tesla.Adapter.Gun do
36 Enum.each(apps, &Application.ensure_all_started/1)
41 {Pleroma.Config.TransferTask, false},
44 http_children(adapter)
46 cachex_children = Enum.map(@cachex_children, &Pleroma.Application.build_cachex(&1, []))
48 Supervisor.start_link(children ++ cachex_children,
49 strategy: :one_for_one,
50 name: Pleroma.Supervisor
53 if Pleroma.Config.get(:env) not in [:test, :benchmark] do
58 defp pleroma_rebooted? do
59 if Restarter.Pleroma.rebooted?() do
68 Application.load(:pleroma)
71 def get_option(options, opt, prompt, defval \\ nil, defname \\ nil) do
72 Keyword.get(options, opt) || shell_prompt(prompt, defval, defname)
75 def shell_prompt(prompt, defval \\ nil, defname \\ nil) do
76 prompt_message = "#{prompt} [#{defname || defval}] "
80 do: Mix.shell().prompt(prompt_message),
81 else: :io.get_line(prompt_message)
87 shell_prompt(prompt, defval, defname)
98 def shell_yes?(message) do
100 do: Mix.shell().yes?("Continue?"),
101 else: shell_prompt(message, "Continue?") in ~w(Yn Y y)
104 def shell_info(message) do
106 do: Mix.shell().info(message),
107 else: IO.puts(message)
110 def shell_error(message) do
112 do: Mix.shell().error(message),
113 else: IO.puts(:stderr, message)
116 @doc "Performs a safe check whether `Mix.shell/0` is available (does not raise if Mix is not loaded)"
117 def mix_shell?, do: :erlang.function_exported(Mix, :shell, 0)
119 def escape_sh_path(path) do
120 ~S(') <> String.replace(path, ~S('), ~S(\')) <> ~S(')
123 defp http_children(Tesla.Adapter.Gun) do
124 Pleroma.Gun.ConnectionPool.children() ++
125 [{Task, &Pleroma.HTTP.AdapterHelper.Gun.limiter_setup/0}]
128 defp http_children(_), do: []