rowdyrotifer / clanvas Goto Github PK
View Code? Open in Web Editor NEWCommand-line client for Canvas by Instructure
License: MIT License
Command-line client for Canvas by Instructure
License: MIT License
Due to the old version of cmd2
used, clanvas no longer works in Python 3.10:
>>> import cmd2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/michael/.local/lib/python3.10/site-packages/cmd2/__init__.py", line 13, in <module>
from .cmd2 import Cmd, Statement, EmptyStatement, categorize
File "/home/michael/.local/lib/python3.10/site-packages/cmd2/cmd2.py", line 48, in <module>
from . import utils
File "/home/michael/.local/lib/python3.10/site-packages/cmd2/utils.py", line 73, in <module>
default_values: collections.Iterable = ()):
AttributeError: module 'collections' has no attribute 'Iterable'
In Python 3.10, Iterable
was moved to collections.abc
.
Several possible solutions:
I could probably do 1 if that's what you want to do.
Currently, if we want to add command history, or any sort of cache that persists longer than a session, we would need to choose more arbitrary files / locations to put them in. Instead, let's start by making this a configurable directory.
Check for an environment variable called CLANVASHOME
, if it is set, then use that value.
Otherwise / by default set this value to a .clanvas
folder in the user's home directory.
In order to consolidate the growing number of files, move ~/.clanvasrc
to clanvas_data_directory/rcfile
.
On startup, if this directory does not exist, create it. Also on startup, if the rcfile does not exist, create it (but leave it empty).
I tried installing clanvas on Ubuntu WSL (Python 3.10) and Windows (Python 3.11), and neither works after install.
Here is the output when I try to run:
$ clanvas [school url redacted]
Traceback (most recent call last):
File "/home/mason/.local/bin/clanvas", line 5, in <module>
from clanvas.clanvas import main
File "/home/mason/.local/lib/python3.10/site-packages/clanvas/clanvas.py", line 11, in <module>
import cmd2
File "/home/mason/.local/lib/python3.10/site-packages/cmd2/__init__.py", line 13, in <module>
from .cmd2 import Cmd, Statement, EmptyStatement, categorize
File "/home/mason/.local/lib/python3.10/site-packages/cmd2/cmd2.py", line 48, in <module>
from . import utils
File "/home/mason/.local/lib/python3.10/site-packages/cmd2/utils.py", line 73, in <module>
default_values: collections.Iterable = ()):
AttributeError: module 'collections' has no attribute 'Iterable'
$ clanvas [school url redacted]
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "D:\Users\Mason Francis\OneDrive\Coding\clanvas-test\venv\Scripts\clanvas.exe\__main__.py", line 4, in <module>
File "D:\Users\Mason Francis\OneDrive\Coding\clanvas-test\venv\Lib\site-packages\clanvas\clanvas.py", line 2, in <module>
import readline
File "D:\Users\Mason Francis\OneDrive\Coding\clanvas-test\venv\Lib\site-packages\readline.py", line 34, in <module>
rl = Readline()
^^^^^^^^^^
File "D:\Users\Mason Francis\OneDrive\Coding\clanvas-test\venv\Lib\site-packages\pyreadline\rlmain.py", line 422, in __init__
BaseReadline.__init__(self)
File "D:\Users\Mason Francis\OneDrive\Coding\clanvas-test\venv\Lib\site-packages\pyreadline\rlmain.py", line 62, in __init__
mode.init_editing_mode(None)
File "D:\Users\Mason Francis\OneDrive\Coding\clanvas-test\venv\Lib\site-packages\pyreadline\modes\emacs.py", line 633, in init_editing_mode
self._bind_key('space', self.self_insert)
File "D:\Users\Mason Francis\OneDrive\Coding\clanvas-test\venv\Lib\site-packages\pyreadline\modes\basemode.py", line 162, in _bind_key
if not callable(func):
^^^^^^^^^^^^^^
File "D:\Users\Mason Francis\OneDrive\Coding\clanvas-test\venv\Lib\site-packages\pyreadline\py3k_compat.py", line 8, in callable
return isinstance(x, collections.Callable)
^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'collections' has no attribute 'Callable'
Currently, the .clanvasrc
file is hardcoded to the user's home directory (~/.clanvasrc
)
It would be nice if there were ways to specify alternate locations for those with custom configurations.
Add a function that resolves the path of the rcfile by using an approach with a series of fallbacks:
--rc-file
, if they do, use that option's value.CLANVASRCPATH
, if they do, use that option's value.join(expanduser('~'), '.clanvasrc')
Use argparse. ArgumentParser
to read the command-line arguments, and os.environ
to read environment variables.
I just took a quick look at the clanvas source code and have a few recommendations regarding the use of cmd2 that you may benefit from:
Currently, tab completion for commands such as change class (cc
), upload assignment (ua
), and concatenate (output) announcement (catann
) all work with ID numbers, but the tab completion results are hard to make sense of because you need to have just listed the announcements or assignments to know what each ID corresponds to.
Cmd2 has a capability to display more than just the completion string on tab-complete. See for example the following behavior of the example located at cmd2/examples/tab_autocompletion.py.
(Cmd) media movies delete SW_EP
MOVIE_ID Title
SW_EP1 Star Wars: Episode I - The Phantom Menace
SW_EP02 Star Wars: Episode II - Attack of the Clones
SW_EP03 Star Wars: Episode III - Revenge of the Sith
SW_EP04 Star Wars: Episode IV - A New Hope
SW_EP05 Star Wars: Episode V - The Empire Strikes Back
SW_EP06 Star Wars: Episode VI - Return of the Jedi
(Cmd) media movies delete SW_EP
Both this example as well as Clanvas leverage the argpase_completer that is a part of cmd2, the CompletionItem
class in that file definitely must be relevant to the behavior we're trying to achieve.
For courses, assignments, and announcements, we want to show the full course names, assignment titles, and announcement titles.
In the Clanvas shell, the default prompt adds functionality parallel to what most shells have with the cd
(change directory) command. Clanvas has a cc
(change class) command, which then implicitly passes that course to all the command that require a course to be specified (for example, lg
(list grades) can be called after a cc
call, or one can use the -c
option to specify a course explicitly or a course other than the current one).
Add a pwc
(present working class) command (analogous to the pwd
(present working directory) command) that outputs information about the class that is currently selected with cc
.
Now, there is a bit more information about courses than there is about directories, so I imagine the command would be a bit more complex than the pwd
command, here is how I imagine some example output:
Command: pwc
EECS455-13682
Command: pwc -l
Name: Applied Graph Theory (100/10395)
Course code: EECS 455
Term: Fall 2018
Course id: 13682
If no course has been selected, something like the following would make sense.
Command: pwc
No course selected. Use cc to select a course.
In the Canvas API, assignments have an allowed_extensions
attribute. These extensions should be checked when running the ua
command, and an appropriate error message should be displayed instead of going through with the upload.
Interestingly enough, it seems that the API happily accepts and submits uploads of the wrong file type currently, whereas in my experience, the website doesn't. We still shouldn't allow it though.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.