Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,18 @@ venv/
build/
clanvas.egg-info/
dist/

.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets
!*.code-workspace

# Built Visual Studio Code Extensions
*.vsix

# test coverage
.coverage
.coverage.*
30 changes: 22 additions & 8 deletions clanvas/clanvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import cmd2
import colorama
from canvasapi import Canvas
from cmd2 import Cmd
from cmd2 import Cmd, Settable

from .completion import apply_completers
from .config import InvalidClanvasConfigurationException, parse_clanvas_config_file
Expand All @@ -26,14 +26,28 @@ class Clanvas(cmd2.Cmd):
CLANVAS_CATEGORY = 'Clanvas'

def __init__(self, base_url, access_token, *args, **kwargs):
super(Clanvas, self).__init__(*args, **kwargs)

# The `cmd2` library will attempt to inspect the object
# for attributes. Since one attribute is `prompt` defined
# as a property that checks for `self.canvas`, we need to
# ensure that `self.canvas` is initialized to avoid
# an AttributeError during initialization.
self.canvas = None

# Explicitly set allow_cli_args to False to prevent cmd2 from parsing CLI args
# Since we already handle CLI args in the main function
super(Clanvas, self).__init__(*args, allow_cli_args=False, **kwargs)

self.default_to_shell = True
self.allow_cli_args = False

self.settable.update({'prompt_format': 'prompt format string'})
self.settable.update({'verbosity': 'default command verbosity (NORMAL/VERBOSE/DEBUG)'})
self.settable.pop('prompt')
self.add_settable(Settable('prompt_format',
val_type=str,
description = 'prompt format string', settable_object=self))
self.add_settable(Settable('verbosity',
val_type=Verbosity.__getitem__,
description='default command verbosity (NORMAL/VERBOSE/DEBUG)',
choices=(Verbosity.__members__.values()),
settable_object=self))

self.url = base_url
self.host = urlparse(base_url).netloc
Expand Down Expand Up @@ -77,13 +91,13 @@ def list_assignments_cached(self, course_id):
return sorted(course.get_assignments(), key=lambda t: t.created_at_date)

def get_verbosity(self) -> Verbosity:
return Verbosity[self.verbosity]
return self.verbosity

prompt_format = (Fore.LIGHTGREEN_EX + '{login_id}@{host}' + Style.RESET_ALL + ':'
+ Fore.LIGHTYELLOW_EX + '{pwc}' + Style.RESET_ALL + ':' + Fore.LIGHTBLUE_EX
+ '{pwd} ' + Style.RESET_ALL + '$ ').replace('\x1b', "\\x1b")

verbosity = 'NORMAL'
verbosity = Verbosity.NORMAL

canvas_path = expanduser('~/canvas')

Expand Down
16 changes: 16 additions & 0 deletions clanvas/outputter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@ class Verbosity(Enum):
VERBOSE = 2
DEBUG = 3

def __str__(self):
return self.name

def __repr__(self):
return str(self)

def __eq__(self, value):
if isinstance(value, str):
# Convert strings to Verbosity enum members before comparison
return super().__eq__(Verbosity.__getitem__(value))

return super().__eq__(value)

def __hash__(self):
return super().__hash__()


class Outputter:
def __init__(self, printfn, verbosityfn):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
author='Mark Lalor',
author_email='[email protected]',
install_requires=[
'canvasapi==0.12.0', 'cmd2==0.9.12', 'tabulate>=0.8.3', 'tree-format>=0.1.2',
'canvasapi==3.3.0', 'cmd2==2.5.6', 'tabulate>=0.9.0', 'tree-format>=0.1.2',
'html2text', 'colorama', 'pytz', 'tzlocal'
],
extras_require={
Expand Down
Empty file added tests/config/__init__.py
Empty file.