Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
howto-cards
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Annegrät Daujeumont
howto-cards
Commits
20d8c645
Verified
Commit
20d8c645
authored
2 years ago
by
Laurent Heirendt
Browse files
Options
Downloads
Patches
Plain Diff
remove all common parts with generator
parent
1d64863f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
.ci/generateIndex.py
+6
-280
6 additions, 280 deletions
.ci/generateIndex.py
with
6 additions
and
280 deletions
.ci/generateIndex.py
+
6
−
280
View file @
20d8c645
import
os
,
re
from
os
import
path
from
os.path
import
exists
from
natsort
import
natsorted
from
pathlib
import
Path
import
yaml
def
line_prepender
(
filename
,
line
):
with
open
(
filename
,
'
r+
'
)
as
f
:
content
=
f
.
read
()
f
.
seek
(
0
,
0
)
f
.
write
(
line
.
rstrip
(
'
\r\n
'
)
+
'
\n
'
+
content
)
def
get_subdirs
(
p
):
for
fname
in
os
.
listdir
(
p
):
if
os
.
path
.
isdir
(
os
.
path
.
join
(
p
,
fname
)):
yield
os
.
path
.
join
(
p
,
fname
)
def
has_subdirs
(
p
):
folders
=
list
(
get_subdirs
(
p
))
return
len
(
folders
)
!=
0
def
build_link
(
title
,
href
):
# strip the number of the title
if
(
'
handbook
'
in
href
):
title
=
re
.
sub
(
'
[0-9.]
'
,
''
,
title
).
strip
()
# add relative url
href
=
"
{{
'"
+
href
+
"'
| relative_url }}
"
return
f
'
\t\t\t
<li><a href=
"
{
href
}
"
>
{
title
}
</a></li>
\n
'
def
root_href
(
href
):
# remove sym link reference in href
if
(
'
handbook-additional
'
in
href
):
href
=
href
.
replace
(
'
handbook-additional
'
,
'
handbook
'
).
strip
()
elif
(
'
handbook-annexes
'
in
href
):
href
=
href
.
replace
(
'
handbook-annexes
'
,
'
handbook
'
).
strip
()
# remove sym link reference in href
if
(
'
lab-software
'
in
href
):
href
=
href
.
replace
(
'
lab-software
'
,
'
lab
'
).
strip
()
elif
(
'
lab-equipment
'
in
href
):
href
=
href
.
replace
(
'
lab-equipment
'
,
'
lab
'
).
strip
()
elif
(
'
lab-hsa
'
in
href
):
href
=
href
.
replace
(
'
lab-hsa
'
,
'
lab
'
).
strip
()
elif
(
'
lab-integrity
'
in
href
):
href
=
href
.
replace
(
'
lab-integrity
'
,
'
lab
'
).
strip
()
# remove sym link reference in href
if
(
'
qms-policies
'
in
href
):
href
=
href
.
replace
(
'
qms-policies
'
,
'
qms
'
).
strip
()
elif
(
'
qms-sops
'
in
href
):
href
=
href
.
replace
(
'
qms-sops
'
,
'
qms
'
).
strip
()
return
href
def
build_section_start
(
title
,
shortcut
):
title
=
title
.
replace
(
"
Gdpr
"
,
"
GDPR
"
)
title
=
title
.
replace
(
"
Handbook additional
"
,
"
Handbook: PI/Supervisor specifics
"
)
title
=
title
.
replace
(
"
Handbook annexes
"
,
"
Handbook: Annexes
"
)
title
=
title
.
replace
(
"
Covid 19
"
,
"
COVID-19
"
)
title
=
title
.
replace
(
"
Ppc
"
,
"
PPC
"
)
title
=
title
.
replace
(
"
Lab software
"
,
"
Lab: Software
"
)
title
=
title
.
replace
(
"
Lab equipment
"
,
"
Lab: Equipment
"
)
title
=
title
.
replace
(
"
Lab hsa
"
,
"
Lab: Health & Safety, Access
"
)
title
=
title
.
replace
(
"
Lab integrity
"
,
"
Lab: Integrity
"
)
title
=
title
.
replace
(
"
Qms sops
"
,
"
QMS: Standard Operating Procedures (SOPS)
"
)
title
=
title
.
replace
(
"
Qms policies
"
,
"
QMS: Policies
"
)
return
f
'
\n\t
<div class=
"
index-box noborderbox
"
id=
"
{
shortcut
}
-card
"
>
\n\t\t
<h3>
{
title
}
</h3>
\n\t\t
<ul>
\n
'
def
build_section_end
():
return
"
\t\t
</ul>
\n\t
</div>
"
def
save_tag
(
localroot
,
root
,
filename
,
tag
):
return_tag
=
""
os
.
chdir
(
root
)
length_tag
=
len
(
tag
)
if
"
yml
"
in
filename
:
with
open
(
filename
,
"
r
"
)
as
stream
:
try
:
metadata
=
list
(
yaml
.
load_all
(
stream
,
Loader
=
yaml
.
FullLoader
))
except
yaml
.
YAMLError
as
exc
:
print
(
exc
)
return_tag
=
metadata
[
0
][
tag
]
else
:
with
open
(
filename
,
'
r
'
)
as
f
:
for
line
in
f
:
# check for the start of the section
if
line
[
0
:
length_tag
+
1
]
==
tag
+
"
:
"
:
return_tag
=
line
[
length_tag
+
2
:]
return_tag
=
return_tag
.
replace
(
'"'
,
''
)
break
# change back to the local root
os
.
chdir
(
localroot
)
return
return_tag
.
rstrip
()
def
get_ignore
():
return
[
"
404.html
"
,
"
Gemfile
"
,
"
Gemfile.lock
"
,
"
README.md
"
,
"
_config.yml
"
,
"
_site
"
,
"
assets
"
,
"
help.md
"
,
"
index.md
"
,
"
pagination.md
"
,
"
.gitkeep
"
,
]
def
save_legacy_from
(
localroot
,
root
,
filename
):
legacy_from
=
[]
os
.
chdir
(
root
)
count
=
0
legacy_from_flag
=
False
with
open
(
filename
,
'
r
'
)
as
f
:
for
line
in
f
:
count
+=
1
# check for the start of the section
if
line
[
0
:
12
]
==
"
legacy_from:
"
:
legacy_from_flag
=
True
# append lines from the legacy section
if
legacy_from_flag
:
legacy_from
.
append
(
line
)
# check for the end of the header
if
legacy_from_flag
and
line
[
0
:
3
]
==
"
---
"
:
legacy_from_flag
=
False
break
# change back to the local root
os
.
chdir
(
localroot
)
return
legacy_from
def
remove_header
(
localroot
,
root
,
filename
):
nfirstlines
=
[]
os
.
chdir
(
root
)
# count the number of lines
count
=
0
n
=
0
headerCheck
=
False
with
open
(
filename
,
'
r
'
)
as
f
:
for
line
in
f
:
count
+=
1
# check if the header is actually a header
if
count
>
1
and
line
[
0
:
3
]
==
"
---
"
:
headerCheck
=
True
n
=
count
# remove the header
if
headerCheck
:
with
open
(
filename
)
as
f
,
open
(
"
tmp
"
+
filename
,
"
w
"
)
as
out
:
for
_
in
range
(
n
):
nfirstlines
.
append
(
next
(
f
))
for
line
in
f
:
out
.
write
(
line
)
os
.
remove
(
filename
)
os
.
rename
(
"
tmp
"
+
filename
,
filename
)
print
(
"
- Old header removed.
"
)
# change back to the local root
os
.
chdir
(
localroot
)
return
n
def
element_header
(
prefix
,
permalink
,
element
):
if
(
(
"
handbook-annexes
"
in
permalink
or
"
handbook-additional
"
in
permalink
)
or
(
"
lab-software
"
in
permalink
or
"
lab-equipment
"
in
permalink
or
"
lab-hsa
"
in
permalink
)
or
(
"
qms-policies
"
in
permalink
or
"
qms-sops
"
in
permalink
)
):
element
+=
prefix
+
"
/cards/
"
+
root_href
(
shortcut
)
+
"
\n
"
element
+=
prefix
+
"
/
"
+
folder
+
"
/cards/
"
+
root_href
(
shortcut
)
+
"
\n
"
return
element
def
generate_header
(
folder
,
permalink
,
shortcut
,
order
,
legacy_from
,
title
,
description
,
qms_yml
):
header
=
"
---
\n
"
if
len
(
order
)
>
0
:
header
+=
"
card_order:
"
+
str
(
order
)
+
"
\n
"
header
+=
"
layout: page
\n
"
header
+=
"
permalink:
"
+
permalink
+
"
\n
"
header
+=
"
shortcut:
"
+
root_href
(
shortcut
)
+
"
\n
"
header
+=
"
redirect_from:
\n
"
header
+=
"
- /cards/
"
+
shortcut
+
"
\n
"
header
+=
"
- /
"
+
folder
+
"
/cards/
"
+
shortcut
+
"
\n
"
# generate specific redirects
header
=
element_header
(
"
-
"
,
shortcut
,
header
)
# include the legacy section in the redirect_from section
if
len
(
legacy_from
)
>
0
:
for
item
in
legacy_from
[
1
:
-
1
]:
header
+=
str
(
item
)
# add the title and description
if
len
(
title
)
>
0
:
header
+=
"
title:
"
+
title
+
"
\n
"
if
len
(
description
)
>
0
:
header
+=
"
description:
"
+
description
+
"
\n
"
# include the legacy section
if
len
(
legacy_from
)
>
0
:
for
item
in
legacy_from
:
header
+=
str
(
item
)
else
:
header
+=
"
---
"
# add title for QMS documents
if
"
qms
"
in
shortcut
and
qms_yml
:
header
+=
"
\n
#
"
+
title
return
header
def
generate_whitelist_entry
(
folder
,
permalink
,
shortcut
):
wl_entry
=
permalink
+
"
\n
"
wl_entry
+=
"
/?
"
+
shortcut
+
"
\n
"
wl_entry
+=
"
/cards/
"
+
shortcut
+
"
\n
"
wl_entry
+=
"
/
"
+
folder
+
"
/cards/
"
+
shortcut
+
"
\n
"
wl_entry
=
element_header
(
""
,
permalink
,
wl_entry
)
return
wl_entry
def
prepare_qms
(
localroot
,
root
,
filename
):
os
.
chdir
(
root
)
filedata
=
""
with
open
(
filename
,
'
r
'
)
as
file
:
for
line
in
file
:
filedata
+=
line
# shift the subtitles by 1 level down
filedata
=
filedata
.
replace
(
"
#
"
,
"
##
"
)
# replace latex command for titles
filedata
=
filedata
.
replace
(
"
{-}
"
,
"
##
"
)
# deal with img location
filedata
=
filedata
.
replace
(
"
policies/
"
+
filename
[:
-
3
]
+
"
/
"
,
""
)
filedata
=
filedata
.
replace
(
"
sops/
"
+
filename
[:
-
3
]
+
"
/
"
,
""
)
# replace img attributes
filedata
=
filedata
.
replace
(
"
{ width=50% }
"
,
""
)
# Write the file out again
with
open
(
filename
,
'
w
'
)
as
file
:
file
.
write
(
filedata
)
# change back to the local root
os
.
chdir
(
localroot
)
from
generator.library
import
*
# loop through the entire internal tree
localroot
=
os
.
getcwd
()
...
...
@@ -337,18 +67,14 @@ for folder in cardDirs:
# save order and legacy section
order
=
save_tag
(
localroot
,
root
,
file
,
"
card_order
"
)
legacy_from
=
save_legacy_from
(
localroot
,
root
,
file
)
title
=
save_tag
(
localroot
,
root
,
file
,
"
title
"
)
description
=
save_tag
(
localroot
,
root
,
file
,
"
description
"
)
# extract the title from the QMS metadata
qms_yml
=
False
if
"
qms
"
in
root
:
if
exists
(
os
.
path
.
join
(
root
,
file
[:
-
3
]
+
"
.yml
"
)):
title
=
save_tag
(
localroot
,
root
,
file
[:
-
3
]
+
"
.yml
"
,
"
title
"
)
prepare_qms
(
localroot
,
root
,
file
)
qms_yml
=
True
else
:
print
(
"
QMS document is not formatted properly.
"
)
title
,
qms_yml
,
yml_file
=
get_title
(
localroot
,
root
,
file
)
if
qms_yml
:
name
=
save_tag
(
localroot
,
root
,
yml_file
,
"
name
"
)
prepare_qms
(
localroot
,
root
,
file
)
# remove the previous header
n
=
remove_header
(
localroot
,
root
,
file
)
...
...
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