clean up many compile warnings..

pull/363/head
Connor Rigby 2017-11-04 21:04:00 -07:00
parent 57dff695e9
commit 6b59f458e1
19 changed files with 123 additions and 147 deletions

View File

@ -59,11 +59,11 @@ defmodule Farmbot.BotState.Transport.GenMQTT.Client do
end
def on_publish(["bot", _bot, "from_clients"], msg, state) do
Logger.warn("not implemented yet: #{inspect Poison.decode!(msg) |> Farmbot.CeleryScript.AST.parse()}")
Logger.warn("not implemented yet: #{inspect Poison.decode!(msg) |> Farmbot.CeleryScript.AST.decode()}")
msg
|> Poison.decode!()
|> Farmbot.CeleryScript.AST.parse()
|> Farmbot.CeleryScript.VirtualMachine.execute()
|> Farmbot.CeleryScript.AST.decode()
|> Farmbot.CeleryScript.execute()
{:ok, state}
end
@ -95,7 +95,7 @@ defmodule Farmbot.BotState.Transport.GenMQTT.Client do
{:noreply, state}
end
defp frontend_topic(bot), do: "bot/#{bot}/from_device"
# defp frontend_topic(bot), do: "bot/#{bot}/from_device"
defp bot_topic(bot), do: "bot/#{bot}/from_clients"
defp sync_topic(bot), do: "bot/#{bot}/sync/#"
defp status_topic(bot), do: "bot/#{bot}/status"

View File

@ -31,7 +31,7 @@ defmodule Farmbot.BotState.Transport.GenMQTT do
{:noreply, [], {internal_state, old_bot_state}}
end
def handle_bot_state_events(events, {%{client: client} = internal_state, old_bot_state}) do
def handle_bot_state_events(events, {%{client: client} = internal_state, _old_bot_state}) do
new_bot_state = List.last(events)
Client.push_bot_state(client, new_bot_state)

View File

@ -10,7 +10,7 @@ defmodule Farmbot.BotState.Transport.HTTP.SocketHandler do
@timeout 60_000
@behaviour :cowboy_websocket_handler
# @behaviour :cowboy_websocket_handler
def init(blah, req, opts) do
conn = Plug.Adapters.Cowboy.Conn.conn(req, :tcp)

View File

@ -0,0 +1,6 @@
defmodule Farmbot.CeleryScript.AST.Arg do
@moduledoc "CeleryScript Argument."
@doc "Verify this arg."
@callback verify(any) :: {:ok, any} | {:error, term}
end

View File

@ -4,87 +4,6 @@ defmodule Farmbot.CeleryScript.AST do
Ast nodes.
"""
defmodule Arg do
@moduledoc "CeleryScript Argument."
@doc "Verify this arg."
@callback verify(any) :: {:ok, any} | {:error, term}
end
defmodule Node do
@moduledoc "CeleryScript Node."
@doc "Decode and validate arguments."
@callback decode_args(map) :: {:ok, map} | {:error, term}
@doc false
defmacro __using__(_) do
quote do
import Farmbot.CeleryScript.AST.Node
@behaviour Farmbot.CeleryScript.AST.Node
# Struct to allow for usage of Elixir Protocols.
defstruct [:ast]
@doc false
def decode_args(args, acc \\ [])
# The AST Decoder comes in as a map. Change it to a Keyword list
# before enumeration.
def decode_args(args, acc) when is_map(args) do
decode_args(Map.to_list(args), acc)
end
def decode_args([{arg_name, val} = arg | rest], acc) do
# if this is an expected argument, there will be a function
# defined that points to the argument type implementation.
# This requires that the Node module has
# `allow_args [<arg_name>]`
if {arg_name, 0} in __MODULE__.module_info(:exports) do
case apply(__MODULE__, arg_name, []).verify(val) do
# if this argument is valid, continue enumeration.
{:ok, decoded} -> decode_args(rest, [{arg_name, decoded} | acc])
{:error, _} = err -> err
end
else
{:error, {:unknown_arg, arg_name}}
end
end
# When we have validated all of the arguments
# Change it back to a map.
def decode_args([], acc) do
{:ok, Map.new(acc)}
end
end
end
@doc "Allow a list of args."
defmacro allow_args(args) do
arg_mod_base = Farmbot.CeleryScript.AST.Arg
args_and_mods = for arg <- args do
mod = Module.concat(arg_mod_base, Macro.camelize(arg |> to_string))
{arg, mod}
end
for {arg, mod} <- args_and_mods do
quote do
# Define this arg, pointing to the module responsible
# For validating it.
@doc false
def unquote(arg)() do
unless Code.ensure_loaded?(unquote(mod)) do
raise CompileError,
description: "Unknown CeleryScript arg: #{unquote(arg)} (#{unquote(mod)})", file: __ENV__.file
end
unquote(mod)
end
end
end
end
end
# AST struct.
defstruct [:kind, :args, :body, :comment]

View File

@ -0,0 +1,73 @@
defmodule Farmbot.CeleryScript.AST.Node do
@moduledoc "CeleryScript Node."
@doc "Decode and validate arguments."
@callback decode_args(map) :: {:ok, map} | {:error, term}
@doc false
defmacro __using__(_) do
quote do
import Farmbot.CeleryScript.AST.Node
@behaviour Farmbot.CeleryScript.AST.Node
# Struct to allow for usage of Elixir Protocols.
defstruct [:ast]
@doc false
def decode_args(args, acc \\ [])
# The AST Decoder comes in as a map. Change it to a Keyword list
# before enumeration.
def decode_args(args, acc) when is_map(args) do
decode_args(Map.to_list(args), acc)
end
def decode_args([{arg_name, val} = arg | rest], acc) do
# if this is an expected argument, there will be a function
# defined that points to the argument type implementation.
# This requires that the Node module has
# `allow_args [<arg_name>]`
if {arg_name, 0} in __MODULE__.module_info(:exports) do
case apply(__MODULE__, arg_name, []).verify(val) do
# if this argument is valid, continue enumeration.
{:ok, decoded} -> decode_args(rest, [{arg_name, decoded} | acc])
{:error, _} = err -> err
end
else
{:error, {:unknown_arg, arg_name}}
end
end
# When we have validated all of the arguments
# Change it back to a map.
def decode_args([], acc) do
{:ok, Map.new(acc)}
end
end
end
@doc "Allow a list of args."
defmacro allow_args(args) do
arg_mod_base = Farmbot.CeleryScript.AST.Arg
args_and_mods = for arg <- args do
mod = Module.concat(arg_mod_base, Macro.camelize(arg |> to_string))
{arg, mod}
end
for {arg, mod} <- args_and_mods do
quote do
# Define this arg, pointing to the module responsible
# For validating it.
@doc false
def unquote(arg)() do
unless Code.ensure_loaded?(unquote(mod)) do
raise CompileError,
description: "Unknown CeleryScript arg: #{unquote(arg)} (#{unquote(mod)})", file: __ENV__.file
end
unquote(mod)
end
end
end
end
end

View File

@ -37,7 +37,7 @@ defmodule Farmbot.CeleryScript.AST.Pretty do
offset = if(indent == 0, do: offset(opts) + 2, else: offset(opts) + indent)
options = offset(opts, offset)
# args = Enum.map(ast.args, fn({k, v}) -> "#{k}=#{format(v, %{pretty: true})}" end) |> Enum.join(", ")
args = Enum.map(ast.args, fn({k, v}) -> "#{k}" end) |> Enum.join(", ")
args = Enum.map(ast.args, fn({k, _v}) -> "#{k}" end) |> Enum.join(", ")
body = if(ast.body == [], do: "[]", else: "\n#{Enum.map(ast.body, fn(sub_ast) -> format(sub_ast, options) end) |> Enum.join("#{spaces(offset)}\n")}\n")
do_ = if(ast.body == [], do: nil, else: "[")
end_ = if(ast.body == [], do: nil, else: "]")

View File

@ -2,4 +2,13 @@ defmodule Farmbot.CeleryScript do
@moduledoc """
CeleryScript is the scripting language that Farmbot OS understands.
"""
alias Farmbot.CeleryScript.AST
@doc "Execute an AST node."
def execute(ast)
def execute(%AST{} = ast) do
end
end

View File

@ -8,7 +8,7 @@ defmodule Farmbot.Firmware.Handler do
Gcodes as parsed by `Farmbot.Firmware.Gcode.Parser`.
"""
@doc "Pid of a firmware implementation."
@typedoc "Pid of a firmware implementation."
@type handler :: pid
@doc "Start a firmware handler."

View File

@ -90,7 +90,7 @@ defmodule Farmbot.HTTP do
@doc "Upload a file to FB storage."
def upload_file(path, meta \\ nil) do
if File.exists?(path) do
GenServer.call(__MODULE__, {:upload_file, path})
GenServer.call(__MODULE__, {:upload_file, path, meta})
else
{:error, "#{path} not found"}
end
@ -123,8 +123,8 @@ defmodule Farmbot.HTTP do
{:reply, res, state}
end
def handle_call({:upload_file, {url, meta}}, _from, %{adapter: adapter} = state) do
res = case @adapter.upload_file(adapter, url, meta || %{x: -1, y: -1, z: -1}) do
def handle_call({:upload_file, {path, meta}}, _from, %{adapter: adapter} = state) do
res = case @adapter.upload_file(adapter, path, meta || %{x: -1, y: -1, z: -1}) do
{:ok, _} = res -> res
{:error, _} = res -> res
end

