Commit effb461a authored by scmalte's avatar scmalte

Turning moss.py into a proper script, available as mu-moss

parent 7b61384b
.vscode
.vscode/
build/
mossutils.egg-info/
def phonky():
print("Make it phonky!")
import mosspy
import argparse
import logging
DEFAULT_USER_ID="3795777", # Malte's Moss ID
DEFAULT_LANGUAGE="cc" # C++
DEFAULT_IGNORE_LIMIT=200 # -m in Moss
DEFAULT_NUMBER_OF_MATCHING_FILES=10 # -n in Moss
DEFAULT_TEMPLATE=None
DEFAULT_FILE_PATTERN="./*/main.cpp"
DEFAULT_REPORT_FILE="moss-report.html"
DEFAULT_REPORT_SUBDIR="_moss-report"
DEFAULT_CONNECTIONS=8
DEFAULT_LOGGING_LEVEL="INFO"
def run_moss(
user_id=DEFAULT_USER_ID,
language=DEFAULT_LANGUAGE,
ignore_limit=DEFAULT_IGNORE_LIMIT,
number_of_matching_files=DEFAULT_NUMBER_OF_MATCHING_FILES,
template=DEFAULT_TEMPLATE,
file_pattern=DEFAULT_FILE_PATTERN,
report_file=DEFAULT_REPORT_FILE,
report_subdir=DEFAULT_REPORT_SUBDIR,
connections=DEFAULT_CONNECTIONS):
# Initialisation
logging.info("User id: {}".format(user_id))
logging.info("Language: {}".format(language))
moss = mosspy.Moss(user_id, language)
# Configure
logging.info("Ignore limit: {}".format(ignore_limit))
logging.info("Matches: {}".format(number_of_matching_files))
moss.setignore_limit(ignore_limit)
moss.setnumber_of_matching_files(number_of_matching_files)
# Add template file(s)
logging.info("Template: {}".format(template))
moss.addBaseFile(template)
# Add submission file
logging.info("File pattern: {}".format(file_pattern))
moss.addFilesByWildcard(file_pattern)
logging.info("Sending files to Moss")
url = moss.send() # Submission Report URL
logging.info("Moss report URL: {}".format(url))
# Save report file
logging.info("Downloading report to: {}".format(report_file))
moss.saveWebPage(url, report_file)
# Download whole report locally including code diff links
logging.info("Downloading individual report files to: {}".format(report_subdir))
mosspy.download_report(url, report_subdir, connections=connections)
# TODO: Transform moss-report.html and replace remote links to match<n>.html
# with local ones to _moss-report/match<n>.html.
# Check that Mossum still correctly works on the transformed file!
def configure_cli_parser(parser):
parser.add_argument(
"-u", "--user-id",
type=int,
help="Moss user ID",
required=True)
parser.add_argument(
"-l", "--language",
type=str,
default=DEFAULT_LANGUAGE,
help="Programming language (default: {})".format(DEFAULT_LANGUAGE))
parser.add_argument(
"-m", "--ignore-limit",
type=int,
default=DEFAULT_IGNORE_LIMIT,
help="Passages occurring in at least this many submissions is ignored (default: {})".format(DEFAULT_IGNORE_LIMIT))
parser.add_argument(
"-n", "--matches",
type=int,
default=DEFAULT_NUMBER_OF_MATCHING_FILES,
help="Number of matches returned from Moss (default: {})".format(DEFAULT_NUMBER_OF_MATCHING_FILES))
parser.add_argument(
"-t", "--template",
type=str,
default=DEFAULT_TEMPLATE,
help="Student template (default: {})".format(DEFAULT_TEMPLATE))
parser.add_argument(
"-rf", "--report-file",
type=str,
default=DEFAULT_REPORT_FILE,
help="Summary report file (default: {})".format(DEFAULT_REPORT_FILE))
parser.add_argument(
"-rd", "--report-dir",
type=str,
default=DEFAULT_REPORT_SUBDIR,
help="Directory for individual report files (default: {})".format(DEFAULT_REPORT_SUBDIR))
parser.add_argument(
"--log-level",
type=str,
choices=("OFF", "DEBUG", "INFO", "WARNING", "ERROR"),
default=DEFAULT_LOGGING_LEVEL,
help="Log level (default: {})".format(DEFAULT_LOGGING_LEVEL))
parser.add_argument(
"pattern",
type=str,
default=DEFAULT_FILE_PATTERN,
help="Pattern for files to send to Moss (e.g.: {})".format(DEFAULT_FILE_PATTERN))
def main():
parser = argparse.ArgumentParser()
configure_cli_parser(parser)
args = parser.parse_args()
log_levels = {
"OFF": logging.NOTSET,
"DEBUG": logging.DEBUG,
"INFO": logging.INFO,
"WARNING": logging.WARNING,
"ERROR": logging.CRITICAL
}
numeric_log_level = log_levels[args.log_level]
logging.basicConfig(level=args.log_level)
run_moss(
user_id=args.user_id,
language=args.language,
ignore_limit=args.ignore_limit,
number_of_matching_files=args.matches,
template=args.template,
file_pattern=args.pattern,
report_file=args.report_file,
report_subdir=args.report_dir)
if __name__ == '__main__':
main()
def main():
print("I was called!")
......@@ -14,6 +14,6 @@ setup(
],
# scripts=['bin/mossutils-moss'],
entry_points = {
"console_scripts": ['mu-moss = mossutils.mossutils:main']
"console_scripts": ['mu-moss = mossutils.moss:main']
},
zip_safe=False)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment