Skip to content
Permalink
Browse files

Fix some farmware bugs

  • Loading branch information...
gabrielburnworth authored and ConnorRigby committed Jul 11, 2019
1 parent e46ac66 commit 3b118dade466f785bc94c7751c311fcc3dab01c0
@@ -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

@@ -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
@@ -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

_ ->
@@ -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.")
@@ -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),
@@ -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

@@ -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,
@@ -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

0 comments on commit 3b118da

Please sign in to comment.
You can’t perform that action at this time.