Moodle Destroyer Tools¶
Using moodle on commandline interfaces. Conquer the moodle world with the best tools provided by manly-man.
Grading with Webservices¶
This branch is a work in progress for exploiting the moodle WebService backend. Mostly for easier grading, but also to use moodle from the commandline. Conquer the moodle world with the best tools provided by manly-man. Use at your own risk!
Prerequisites¶
There are some things to do before you can use these tools.
Moodle Server¶
Have you administrator enable the Moodle Mobile backend for you. If that is not possible, you might want to fall back to the master branch.
Your PC¶
linux machine with python3 installed and the following additional python-libraries:
- requests
why linux? because -1 did not care to make it platform independent.
Installation and usage¶
Installation¶
clone the master (!) repository, not develop. you can then just link mdt.py into your path.
Usage¶
Why you might not want to use this¶
- everything is changing, this is a development branch, after all
- code: quality is dubious, interfaces unstable, documentation non-existant. WIP
- no/wonky error handling, moodle almost always says 200 OK, even on exceptions o/ WIP
If you want to use it anyway:¶
- mdt.py is a wrapper like git, but not as powerfull:
- some commands are built-in, they will be presented if you execute mdt. If you want to hook additional scripts into mdt, put them in you path and prefix the filename with ‘mdt-‘. Mdt will try to execute them, so you can have them in the same toolchain, for nicer workflows. Until now, mdt cannot pass information to external scripts. it is planned.
Configuration works much like git, there is a global and some local config files.
- global:
- mdtconfig will be in one of these folders if present: $XDG_CONFIG_HOME/, ~/.config/ If none of these folders is found, the global config will be ~/.mdtconfig
- local:
- after you use mdt init in a directory, you should find the folder .mdt Every value in .mdt/config will override the global values.
Implemented Subcommands¶
- auth: get a token for the webservice, do that first. It is interactive
- init: will list the courses you enrolled in you can interactively select the ones you want to grade. Don’t put in too many, your admin will thank you.
- sync: retreives the metadata from moodle for your selected courses. If many courses are selected, this will take a while.
- status: without any arguments, it will only display due assignments, see commandline help.
- pull: retrieves and stores submissions for grading. Creates a file for grading result and feedback, interface unstable.
- grade: interprets pull’s file with grades in it, submits grades to moodle users, interface unstable.
Planned Subcommands¶
- config: like git, could be useful.
- ?: maybe help grading even further.
planned¶
- extend the scripts to detect which commands you Moodle serves.
- add documentation after decision for a sensible code-architecture.
- accessing Moodle Quizzes
- shell completion
- threaded download
- curses UI, maybe interactive.
unplanned functionality¶
- Functionality not involving Web Services: We don’t want to navigate the front-end DOM. At least -1 doesn’t
Grading without Webservices¶
This repository contains two scripts for grading assigments, in case you find yourself with no access to Moodle’s Webservices. Use at your own risk!
Prepare moodle¶
To use the moodle-destroyer tools, please make sure you configured your submissions like shown in the screenshot.

- Offline grading worksheet enables the download of the grading-file.
- Feedback comments enables a feedback-column in the grading-file
Description and usage¶
moodle-destroyer.py¶
- Creates a csv file that can be uploaded into moodle.
- Usage:
python moodle-destroyer --help
to show usage infos. - Run this command in the directory where your CSV files are located.
- Single user mode: matching to “Vollständiger Name” instead of “Gruppe”
- Feedback Flag: Set only if gradingfile provides no “Feedback als Kommentar” column. (smart programming led to reverse yoda conditions.)
usage: Moodle Destroyer [-h] -d DESTROY DESTROY [-r RESULT] [-s] [-f] [-v]
optional arguments:
-h, --help show this help message and exit
-d DESTROY DESTROY, --destroy DESTROY DESTROY
grading-file, moodle-file
-r RESULT, --result RESULT
result-file
-s, --single is in single mode
-f, --feedback no feedback column in grading
-v, --version show program's version number and exit
moodle-extractor.py¶
- Unzips exercise submissions
- Run this command in the directory where your Zip is located.
usage: Moodle Extractor [-h] [-s] [-ng] [-v] zipfile
positional arguments:
zipfile zip file to extract
optional arguments:
-h, --help show this help message and exit
-s, --single Single User Mode, default is Group mode
-ng, --no-grading-file
Do not generate grading-file
-v, --version show program's version number and exit
Development¶
Where you can help¶
- Backend:
- moodle.communication: MoodleSession implements Moodle’s Web Service API: it is incomplete and has no support for different service versions. Implementing those is tedious, especially since Moodles API is pretty wonky: You will almost always receive 200 OK, and will have to handle exceptions by hand.
- moodle.models: contains various representations of Moodle data structures. They are badly interconnected and need restructuring.
- Frontend:
- wstools: needs command structure. a curses interface and better pretty printing should be nice.
Documentation¶
Moodle back-end¶
Moodle Developers do not provide direct access to the Web Service API. The WS API Documentation is only available per Moodle instance, so you are left with some choices:
- Ask your Moodle Administrator for it,
- set-up your own Moodle Instance (I recommend you don’t, installation takes a really long time),
- get it from the Moodle Demo Server,
- dig in Moodle’s PHP sources (I also recommend against that, use as last resort. Does not help understanding the data structures.)
Bootstrap¶
Before starting to develop on manly-man moodle scripts you should run the boostrap script. This will setup git-flow with the default settings.
We recommend git-flow AVH Edition. For detailed installation instructions have a look at https://github.com/petervanderdoes/gitflow/wiki
Working with git-flow¶
- Start a new feature with git-flow feature start FEATURE_NAME (this creates a new branch)
- Hack on your feature
- Finish your feature with git-flow feature stop FEATURE_NAME (this merges the branch into develop)