Skip to content

Commit

Permalink
adding ability to update using .sh and .sql
Browse files Browse the repository at this point in the history
  • Loading branch information
CamDavidsonPilon committed Nov 15, 2022
1 parent 0abf4d9 commit a0da3de
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 16 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
### Upcoming
- Fix bug in UI that wasn't letting users update software
- during `pio update --app`, we now check for additional files in the github release that are to be executed. This provides a path of upgrading non-Python things.


### 22.11.2
- Removing `parent` from BackgroundSubJob
- Make thermostat heuristic slightly better
Expand Down
2 changes: 1 addition & 1 deletion pioreactor/actions/pump.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def _pump(
timestamp=current_utc_datetime(),
pump=pump_type,
duration_=1.0,
hz=200.0,
hz=200.0, # is this an okay default?
dc=100.0,
bias_=0,
voltage=-1,
Expand Down
60 changes: 45 additions & 15 deletions pioreactor/cli/pio.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,33 +300,63 @@ def update(ui: bool, app: bool, branch: Optional[str], source: Optional[str]) ->
click.echo("Nothing to do. Specify either --app or --ui.")

if app:
commands_and_priority = []

if source is not None:
version_installed = source
command = f"sudo pip3 install --root-user-action=ignore -U --force-reinstall {source}"
commands_and_priority.append(
(f"sudo pip3 install --root-user-action=ignore -U --force-reinstall {source}", 1)
)

elif branch is not None:
version_installed = branch
command = f"sudo pip3 install --root-user-action=ignore -U --force-reinstall https://github.com/pioreactor/pioreactor/archive/{branch}.zip"
commands_and_priority.append(
(
f"sudo pip3 install --root-user-action=ignore -U --force-reinstall https://github.com/pioreactor/pioreactor/archive/{branch}.zip",
1,
)
)
else:
latest_release_metadata = loads(
get("https://api.github.com/repos/pioreactor/pioreactor/releases/latest").body
)
version_installed = latest_release_metadata["name"]
url_to_get_whl = f"https://github.com/Pioreactor/pioreactor/releases/download/{version_installed}/pioreactor-{version_installed}-py3-none-any.whl"
for asset in latest_release_metadata["assets"]:
if asset["name"].endswith(".whl") and asset["name"].startswith("pioreactor"):
url_to_get_whl = asset["browser_download_url"]
commands_and_priority.append(
(
f'sudo pip3 install --root-user-action=ignore "pioreactor @ {url_to_get_whl}"',
1,
)
)
elif asset["name"] == "update.sh":
url_to_get_sh = asset["browser_download_url"]
commands_and_priority.append((f"sudo bash <(curl -s {url_to_get_sh})", 2))
elif asset["name"] == "update.sql":
url_to_get_sql = asset["browser_download_url"]
commands_and_priority.append(
(
f'sudo sqlite3 {config["storage"]["database"]} < <(curl -s {url_to_get_sql})',
3,
)
)

command = f'sudo pip3 install --root-user-action=ignore "pioreactor @ {url_to_get_whl}"'
for command, _ in sorted(commands_and_priority, key=lambda t: t[1]):
logger.debug(command)
p = subprocess.run(
command,
shell=True,
universal_newlines=True,
stdout=subprocess.DEVNULL,
stderr=subprocess.PIPE,
)
if p.returncode != 0:
logger.error(p.stderr)
# end early
return

p = subprocess.run(
command,
shell=True,
universal_newlines=True,
stdout=subprocess.DEVNULL,
stderr=subprocess.PIPE,
)
if p.returncode == 0:
logger.notice(f"Updated Pioreactor to version {version_installed}.") # type: ignore
else:
logger.error(p.stderr)
logger.notice(f"Updated Pioreactor to version {version_installed}.") # type: ignore

if ui and whoami.am_I_leader():
gitp = "git pull origin master"
Expand Down

0 comments on commit a0da3de

Please sign in to comment.