Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
hallgrim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jan Maximilian Michal
hallgrim
Commits
bf975393
Commit
bf975393
authored
8 years ago
by
Jan Maximilian Michal
Browse files
Options
Downloads
Patches
Plain Diff
Scripts are tested for required fields
parent
4f61b4ba
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
grim.py
+17
-3
17 additions, 3 deletions
grim.py
hallgrim/IliasXMLCreator/gap.py
+15
-0
15 additions, 0 deletions
hallgrim/IliasXMLCreator/gap.py
hallgrim/messages.py
+10
-1
10 additions, 1 deletion
hallgrim/messages.py
with
42 additions
and
4 deletions
grim.py
+
17
−
3
View file @
bf975393
...
@@ -21,20 +21,31 @@ def type_selector(type):
...
@@ -21,20 +21,31 @@ def type_selector(type):
if
'
single
'
in
type
:
if
'
single
'
in
type
:
return
'
SINGLE CHOICE QUESTION
'
return
'
SINGLE CHOICE QUESTION
'
def
file_exists
(
path
):
def
file_exists
(
path
):
if
not
os
.
path
.
exists
(
path
):
if
not
os
.
path
.
exists
(
path
):
msg
=
'
The script
"
{}
"
does not exist.
'
.
format
(
path
)
msg
=
'
The script
"
{}
"
does not exist.
'
.
format
(
path
)
raise
argparse
.
ArgumentTypeError
(
msg
)
raise
argparse
.
ArgumentTypeError
(
msg
)
return
path
return
path
def
script_is_valid
(
script
):
required
=
[
'
meta
'
,
'
task
'
,
'
choices
'
,
'
feedback
'
]
for
field
in
required
:
if
not
hasattr
(
script
,
field
):
error
(
"
script does not export
'
{}
'
field.
"
.
format
(
field
))
if
any
(
not
hasattr
(
script
,
field
)
for
field
in
required
):
abort
(
"
Script is invalid (see above)
"
)
def
parseme
():
def
parseme
():
parser
=
argparse
.
ArgumentParser
()
parser
=
argparse
.
ArgumentParser
()
subparsers
=
parser
.
add_subparsers
(
dest
=
"
command
"
)
subparsers
=
parser
.
add_subparsers
(
dest
=
"
command
"
)
parser_new
=
subparsers
.
add_parser
(
"
new
"
,
help
=
"
The utility the generate new scripts.
"
)
parser_new
=
subparsers
.
add_parser
(
"
new
"
,
help
=
"
The utility the generate new scripts.
"
)
parser_new
.
add_argument
(
parser_new
.
add_argument
(
"
name
"
,
"
name
"
,
help
=
"
The name of the new script
"
help
=
"
The name of the new script
"
,
metavar
=
'
NAME
'
)
)
parser_new
.
add_argument
(
parser_new
.
add_argument
(
"
-t
"
,
"
-t
"
,
...
@@ -58,7 +69,8 @@ def parseme():
...
@@ -58,7 +69,8 @@ def parseme():
metavar
=
'
POINTS
'
,
metavar
=
'
POINTS
'
,
)
)
parser_gen
=
subparsers
.
add_parser
(
"
gen
"
,
help
=
"
Subcommand to convert from script to xml.
"
)
parser_gen
=
subparsers
.
add_parser
(
"
gen
"
,
help
=
"
Subcommand to convert from script to xml.
"
)
parser_gen
.
add_argument
(
parser_gen
.
add_argument
(
'
-o
'
,
'
-o
'
,
'
--out
'
,
'
--out
'
,
...
@@ -90,6 +102,7 @@ def parseme():
...
@@ -90,6 +102,7 @@ def parseme():
def
handle_choice_questions
(
output
,
script_name
,
instances
):
def
handle_choice_questions
(
output
,
script_name
,
instances
):
script
=
importlib
.
import_module
(
file_to_module
(
script_name
))
script
=
importlib
.
import_module
(
file_to_module
(
script_name
))
script_is_valid
(
script
)
data
=
{
data
=
{
'
type
'
:
type_selector
(
script
.
meta
[
'
type
'
]),
'
type
'
:
type_selector
(
script
.
meta
[
'
type
'
]),
'
description
'
:
"
_description
"
,
'
description
'
:
"
_description
"
,
...
@@ -107,6 +120,7 @@ def handle_choice_questions(output, script_name, instances):
...
@@ -107,6 +120,7 @@ def handle_choice_questions(output, script_name, instances):
packer
.
convert_and_print
(
data
,
output
,
instances
)
packer
.
convert_and_print
(
data
,
output
,
instances
)
info
(
'
Processed
"
{}
"
and wrote xml to
"
{}
"
.
'
.
format
(
script_name
,
output
))
info
(
'
Processed
"
{}
"
and wrote xml to
"
{}
"
.
'
.
format
(
script_name
,
output
))
def
handle_new_script
(
name
,
type
,
author
,
points
):
def
handle_new_script
(
name
,
type
,
author
,
points
):
raise
NotImplementedError
()
raise
NotImplementedError
()
...
...
This diff is collapsed.
Click to expand it.
hallgrim/IliasXMLCreator/gap.py
0 → 100644
+
15
−
0
View file @
bf975393
import
xml.etree.ElementTree
as
et
from
hallgrim.IliasXMLCreator.xmlBuildingBlocks
import
*
class
GapQuestion
:
"""
docstring for GapQuestion
"""
def
__init__
(
self
,
type
,
description
,
question_text
,
author
,
title
,
questions
,
feedback
,
gapLength
):
self
.
type
=
type
self
.
description
=
description
self
.
question_text
=
question_text
self
.
author
=
author
self
.
title
=
title
self
.
questions
=
questions
self
.
feedback
=
feedback
self
.
gapLength
=
gapLength
This diff is collapsed.
Click to expand it.
hallgrim/messages.py
+
10
−
1
View file @
bf975393
import
sys
def
warn
(
msg
):
def
warn
(
msg
):
print
(
'
[WARN]
'
,
msg
)
print
(
'
[WARN]
'
,
msg
)
...
@@ -5,4 +7,11 @@ def debug(msg):
...
@@ -5,4 +7,11 @@ def debug(msg):
print
(
'
[DEBUG]
'
,
msg
)
print
(
'
[DEBUG]
'
,
msg
)
def
info
(
msg
):
def
info
(
msg
):
print
(
'
[INFO]
'
,
msg
)
print
(
'
[INFO]
'
,
msg
)
\ No newline at end of file
def
error
(
msg
):
print
(
'
[ERROR]
'
,
msg
)
def
abort
(
msg
):
print
(
'
[FATAL]
'
,
msg
)
sys
.
exit
(
'
exiting...
'
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment