Skip to content

Commit

Permalink
Fix some farmware bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielburnworth authored and ConnorRigby committed Jul 11, 2019
1 parent e46ac66 commit 3b118da
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ defmodule FarmbotCeleryScript.Compiler do
compile :take_photo do
# {:execute_script, [], ["take_photo", {:%{}, [], []}]}
quote location: :keep do
FarmbotCeleryScript.SysCalls.execute_script("take_photo", %{})
FarmbotCeleryScript.SysCalls.execute_script("take-photo", %{})
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule FarmbotCore.Asset.FarmwareInstallation.Manifest do
use Ecto.Schema
import Ecto.Changeset
@primary_key false
@acceptable_manifest_version_requirement "2.0.0"
@acceptable_manifest_version "2.0.0"
@acceptable_farmware_tools_version_requirement "2.0.0"

alias FarmbotCore.Project
Expand Down Expand Up @@ -125,16 +125,9 @@ defmodule FarmbotCore.Asset.FarmwareInstallation.Manifest do

defp validate_farmware_manifest_version(%{valid?: false} = change), do: change
defp validate_farmware_manifest_version(changeset) do
req = get_field(changeset, :farmware_manifest_version)
match =
try do
Version.match?(@acceptable_manifest_version_requirement, req)
rescue
Version.InvalidRequirementError -> :invalid_version
end

case match do
true ->
manifest_version = get_field(changeset, :farmware_manifest_version)
case Version.compare(@acceptable_manifest_version, manifest_version) do
:eq ->
changeset

_ ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ defimpl FarmbotCore.AssetWorker, for: FarmbotCore.Asset.FarmwareInstallation do
end

def maybe_update(%FWI{} = installed_fwi, %FWI{} = updated) do
case Version.compare(installed_fwi.manifest.version, updated.manifest.version) do
case Version.compare(installed_fwi.manifest.package_version, updated.manifest.package_version) do
# Installed is newer than remote.
:gt ->
success_log(updated, "up to date.")
Expand Down Expand Up @@ -174,16 +174,16 @@ defimpl FarmbotCore.AssetWorker, for: FarmbotCore.Asset.FarmwareInstallation do
|> File.write(json)
end

def install_farmware_tools(%FWI{manifest: %{farmware_tools_version: version}} = fwi) do
def install_farmware_tools(%FWI{manifest: %{farmware_tools_version_requirement: version}} = fwi) do
install_dir = install_dir(fwi)
File.mkdir_p(Path.join(install_dir, "farmware_tools"))

release_url =
if version == "latest" do
"https://api.github.com/repos/FarmBot-Labs/farmware-tools/releases/latest"
else
"https://api.github.com/repos/FarmBot-Labs/farmware-tools/releases/tags/#{version}"
end
release_url = "https://api.github.com/repos/FarmBot-Labs/farmware-tools/releases/latest"
# if version == "latest" do
# "https://api.github.com/repos/FarmBot-Labs/farmware-tools/releases/latest"
# else
# "https://api.github.com/repos/FarmBot-Labs/farmware-tools/releases/tags/#{version}"
# end

with {:ok, {_commit, zip_url}} <- get_tools_zip_url(release_url),
{:ok, zip_binary} <- get_zip(zip_url),
Expand Down
4 changes: 2 additions & 2 deletions farmbot_core/lib/farmbot_core/bot_state_ng.ex
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ defmodule FarmbotCore.BotStateNG do
end

@doc "Add or update a farmware to state.farmwares"
def add_or_update_farmware(state, _name, %{} = _manifest) do
def add_or_update_farmware(state, name, %{} = manifest) do
# TODO(Connor) finish this.
cs = changeset(state, %{})

new_farmwares =
cs
|> get_field(:process_info)
|> Map.get(:farmwares)
# |> Map.put(name, manifest)
|> Map.put(name, manifest)
put_change(cs, :process_info, %{farmwares: new_farmwares})
end

Expand Down
2 changes: 1 addition & 1 deletion farmbot_core/lib/farmbot_core/farmware_runtime.ex
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ defmodule FarmbotCore.FarmwareRuntime do
)

# Start the plugin.
{cmd, _} = spawn_monitor(MuonTrap, :cmd, [exec, manifest.args, opts])
{cmd, _} = spawn_monitor(MuonTrap, :cmd, [exec, [manifest.args], opts])

state = %State{
cmd: cmd,
Expand Down
2 changes: 1 addition & 1 deletion farmbot_os/lib/farmbot_os/sys_calls/execute_script.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ defmodule FarmbotOS.SysCalls.ExecuteScript do

def lookup(farmware_name) do
case Asset.get_farmware_manifest(farmware_name) do
nil -> {:error, "farmware not installed"}
nil -> {:error, "#{farmware_name} farmware not installed"}
manifest -> {:ok, manifest}
end
end
Expand Down

0 comments on commit 3b118da

Please sign in to comment.