To receive notifications about scheduled maintenance, please subscribe to the mailing-list gitlab-operations@sympa.ethz.ch. You can subscribe to the mailing-list at https://sympa.ethz.ch

Commit b6480d92 authored by scmalte's avatar scmalte
Browse files

Added utils/logging.py, adapted setup.py, started working on revise.py

parent c5675fde
.vscode/ .vscode/
build/ build/
mossutils.egg-info/ mossutils.egg-info/
mossutils/utils/__pycache__/
mossutils/__pycache__/
import mosspy import mosspy
import argparse import argparse
# import logging import logging
import pprint
from .utils import logging as logutils
DEFAULT_USER_ID="3795777", # Malte's Moss ID DEFAULT_USER_ID="3795777", # Malte's Moss ID
DEFAULT_LANGUAGE="cc" # C++ DEFAULT_LANGUAGE="cc" # C++
...@@ -12,7 +13,6 @@ DEFAULT_FILE_PATTERN="./*/main.cpp" ...@@ -12,7 +13,6 @@ DEFAULT_FILE_PATTERN="./*/main.cpp"
DEFAULT_REPORT_FILE="moss-report.html" DEFAULT_REPORT_FILE="moss-report.html"
DEFAULT_REPORT_SUBDIR="_moss-report" DEFAULT_REPORT_SUBDIR="_moss-report"
DEFAULT_CONNECTIONS=8 DEFAULT_CONNECTIONS=8
DEFAULT_LOGGING_LEVEL="INFO"
def run_moss( def run_moss(
user_id=DEFAULT_USER_ID, user_id=DEFAULT_USER_ID,
...@@ -32,36 +32,39 @@ def run_moss( ...@@ -32,36 +32,39 @@ def run_moss(
comment_string = str(comments) comment_string = str(comments)
# # A nicely formatted string representation requires a bit of hacking # # A nicely formatted string representation requires a bit of hacking
# import pprint
# comment_string = pprint.pformat(comments, indent=2) # comment_string = pprint.pformat(comments, indent=2)
# comment_string = comment_string.replace("\n", "<br/>") # comment_string = comment_string.replace("\n", "<br/>")
# comment_string = comment_string.replace(" ", "&nbsp;&nbsp;") # comment_string = comment_string.replace(" ", "&nbsp;&nbsp;")
# Initialisation # Initialisation
logging.info("User id: {}".format(user_id)) logging.debug("User id: {}".format(user_id))
logging.info("Language: {}".format(language)) logging.debug("Language: {}".format(language))
moss = mosspy.Moss(user_id, language) moss = mosspy.Moss(user_id, language)
# Configure # Configure
logging.info("Ignore limit: {}".format(ignore_limit)) logging.debug("Ignore limit: {}".format(ignore_limit))
logging.info("Matches: {}".format(number_of_matching_files)) logging.debug("Matches: {}".format(number_of_matching_files))
# logging.info("Comment: {}".format(comment_string)) # logging.debug("Comment: {}".format(comment_string))
moss.setIgnoreLimit(ignore_limit) moss.setIgnoreLimit(ignore_limit)
moss.setNumberOfMatchingFiles(number_of_matching_files) moss.setNumberOfMatchingFiles(number_of_matching_files)
moss.setCommentString(comment_string) moss.setCommentString(comment_string)
# Add template file(s) # Add template file(s)
logging.info("Template: {}".format(template)) logging.debug("Template: {}".format(template))
if template: if template:
moss.addBaseFile(template) moss.addBaseFile(template)
# Add submission file # Add submission file
logging.info("File pattern: {}".format(file_pattern)) logging.debug("File pattern: {}".format(file_pattern))
moss.addFilesByWildcard(file_pattern) moss.addFilesByWildcard(file_pattern)
exit(0)
logging.info("Sending files to Moss") logging.info("Sending files to Moss")
url = moss.send() # Submission Report URL url = moss.send() # Submission Report URL
...@@ -124,12 +127,7 @@ def configure_cli_parser(parser): ...@@ -124,12 +127,7 @@ def configure_cli_parser(parser):
default=DEFAULT_REPORT_SUBDIR, default=DEFAULT_REPORT_SUBDIR,
help="Directory for individual report files (default: {})".format(DEFAULT_REPORT_SUBDIR)) help="Directory for individual report files (default: {})".format(DEFAULT_REPORT_SUBDIR))
parser.add_argument( logutils.add_loglevel_argument(parser)
"--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( parser.add_argument(
"pattern", "pattern",
...@@ -142,21 +140,7 @@ def main(): ...@@ -142,21 +140,7 @@ def main():
configure_cli_parser(parser) configure_cli_parser(parser)
args = parser.parse_args() args = parser.parse_args()
# See https://docs.python.org/3.8/library/logging.html#logging-levels logutils.configure_level_and_format(args.log_level)
log_levels = {
"OFF": logging.NOTSET,
"DEBUG": logging.DEBUG,
"INFO": logging.INFO,
"WARNING": logging.WARNING,
"ERROR": logging.ERROR
}
log_level = log_levels[args.log_level]
# See https://docs.python.org/3.8/library/logging.html#logrecord-attributes
log_format = "%(message)s"
logging.basicConfig(level=log_level, format=log_format)
run_moss( run_moss(
user_id=args.user_id, user_id=args.user_id,
...@@ -168,5 +152,6 @@ def main(): ...@@ -168,5 +152,6 @@ def main():
report_file=args.report_file, report_file=args.report_file,
report_subdir=args.report_dir) report_subdir=args.report_dir)
if __name__ == '__main__': if __name__ == '__main__':
main() main()
import re
import logging
import argparse
from bs4 import BeautifulSoup
from .utils import logging as logutils
DEFAULT_REPORT_INPUT_FILE="moss-report.html"
DEFAULT_REPORT_OUTPUT_FILE="moss-report-revised.html"
def get_match_percentage(match_text):
percentage_pattern = r'\((\d+)%\)$'
percentage_string = re.search(percentage_pattern, match_text).group(1)
return int(percentage_string)
# moss_report_input_filename = 'moss-report.html'
# moss_report_ouput_filename = 'moss-report-fixed.html'
def main():
with open(moss_report_input_filename) as input_file:
# We use BeautifulSoup because of it allows easy DOM manipulation and has
# a nice pretty-printing feature. The lxml parser is used because it is able
# to parse the totally broken HTML report file that Moss generates.
doc = BeautifulSoup(input_file, features='lxml')
doc.body.table['class'] = 'sortable'
ths = doc.find_all('th')
th = doc.new_tag('th')
th.string = 'Avg. %'
ths[1].insert_after(th)
for row in doc.find_all('tr'):
for a in row.find_all('a'):
a['target'] = '_blank'
# print(row)
cols = row.find_all('td')
first_match_text = cols[0].a.string
second_match_text = cols[1].a.string
first_percentage = get_match_percentage(first_match_text)
second_percentage = get_match_percentage(second_match_text)
avg_percentage = (first_percentage + second_percentage) / 2
td = doc.new_tag('td')
td.string = str(avg_percentage)
row.insert(2, td)
# <script src="sorttable.js"></script>
script = doc.new_tag('script')
script['src'] = 'sorttable.js' # Library from https://kryogenix.org/code/browser/sorttable/
doc.html.head.append(script)
# <link href="style.css" rel="stylesheet">
link = doc.new_tag('link')
link['href'] = 'style.css'
link['rel'] = 'stylesheet'
doc.html.head.append(link)
# <script src="script.js"></script>
script = doc.new_tag('script')
script['src'] = 'script.js'
doc.html.body.append(script)
with open(moss_report_ouput_filename, 'w') as output_file:
output_file.write(doc.prettify()) # 'utf-8'
if __name__ == '__main__':
main()
\ No newline at end of file
import logging
import argparse
# See https://docs.python.org/3.8/library/logging.html#logging-levels
LOG_LEVELS = {
"DEBUG": logging.DEBUG,
"INFO": logging.INFO,
"WARNING": logging.WARNING,
"ERROR": logging.ERROR,
"OFF": logging.CRITICAL + 1
}
DEFAULT_LOGGING_LEVEL="DEBUG"
DEFAULT_LOG_FORMAT="[%(levelname)s] %(message)s"
def add_loglevel_argument(parser, default_level=DEFAULT_LOGGING_LEVEL):
parser.add_argument(
"--log-level",
type=str,
choices=("OFF", "DEBUG", "INFO", "WARNING", "ERROR"),
default=default_level,
help="Log level (default: {})".format(default_level))
def configure_level_and_format(level_string=DEFAULT_LOGGING_LEVEL, format=DEFAULT_LOG_FORMAT):
# See https://docs.python.org/3.8/library/logging.html#logrecord-attributes
logging.basicConfig(level=LOG_LEVELS[level_string], format=format)
...@@ -8,12 +8,20 @@ setup( ...@@ -8,12 +8,20 @@ setup(
author='Malte Schwerhoff', author='Malte Schwerhoff',
author_email='malte.schwerhoff@inf.ethz.ch', author_email='malte.schwerhoff@inf.ethz.ch',
license='unlicensed', license='unlicensed',
packages=['mossutils'], packages=[
'mossutils',
'mossutils.utils'
],
install_requires=[ install_requires=[
'mosspy', 'mosspy',
'bs4',
'lxml'
], ],
# scripts=['bin/mossutils-moss'], # scripts=['bin/mossutils-moss'],
entry_points = { entry_points = {
"console_scripts": ['mu-moss = mossutils.moss:main'] "console_scripts": [
'mu-moss = mossutils.moss:main',
'mu-revise = mossutils.revise:main'
]
}, },
zip_safe=False) 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