View File

@ -6,7 +6,7 @@ defmodule Farmbot.HTTP.HTTPoisonAdapter do
use GenServer
alias HTTPoison
alias HTTPoison.{AsyncResponse, AsyncStatus, AsyncHeaders, AsyncChunk, AsyncEnd}
alias Farmbot.HTTP.{Response, Helpers, Error}
alias Farmbot.HTTP.{Response, Helpers}
import Helpers
require Logger
@ -110,7 +110,7 @@ defmodule Farmbot.HTTP.HTTPoisonAdapter do
GenServer.start_link(__MODULE__, [], [])
end
def init(token) do
def init([]) do
state = %State{requests: %{}}
{:ok, state}
end

View File

@ -10,17 +10,17 @@ defmodule Farmbot.HTTP.ImageUploader do
@doc """
Starts the Image Watcher
"""
def start_link(http, opts) do
GenServer.start_link(__MODULE__, http, opts)
def start_link() do
GenServer.start_link(__MODULE__, [], [name: __MODULE__])
end
def init(http) do
def init([]) do
File.rm_rf!(@images_path)
File.mkdir_p!(@images_path)
:fs_app.start(:normal, [])
:fs.subscribe()
Process.flag(:trap_exit, true)
{:ok, %{http: http, uploads: %{}}}
{:ok, %{uploads: %{}}}
end
def handle_info({_pid, {:fs, :file_event}, {path, [:modified, :closed]}}, state) do
@ -48,7 +48,7 @@ defmodule Farmbot.HTTP.ImageUploader do
{path, meta, retries} ->
Logger.warn(">> faile to upload #{path} #{inspect(reason)}. Going to retry.")
Process.sleep(1000 * retries)
new_pid = spawn(__MODULE__, :upload, [state.http, path, meta])
new_pid = spawn(__MODULE__, :upload, [path, meta])
new_uploads =
state
@ -73,9 +73,9 @@ defmodule Farmbot.HTTP.ImageUploader do
end)
end
def upload(http, file_path, meta) do
def upload(file_path, meta) do
Logger.info("Image Watcher trying to upload #{file_path}", type: :busy)
Farmbot.HTTP.upload_file!(http, file_path, meta)
Farmbot.HTTP.upload_file(file_path, meta)
File.rm!(file_path)
Logger.info("Image Watcher uploaded #{file_path}", type: :success)
end

View File

@ -4,22 +4,27 @@ defmodule Farmbot.Repo do
use GenServer
require Logger
@doc "Fetch the current repo."
def current_repo do
GenServer.call(__MODULE__, :current_repo)
end
@doc "Fetch the non current repo."
def other_repo do
GenServer.call(__MODULE__, :other_repo)
end
@doc "Flip the repos."
def flip() do
GenServer.call(__MODULE__, :flip)
end
@doc "Register a diff to be stored until a flip."
def register_sync_cmd(sync_cmd) do
GenServer.call(__MODULE__, {:register_sync_cmd, sync_cmd})
end
@doc false
def start_link(repos) do
GenServer.start_link(__MODULE__, repos, [name: __MODULE__])
end
@ -102,7 +107,7 @@ defmodule Farmbot.Repo do
end
end
defp fix_repo(repo, %{body: nil}) do
defp fix_repo(_repo, %{body: nil}) do
# The delete already failed. Nothing we can do. This object doesn't exist anymore.
:ok
end

View File

@ -7,48 +7,11 @@ defmodule Farmbot.Repo.Sequence do
use Ecto.Schema
import Ecto.Changeset
defmodule CeleryScriptBody do
@moduledoc "Custom Ecto.Type for convirting text to CelecyScript."
@behaviour Ecto.Type
# Cast and Dump will just be forwareded to the JSONType module.
defdelegate cast(data), to: JSONType
defdelegate dump(data), to: JSONType
defdelegate type, to: JSONType
def load(text) do
{:ok, data} = text |> JSONType.load()
res =
Enum.map(data, fn data ->
Farmbot.CeleryScript.AST.parse(data)
end)
{:ok, res}
end
end
defmodule CeleryScriptArgs do
@moduledoc "Custom Ecto.Type for convirting a sequence args to CS args."
@behaviour Ecto.Type
# Cast and Dump will just be forwareded to the JSONType module.
defdelegate cast(data), to: JSONType
defdelegate dump(data), to: JSONType
defdelegate type, to: JSONType
def load(text) do
{:ok, data} = text |> JSONType.load()
res = Farmbot.CeleryScript.AST.parse_args(data)
{:ok, res}
end
end
schema "sequences" do
field(:name, :string)
field(:kind, :string)
field(:args, CeleryScriptArgs)
field(:body, CeleryScriptBody)
field(:args, JSONType)
field(:body, JSONType)
end
use Farmbot.Repo.Syncable

