Skip to content

Commit

Permalink
method check change
Browse files Browse the repository at this point in the history
  • Loading branch information
i-oden committed Aug 19, 2021
1 parent 85daf24 commit 1d99e6f
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 22 deletions.
4 changes: 4 additions & 0 deletions dds_cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
__author_email__ = "datacentre@scilifelab.se"
__license__ = "MIT"

# Valid methods

DDS_METHODS = ["ls"]


###############################################################################
# CLASSES ########################################################### CLASSES #
Expand Down
6 changes: 4 additions & 2 deletions dds_cli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
# MAIN ################################################################# MAIN #
###############################################################################


# Print header to STDERR
stderr = dds_cli.utils.console
stderr.print(
Expand All @@ -70,6 +69,7 @@ def dds_main(ctx, verbose, log_file):
"""Main CLI command, sets up DDS info."""

if "--help" not in sys.argv:

# Set the base logger to output DEBUG
LOG.setLevel(logging.DEBUG)

Expand Down Expand Up @@ -199,7 +199,7 @@ def put(
try:
dds_cli.data_putter.put(
dds_info,
dds_info["CONFIG"] if config is None else config,
dds_info.get("CONFIG") if config is None else config,
username,
project,
source,
Expand Down Expand Up @@ -351,6 +351,8 @@ def ls(dds_info, project, folder, projects, size, username, config, usage, sort,
LOG.error(e)
sys.exit(1)

print("TESTING")


###############################################################################
# DELETE ############################################################# DELETE #
Expand Down
18 changes: 5 additions & 13 deletions dds_cli/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,14 @@
from dds_cli import file_handler as fh
from dds_cli import s3_connector as s3
from dds_cli import user
from dds_cli import exceptions

###############################################################################
# START LOGGING CONFIG ################################# START LOGGING CONFIG #
###############################################################################

LOG = logging.getLogger(__name__)

###############################################################################
# FUNCTIONS ####################################################### FUNCTIONS #
###############################################################################


def attempted_operation():
"""Gets the command entered by the user (e.g. put)."""

curframe = inspect.currentframe()
return inspect.getouterframes(curframe, 2)[3].function


###############################################################################
# CLASSES ########################################################### CLASSES #
Expand All @@ -60,11 +50,13 @@ def __init__(
config=None,
project=None,
dds_directory: pathlib.Path = None,
method: str = None,
):

# Get attempted operation e.g. put/ls/rm/get
self.method = attempted_operation()
LOG.debug(f"Attempted operation: {self.method}")
self.method = method
if self.method not in ["put", "get", "ls", "rm"]:
raise exceptions.InvalidMethodError(attempted_method=self.method)

# Use user defined festination if any specified
if self.method in ["get", "put"]:
Expand Down
7 changes: 2 additions & 5 deletions dds_cli/data_lister.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class DataLister(base.DDSBaseClass):

def __init__(
self,
method: str = "ls",
username: str = None,
config: pathlib.Path = None,
project: str = None,
Expand All @@ -51,11 +52,7 @@ def __init__(
):

# Initiate DDSBaseClass to authenticate user
super().__init__(
username=username,
config=config,
project=project,
)
super().__init__(username=username, config=config, project=project, method=method)

# Only method "ls" can use the DataLister class
if self.method != "ls":
Expand Down
13 changes: 13 additions & 0 deletions dds_cli/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Custom Exception classes"""

import click
import dds_cli


class ConfigFileNotFoundError(click.ClickException):
Expand All @@ -19,6 +20,18 @@ def show(self):
click.echo(self)


class InvalidMethodError(Exception):
"""Valid methods are only ls, put, get, rm. Anything else should raise errors."""

def __init__(self, attempted_method, message="Attempting an invalid method in the DDS"):
self.method = attempted_method
self.message = message
super().__init__(message)

def __str__(self):
return f"{self.message}: {self.method}"


class AuthenticationError(Exception):
"""Errors due to user authentication.
Expand Down
4 changes: 2 additions & 2 deletions dds_cli/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import dds_cli
import rich
import rich.console

console = rich.console.Console(stderr=True)
# console = rich.console.Console()

0 comments on commit 1d99e6f

Please sign in to comment.