Skip to content

Commit

Permalink
small updates to updates
Browse files Browse the repository at this point in the history
  • Loading branch information
CamDavidsonPilon committed Dec 5, 2023
1 parent 2b4fee6 commit ec81641
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 18 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
### Upcoming

- Improvements to OD calibration and pump calibrations. Both now have a `-f` option to provide a json file with calibration data, to skip rerunning data-gathering routines. For example: `pio run pump_calibration -f pump_data.json`.
- Ability to update via our release_archives (available on the github release page) via the UI. To turn this feature off (which is a recommended practice when you expose your UI publically), add an empty file called `DISALLOW_UI_UPLOADS` to the `~/.pioreactor` directory.
-


### 23.11.29

Expand Down
18 changes: 5 additions & 13 deletions pioreactor/background_jobs/stirring.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ def setup(self) -> None:
lgpio.gpio_claim_alert(
self._handle, hardware.HALL_SENSOR_PIN, lgpio.FALLING_EDGE, lgpio.SET_PULL_UP
)
self._edge_callback = lgpio.callback(
self._handle, hardware.HALL_SENSOR_PIN, lgpio.FALLING_EDGE
)
self._edge_callback = lgpio.callback(self._handle, hardware.HALL_SENSOR_PIN, lgpio.FALLING_EDGE)
else:
self._edge_callback = MockCallback()
self._handle = MockHandle()
Expand Down Expand Up @@ -286,9 +284,7 @@ def initialize_rpm_to_dc_lookup(self) -> Callable:
# we scale this by 90% to make sure the PID + prediction doesn't overshoot,
# better to be conservative here.
# equivalent to a weighted average: 0.1 * current + 0.9 * predicted
return lambda rpm: self.duty_cycle - 0.90 * (
self.duty_cycle - (coef * rpm + intercept)
)
return lambda rpm: self.duty_cycle - 0.90 * (self.duty_cycle - (coef * rpm + intercept))
else:
return lambda rpm: self.duty_cycle

Expand Down Expand Up @@ -334,9 +330,7 @@ def kick_stirring_but_avoid_od_reading(self) -> None:
self.kick_stirring()
return

interval_msg = subscribe(
f"pioreactor/{self.unit}/{self.experiment}/od_reading/interval", timeout=3
)
interval_msg = subscribe(f"pioreactor/{self.unit}/{self.experiment}/od_reading/interval", timeout=3)

if interval_msg is not None and interval_msg.payload:
interval = float(interval_msg.payload)
Expand Down Expand Up @@ -407,7 +401,7 @@ def set_target_rpm(self, value: float) -> None:
if self.rpm_calculator is None:
raise ValueError("Can't set target RPM when no RPM measurement is being made")

self.target_rpm = value
self.target_rpm = clamp(0, value, 5_000)
self.set_duty_cycle(self.rpm_to_dc_lookup(self.target_rpm))
self.pid.set_setpoint(self.target_rpm)

Expand Down Expand Up @@ -496,9 +490,7 @@ def start_stirring(
show_default=True,
type=click.FloatRange(0, 1500, clamp=True),
)
@click.option(
"--use-rpm/--ignore-rpm", default=config.getboolean("stirring", "use_rpm", fallback="true")
)
@click.option("--use-rpm/--ignore-rpm", default=config.getboolean("stirring", "use_rpm", fallback="true"))
def click_stirring(target_rpm: float, use_rpm: bool):
"""
Start the stirring of the Pioreactor.
Expand Down
15 changes: 10 additions & 5 deletions pioreactor/cli/pio.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,8 @@ def update_app(

import re

if re.search("release_(.*).zip", source):
if re.search(r"^release_\d{0,2}\.\d{0,2}\.\d{0,2}\w{0,6}\.zip$", source):
# provided a release archive
version_installed = re.search("release_(.*).zip", source).groups()[0] # type: ignore
tmp_release_folder = f"/tmp/release_{version_installed}"
# fmt: off
Expand All @@ -482,34 +483,38 @@ def update_app(
(f"rm -rf {tmp_release_folder}", -3),
(f"unzip {source} -d {tmp_release_folder}", -2),
(f"unzip {tmp_release_folder}/wheels_{version_installed}.zip -d {tmp_release_folder}/wheels", 0),
(f"mv {tmp_release_folder}/pioreactorui_*.tar.gz /tmp/pioreactorui_archive || :", 0.5),
(f"mv {tmp_release_folder}/pioreactorui_*.tar.gz /tmp/pioreactorui_archive || :", 0.5), # move ui folder to be accessed by a `pio update ui`
(f"sudo bash {tmp_release_folder}/pre_update.sh || :", 1),
(f"sudo pip install --force-reinstall --no-index --find-links={tmp_release_folder}/wheels/ {tmp_release_folder}/pioreactor-{version_installed}-py3-none-any.whl", 2),
(f"sudo bash {tmp_release_folder}/update.sh || :", 3),
(f'sudo sqlite3 {config["storage"]["database"]} < {tmp_release_folder}/update.sql || :', 4),
(f"sudo bash {tmp_release_folder}/post_update.sh || :", 5),
(f"rm -rf {tmp_release_folder}", 6),
]
)
# fmt: on

else:
elif source.endswith(".whl"):
# provided a whl
version_installed = source
commands_and_priority.append((f"sudo pip3 install --force-reinstall --no-index {source}", 1))
else:
raise click.Abort("Not a valid source file. Should be either a whl or release archive.")

elif branch is not None:
cleaned_branch = quote(branch)
cleaned_repo = quote(repo)
version_installed = cleaned_branch
commands_and_priority.append(
(f"sudo pip3 install -U --force-reinstall https://github.com/{cleaned_repo}/archive/{cleaned_branch}.zip", 1,) # fmt: skip
(f"sudo pip3 install https://github.com/{cleaned_repo}/archive/{cleaned_branch}.zip", 1,) # fmt: skip
)

else:
try:
tag = get_tag_to_install(repo, version)
except HTTPException:
raise HTTPException(
f"Unable to retrieve information over internet. Is the Pioreactor connected to the internet? LAP is {is_using_local_access_point()}."
f"Unable to retrieve information over internet. Is the Pioreactor connected to the internet? Local access point is {'active' if is_using_local_access_point() else 'inactive'}."
)
response = get(f"https://api.github.com/repos/{repo}/releases/{tag}")
if response.raise_for_status():
Expand Down
8 changes: 8 additions & 0 deletions update_scripts/Upcoming/update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

set -x
set -e

export LC_ALL=C

mv ./update_ui.sh /usr/local/bin # TODO: add update_ui.sh to this folder.

0 comments on commit ec81641

Please sign in to comment.