Skip to content

Commit

Permalink
Switch file name to upgrade to match function
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtavis committed Aug 22, 2024
1 parent 66aa5ec commit ba48d1d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 30 deletions.
4 changes: 2 additions & 2 deletions src/scribe_data/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from scribe_data.cli.interactive import start_interactive_mode
from scribe_data.cli.list import list_wrapper
from scribe_data.cli.total import get_total_lexemes
from scribe_data.cli.update import update_cli
from scribe_data.cli.upgrade import upgrade_cli
from scribe_data.cli.version import get_version_message

LIST_DESCRIPTION = "List languages, data types and combinations of each that Scribe-Data can be used for."
Expand Down Expand Up @@ -196,7 +196,7 @@ def main() -> None:
args = parser.parse_args()

if args.upgrade:
update_cli()
upgrade_cli()
return

if not args.command:
Expand Down
51 changes: 23 additions & 28 deletions src/scribe_data/cli/update.py → src/scribe_data/cli/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,80 +20,75 @@
-->
"""

import sys
import os
import shutil
import requests
import tarfile
import subprocess
import sys
import tarfile
from pathlib import Path
from scribe_data.cli.version import get_local_version, get_latest_version

import requests

from scribe_data.cli.version import get_latest_version, get_local_version


def update_cli():
def upgrade():
local_version = get_local_version()
latest_version = get_latest_version()
latest_version = latest_version.split("v")[-1]

pointer = True
if local_version == latest_version:
user_input = input(
f"You are already using the latest Scribe-Data v{latest_version} version.\nDo you want to overwrite upgrade anyway? (y/n): "
)
pointer = False
if user_input.lower() != "y":
print("Update cancelled.")
return
if pointer:
print("You already have the latest version of Scribe-Data.")

if local_version < latest_version:
print(f"Current version: {local_version}")
print(f"Latest version: {latest_version}")
print("Updating Scribe-Data...")

print("Updating Scribe-Data ...")

url = f"https://github.com/scribe-org/Scribe-Data/archive/refs/tags/{latest_version}.tar.gz"
print(f"Downloading Scribe-Data v{latest_version}...")
print(f"Downloading Scribe-Data v{latest_version} ...")
response = requests.get(url)

if response.status_code == 200:
with open(f"Scribe-Data-{latest_version}.tar.gz", "wb") as f:
f.write(response.content)
print(f"Download complete: Scribe-Data-{latest_version}.tar.gz")

print("Extracting files...")
print("Extracting files ...")
temp_dir = Path(f"temp_Scribe-Data-{latest_version}")
with tarfile.open(f"Scribe-Data-{latest_version}.tar.gz", "r:gz") as tar:
tar.extractall(path=temp_dir)

print("Extraction complete.")

print("Updating local files...")
print("Updating local files ...")
extracted_dir = temp_dir / f"Scribe-Data-{latest_version}"
for item in extracted_dir.iterdir():
if item.is_dir():
if (Path.cwd() / item.name).exists():
shutil.rmtree(Path.cwd() / item.name)

shutil.copytree(item, Path.cwd() / item.name)

else:
shutil.copy2(item, Path.cwd())

print("Local files updated successfully.")

print("Cleaning up temporary files...")
print("Cleaning up temporary files ...")
shutil.rmtree(temp_dir)
os.remove(f"Scribe-Data-{latest_version}.tar.gz")
print("Cleanup complete.")

print("Installing the updated version of Scribe-Data locally...")
print("Installing the updated version of Scribe-Data locally ...")
try:
subprocess.check_call([sys.executable, "-m", "pip", "install", "-e", "."])
print("Local installation successful.")

except subprocess.CalledProcessError as e:
print(f"Local installation failed with error: {e}")
print(
"Failed to install the local version of Scribe-Data. Please try manually running 'pip install -e .'"
f"Failed to install the local version of Scribe-Data with error {e}. Please try manually running 'pip install -e .'"
)

print(f"Scribe-Data has been successfully updated to version {latest_version}")
print("Please restart your application to use the updated version.")
else:
print(f"Failed to download the update. Status code: {response.status_code}")
print("Please try again later or update manually.")

print("Update process completed.")

0 comments on commit ba48d1d

Please sign in to comment.