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
b15ddde2
Commit
b15ddde2
authored
8 years ago
by
Jan Maximilian Michal
Browse files
Options
Downloads
Patches
Plain Diff
Can now create new scripts from command line.
parent
c082d716
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
grim.py
+34
-9
34 additions, 9 deletions
grim.py
scripts/__init__.py
+0
-0
0 additions, 0 deletions
scripts/__init__.py
with
34 additions
and
9 deletions
grim.py
+
34
−
9
View file @
b15ddde2
...
...
@@ -30,6 +30,7 @@ def file_exists(path):
raise
argparse
.
ArgumentTypeError
(
msg
)
return
path
def
script_is_valid
(
script
,
required
):
for
field
in
required
:
if
not
hasattr
(
script
,
field
):
...
...
@@ -37,6 +38,7 @@ def script_is_valid(script, required):
if
any
(
not
hasattr
(
script
,
field
)
for
field
in
required
):
abort
(
"
Script is invalid (see above)
"
)
def
parseme
():
parser
=
argparse
.
ArgumentParser
()
subparsers
=
parser
.
add_subparsers
(
dest
=
"
command
"
)
...
...
@@ -100,16 +102,18 @@ def parseme():
if
args
.
command
==
None
:
parser
.
print_help
()
def
delegator
(
output
,
script_name
,
instances
):
script
=
importlib
.
import_module
(
file_to_module
(
script_name
))
handler
=
{
'
gap
'
:
handle_gap_questions
,
'
single choice
'
:
handle_choice_questions
,
'
multiple choice
'
:
handle_choice_questions
'
gap
'
:
handle_gap_questions
,
'
single choice
'
:
handle_choice_questions
,
'
multiple choice
'
:
handle_choice_questions
}[
script
.
meta
[
'
type
'
]]
handler
(
output
,
script
,
instances
)
def
handle_gap_questions
(
output
,
script
,
instances
):
script_is_valid
(
script
,
required
=
[
'
meta
'
,
'
task
'
,
'
feedback
'
])
data
=
{
...
...
@@ -126,7 +130,9 @@ def handle_gap_questions(output, script, instances):
output
=
os
.
path
.
join
(
'
output
'
,
script
.
meta
[
'
title
'
])
+
'
.xml
'
if
not
output
else
output
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_choice_questions
(
output
,
script
,
instances
):
script_is_valid
(
script
,
required
=
[
'
meta
'
,
'
task
'
,
'
choices
'
,
'
feedback
'
])
...
...
@@ -145,11 +151,30 @@ def handle_choice_questions(output, script, instances):
output
=
os
.
path
.
join
(
'
output
'
,
script
.
meta
[
'
title
'
])
+
'
.xml
'
if
not
output
else
output
packer
.
convert_and_print
(
data
,
output
,
instances
)
info
(
'
Processed
"
{}
"
and wrote xml to
"
{}
"
.
'
.
format
(
script
.
__name__
,
output
))
def
handle_new_script
(
name
,
type
,
author
,
points
):
raise
NotImplementedError
()
info
(
'
Processed
"
{}
"
and wrote xml to
"
{}
"
.
'
.
format
(
script
.
__name__
,
output
))
def
handle_new_script
(
name
,
qtype
,
author
,
points
):
with
open
(
'
scripts/
'
+
name
+
'
.py
'
,
'
x
'
)
as
new_script
:
choice
=
''
if
qtype
in
[
'
multi
'
,
'
single
'
]:
choice
=
'
\n
choices =
"""
\n
[X] A
\n
[ ] B
\n
[ ] C
\n
[X] D
\n
"""
\n
'
scaffolding
=
'''
meta = {{
'
author
'
:
'
{}
'
,
'
title
'
:
'
{}
'
,
'
type
'
:
'
{}
'
,
'
points
'
: {}, # per correct choice
}}
task =
"""
decription
"""
{}
feedback =
"""
decription
"""
'''
.
format
(
author
,
name
,
qtype
,
points
,
choice
).
strip
()
print
(
scaffolding
,
file
=
new_script
)
info
(
'
Generated new script
"
{}.
"'
.
format
(
new_script
.
name
))
if
__name__
==
'
__main__
'
:
parseme
()
This diff is collapsed.
Click to expand it.
scripts/__init__.py
deleted
100644 → 0
+
0
−
0
View file @
c082d716
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