View File

@ -4,7 +4,7 @@ defmodule Farmbot.System do
"""
alias Farmbot.System.ConfigStorage
alias Farmbot.System.Init.Ecto
# alias Farmbot.System.Init.Ecto
error_msg = """
Please configure your `:system_tasks` behaviour!

View File

@ -86,7 +86,7 @@ defmodule Farmbot.Mixfile do
# {:tzdata, "~> 0.1.201601", override: true},
# {:timex, "~> 3.1.13"},
# {:fs, "~> 0.9.1"},
{:fs, "~> 3.4.0"},
{:nerves_uart, "0.1.2"},
{:uuid, "~> 1.1"},
{:cowboy, "~> 1.1"},

View File

@ -17,7 +17,7 @@
"ex_json_schema": {:hex, :ex_json_schema, "0.5.5", "d8d4c3f47b86c9e634e124d518b290dda82a8b94dcc314e45af10042fc369361", [], [], "hexpm"},
"excoveralls": {:hex, :excoveralls, "0.7.2", "f69ede8c122ccd3b60afc775348a53fc8c39fe4278aee2f538f0d81cc5e7ff3a", [], [{:exjsx, ">= 3.0.0", [hex: :exjsx, repo: "hexpm", optional: false]}, {:hackney, ">= 0.12.0", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm"},
"exjsx": {:hex, :exjsx, "4.0.0", "60548841e0212df401e38e63c0078ec57b33e7ea49b032c796ccad8cde794b5c", [], [{:jsx, "~> 2.8.0", [hex: :jsx, repo: "hexpm", optional: false]}], "hexpm"},
"fs": {:hex, :fs, "0.9.2", "ed17036c26c3f70ac49781ed9220a50c36775c6ca2cf8182d123b6566e49ec59", [], [], "hexpm"},
"fs": {:hex, :fs, "3.4.0", "6d18575c250b415b3cad559e6f97a4c822516c7bc2c10bfbb2493a8f230f5132", [], [], "hexpm"},
"gen_mqtt": {:hex, :gen_mqtt, "0.3.1", "6ce6af7c2bcb125d5b4125c67c5ab1f29bcec2638236509bcc6abf510a6661ed", [], [{:vmq_commons, "1.0.0", [hex: :vmq_commons, repo: "hexpm", optional: false]}], "hexpm"},
"gen_stage": {:hex, :gen_stage, "0.12.2", "e0e347cbb1ceb5f4e68a526aec4d64b54ad721f0a8b30aa9d28e0ad749419cbb", [], [], "hexpm"},
"gettext": {:hex, :gettext, "0.13.1", "5e0daf4e7636d771c4c71ad5f3f53ba09a9ae5c250e1ab9c42ba9edccc476263", [], [], "hexpm"},

View File

@ -20,7 +20,7 @@ defmodule Farmbot.Host.Bootstrap.Configurator do
:ignore
end
defp error(field) do
defp error(_field) do
"""
Your environment is not properly configured! You will need to follow the
directions in `config/host/auth_secret_template.exs` before continuing.

View File

@ -45,8 +45,9 @@ defmodule Farmbot.System.ConfigStorage.Migrations.SeedGroups do
defp populate_config_values("settings", group_id) do
create_value(BoolValue, false) |> create_config(group_id, "os_auto_update")
create_value(BoolValue, true) |> create_config(group_id, "first_boot")
create_value(BoolValue, true) |> create_config(group_id, "first_party_farmware")
create_value(BoolValue, true) |> create_config(group_id, "first_boot")
create_value(BoolValue, true) |> create_config(group_id, "first_party_farmware")
create_value(BoolValue, false) |> create_config(group_id, "auto_sync")
create_value(StringValue, nil) |> create_config(group_id, "timezone")
fpf_url = Application.get_env(:farmbot, :farmware)[:first_part_farmware_manifest_url]
create_value(StringValue, fpf_url) |> create_config(group_id, "first_party_farmware_url")