Skip to content

Commit

Permalink
fixing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Edgard Marx committed Apr 9, 2024
1 parent 1685f72 commit a8ed489
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 24 deletions.
36 changes: 22 additions & 14 deletions imr/imr.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@


class IMRRemote:
"""Remote repository class."""

def __init__(self, repo: str, user: str, password: str):
self.repo = repo
self.user = user
self.password = password
self.home = str(Path.home())

def list(self) -> list:
packages = []
"""List models from the remote repository."""
path = ArtifactoryPath(self.repo, auth=(self.user, self.password), auth_type=HTTPBasicAuth)
for package in path.glob("*/*"):
packages.append(str(package).replace(self.repo + "/", ""))
return packages
return [str(package).replace(self.repo + "/", "") for package in path.glob("*/*")]

def push(self, directory: str, package: str, version :str="latest") -> None:
def push(self, directory: str, package: str, version: str = "latest") -> None:
"""Push a local model to the remote repository."""
path = ArtifactoryPath(
self.repo + "/" + package + "/" + version,
auth=(self.user, self.password),
Expand All @@ -31,7 +32,8 @@ def push(self, directory: str, package: str, version :str="latest") -> None:
shutil.make_archive("model", "zip", directory)
path.deploy_file("model.zip")

def pull(self, directory: str, package: str, version :str="latest") -> None:
def pull(self, directory: str, package: str, version: str = "latest") -> None:
"""Pull a remote model to the local repository."""
path = ArtifactoryPath(
self.repo + "/" + package + "/" + version + "/model.zip",
auth=(self.user, self.password),
Expand All @@ -44,7 +46,8 @@ def pull(self, directory: str, package: str, version :str="latest") -> None:
out.write(fd.read())
shutil.unpack_archive(file_path + "/" + "model.zip", file_path + "/model")

def rm(self, package: str, version :str="latest") -> None:
def rm(self, package: str, version: str = "latest") -> None:
"""Remove a model from the remote repository."""
artefact = self.repo + "/" + package
if version is not None:
artefact = self.repo + "/" + package + "/" + version
Expand All @@ -54,6 +57,8 @@ def rm(self, package: str, version :str="latest") -> None:


class IMRLocal:
"""Local repository class."""

def __init__(self, repo: str | None = None):
self.home = Path.home()
if repo is None:
Expand All @@ -64,16 +69,19 @@ def __init__(self, repo: str | None = None):
Path.mkdir(self.repo, parents=True)

def list(self) -> list:
list = []
for entry in os.walk(self.repo):
if len(entry[1]) == 0 and entry[0] not in self.repo:
list.append(entry[0].replace(self.repo + "/", ""))
return list
"""List local models."""
return [
entry[0].replace(self.repo + "/", "")
for entry in os.walk(self.repo)
if len(entry[1]) == 0 and entry[0] not in self.repo
]

def push(self, directory: str, package: str, version: str="latest") -> None:
def push(self, directory: str, package: str, version: str = "latest") -> None:
"""Push a model in a directory to the local repository."""
shutil.copytree(directory, self.repo + "/" + package + "/" + version)

def rm(self, package: str, version :str="latest") -> None:
def rm(self, package: str, version: str = "latest") -> None:
"""Remove a model from the local repository."""
if version is None:
shutil.rmtree(self.repo + "/" + package)
else:
Expand Down
32 changes: 22 additions & 10 deletions imr/imr-cli.py → imr/imr_cli.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,40 @@
from os.path import expanduser
from pathlib import Path
""" Path module.
For handling local files and directory operations.
"""

import click
import yaml

from imr import IMRLocal, IMRRemote

home = expanduser("~")
home = Path.home()
imr_dir = home + "/.imr"
imr_local: IMRLocal = IMRLocal(imr_dir)
imr_remote: IMRRemote = None


def loadParams() -> None:
"""Load the default parameters from conf.yaml file."""
with open(imr_dir + "/config.yaml") as stream:
imrConfig = yaml.safe_load(stream)


@click.group()
def cli() -> None:
"""Get the cli command options."""
# loadParams()
pass


@cli.group()
def local() -> None:
pass
"""Get local command options."""


@local.command()
@local.command("list")
def list_local() -> None:
"""List local packages."""
for package in imr_local.list():
print(package)

Expand All @@ -39,22 +45,25 @@ def list_local() -> None:
"-v", "--version", type=str, default="latest", help="version of the model.", show_default=True
)
def remove(package: str, version: str) -> None:
list = local.rm(package, version)
"""Remove local packages."""
local.rm(package, version)


@cli.group()
@click.argument("host")
@click.argument("user")
@click.argument("password")
def remote(host: str, user: str, password: str) -> None:
"""Get remote command cli options."""
global imr_remote
imr_remote = IMRRemote(host, user, password)


@remote.command()
@remote.command("list")
def list_remote() -> None:
list = imr_remote.list()
for p in list:
"""List remote packages."""
packages = imr_remote.list()
for p in packages:
print(p)


Expand All @@ -64,6 +73,7 @@ def list_remote() -> None:
"-v", "--version", type=str, default="latest", help="version of the model.", show_default=True
)
def rm(package: str, version: str) -> None:
"""Remove remote package."""
imr_remote.rm(package, version)


Expand All @@ -74,6 +84,7 @@ def rm(package: str, version: str) -> None:
"-v", "--version", type=str, default="latest", help="version of the model.", show_default=True
)
def push(model_directory: str, package: str, version: str) -> None:
"""Push model to remote repository."""
imr_remote.push(model_directory, package, version)


Expand All @@ -90,7 +101,8 @@ def push(model_directory: str, package: str, version: str) -> None:
@click.option(
"-v", "--version", type=str, default="latest", help="version of the model.", show_default=True
)
def pull(package :str, dir :str, version :str) -> None:
def pull(package: str, dir: str, version: str) -> None:
"""Pull model from remote repository."""
imr_remote.pull(dir, package, version)


Expand Down

0 comments on commit a8ed489

Please sign in to comment.