Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
Nueval Machinable Rules
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
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
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Academany
Fab Academy
2020
Nueval Machinable Rules
Commits
8c113148
Commit
8c113148
authored
4 years ago
by
Steven Chew
Browse files
Options
Downloads
Patches
Plain Diff
rm python3 build.py
parent
20adaa7c
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#161902
passed
4 years ago
Stage: test
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
build3.py
+0
-104
0 additions, 104 deletions
build3.py
with
0 additions
and
104 deletions
build3.py
deleted
100755 → 0
+
0
−
104
View file @
20adaa7c
# Build script for machine-friendly eval rules
import
yaml
import
glob
import
codecs
from
io
import
StringIO
import
json
import
os
import
traceback
import
sys
#import importlib
#importlib.reload(sys)
#sys.setdefaultencoding('utf8')
SOURCE_DIR
=
os
.
path
.
join
(
os
.
getcwd
(),
'
src
'
)
JSON_DIR
=
os
.
path
.
join
(
os
.
getcwd
(),
'
json
'
)
GITBOOK_DIR
=
os
.
path
.
join
(
os
.
getcwd
(),
'
gitbook
'
)
SOURCE_FILES
=
glob
.
glob
(
os
.
path
.
join
(
SOURCE_DIR
,
'
*.yaml
'
))
def
UTFWriter
():
buffer
=
StringIO
()
wrapper
=
codecs
.
getwriter
(
"
utf8
"
)(
buffer
)
wrapper
.
buffer
=
buffer
return
wrapper
def
read_yaml
(
yaml_src
):
"""
Read a yamls file
"""
print
(
'
Reading %s
'
%
yaml_src
)
yaml_file
=
open
(
yaml_src
,
'
r
'
)
yaml_data
=
yaml
.
load
(
yaml_file
.
read
(),
Loader
=
yaml
.
Loader
)
yaml_file
.
close
()
return
yaml_data
def
make_task
(
task
):
"""
Create a Markdown fragment for a task
"""
task_md
=
UTFWriter
()
print
(
'
## %s
\n
'
%
task
[
'
name
'
],
file
=
task_md
)
print
(
task
[
'
description
'
],
file
=
task_md
)
print
(
'
### Learning outcomes
\n
'
,
file
=
task_md
)
for
task_outcome
in
task
[
'
outcomes
'
]:
print
(
'
* %s
'
%
task_outcome
,
file
=
task_md
)
print
(
'
\n
### Have you?
\n
'
,
file
=
task_md
)
for
task_checklist
in
task
[
'
checklist
'
]:
print
(
'
* %s
'
%
task_checklist
,
file
=
task_md
)
return
task_md
.
buffer
.
getvalue
()
def
make_book_page
(
unit_data
):
"""
Create a Markdown version of a unit
"""
md_buffer
=
UTFWriter
()
print
(
'
# %s
\n
'
%
unit_data
[
'
unit
'
],
file
=
md_buffer
)
for
task
in
unit_data
[
'
tasks
'
]:
print
(
make_task
(
task
),
file
=
md_buffer
)
print
(
'
## FAQ
\n
'
,
file
=
md_buffer
)
print
(
unit_data
[
'
faq
'
],
file
=
md_buffer
)
return
md_buffer
.
buffer
.
getvalue
()
if
__name__
==
'
__main__
'
:
if
len
(
sys
.
argv
)
<
2
:
print
(
'
Usage: build.py [command]
\n
'
)
print
(
'
Available commands
'
)
print
(
'
test: Check if file syntax is ok
'
)
print
(
'
json: Export rules to nueval-app json
'
)
print
(
'
gitbook: Build markdown pages from YAML source
\n\n
'
)
sys
.
exit
(
-
1
)
BUILD_CMD
=
sys
.
argv
[
1
]
for
source
in
SOURCE_FILES
:
if
BUILD_CMD
==
'
test
'
:
try
:
read_yaml
(
source
)
print
(
'
Syntax OK
'
)
except
Exception
as
ex
:
print
(
'
Syntax Error
'
)
traceback
.
print_exc
()
elif
BUILD_CMD
==
'
json
'
:
if
not
os
.
path
.
exists
(
JSON_DIR
):
os
.
makedirs
(
JSON_DIR
)
try
:
data
=
read_yaml
(
source
)
jsonFile
=
os
.
path
.
basename
(
source
).
replace
(
'
.yaml
'
,
'
.json
'
)
jsonData
=
json
.
dumps
(
data
,
separators
=
(
'
,
'
,
'
:
'
),
indent
=
4
)
tmp_file
=
codecs
.
open
(
os
.
path
.
join
(
JSON_DIR
,
jsonFile
),
'
w
'
,
encoding
=
'
utf-8
'
)
tmp_file
.
write
(
jsonData
)
tmp_file
.
close
()
except
Exception
as
ex
:
print
(
'
Syntax Error
'
)
traceback
.
print_exc
()
elif
BUILD_CMD
==
'
gitbook
'
:
if
not
os
.
path
.
exists
(
GITBOOK_DIR
):
os
.
makedirs
(
GITBOOK_DIR
)
try
:
data
=
read_yaml
(
source
)
md_file
=
os
.
path
.
basename
(
source
).
replace
(
'
.yaml
'
,
'
.md
'
)
md_data
=
make_book_page
(
data
)
tmp_file
=
codecs
.
open
(
os
.
path
.
join
(
GITBOOK_DIR
,
md_file
),
'
w
'
,
encoding
=
'
utf-8
'
)
tmp_file
.
write
(
md_data
)
tmp_file
.
close
()
except
Exception
as
ex
:
traceback
.
print_exc
()
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