Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
generator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
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
Container Registry
Model registry
Operate
Terraform modules
Monitor
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
R3
apps
generator
Commits
a8983c7a
Verified
Commit
a8983c7a
authored
2 years ago
by
Laurent Heirendt
Browse files
Options
Downloads
Patches
Plain Diff
merge all fcts
parent
222e5754
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
library.py
+116
-94
116 additions, 94 deletions
library.py
with
116 additions
and
94 deletions
library.py
+
116
−
94
View file @
a8983c7a
...
...
@@ -4,6 +4,7 @@ from os.path import exists
from
threading
import
local
import
yaml
from
natsort
import
natsorted
from
pathlib
import
Path
def
line_prepender
(
filename
,
line
):
with
open
(
filename
,
'
r+
'
)
as
f
:
...
...
@@ -288,9 +289,118 @@ def get_title(localroot, root, file):
return
title
,
qms_yml
,
yml_file
def
core
(
cardDirs
,
localroot
,
localIndexArr
,
orderArr
,
sections
,
ignore
):
def
get_sections
(
cardDirs
):
sections
=
[]
# retrieve ignore list
ignore
=
get_ignore
()
# determine first the directories
for
direct
in
cardDirs
:
if
path
.
isdir
(
direct
)
and
has_subdirs
(
direct
):
dirs
=
os
.
listdir
(
direct
)
dirs
=
natsorted
(
dirs
)
for
d
in
dirs
:
if
d
[
0
]
!=
"
.
"
and
d
not
in
ignore
and
has_subdirs
(
direct
+
"
/
"
+
d
):
sections
.
append
(
d
)
sections
=
list
(
set
(
sections
))
sections
=
natsorted
(
sections
)
return
sections
,
ignore
def
get_indexArr
(
sections
):
localIndexArr
=
{
k
:
[]
for
k
in
range
(
len
(
sections
))}
orderArr
=
{
k
:
[]
for
k
in
range
(
len
(
sections
))}
return
localIndexArr
,
orderArr
def
sort_sections
(
sections
,
localIndexArr
,
orderArr
):
for
d
in
sections
:
indexS
=
sections
.
index
(
d
)
# join all subcategories to the index
# if all subcategories have a predefined order
if
len
(
orderArr
[
indexS
])
==
len
(
localIndexArr
[
indexS
])
-
1
and
len
(
orderArr
[
indexS
])
>
0
:
print
(
""
)
X
=
localIndexArr
[
indexS
][
1
:]
Y
=
orderArr
[
indexS
]
localIndexArr
[
indexS
]
=
[
x
for
_
,
x
in
sorted
(
zip
(
Y
,
X
))]
# natural sorting otherwise
else
:
localIndexArr
[
indexS
]
=
natsorted
(
localIndexArr
[
indexS
])
print
(
localIndexArr
)
return
localIndexArr
def
generate_index_top
():
index
=
'
\n
<div class=
"
index-box-container
"
>
\n
'
return
index
def
generate_index
(
index
,
sections
,
localIndexArr
):
# determine the index
k
=
0
for
s
in
sections
:
index
+=
build_section_start
(
s
.
replace
(
"
-
"
,
"
"
).
capitalize
(),
s
)
index
+=
''
.
join
(
localIndexArr
[
k
])
index
+=
build_section_end
()
k
+=
1
# close the container
index
+=
"
\n
</div>
"
## add link to return to main index
index
+=
"""
<br><center><a href=
"
{{
'
/
'
| relative_url }}
"
>go back</a></center>
"""
index
+=
"""
<br><center><a href=
"
{{
'
/cards
'
| relative_url }}
"
>Overview of all HowTo cards</a></center>
"""
return
index
def
save_index
(
index
,
indexFile
):
# output the index
#print(index)
# Read in the file
#indexFile = "cards.md"
filedata
=
""
with
open
(
indexFile
,
'
r
'
)
as
file
:
for
line
in
file
:
filedata
+=
line
# stop reading once the index place holder has been reached
if
re
.
search
(
"
<!-- index -->
"
,
line
):
filedata
+=
"
[[ index ]]
"
break
# Replace the target string
filedata
=
filedata
.
replace
(
'
[[ index ]]
'
,
index
)
# Write the file out again
with
open
(
indexFile
,
'
w
'
)
as
file
:
file
.
write
(
filedata
)
print
(
"
\n
> New index generated and saved in
"
+
indexFile
)
def
save_whitelist
(
whitelist
,
whitelistFile
):
# write link whitelist out
if
Path
(
whitelistFile
).
exists
():
with
open
(
whitelistFile
,
'
r
'
)
as
file
:
for
line
in
file
:
whitelist
+=
line
with
open
(
whitelistFile
,
'
w
'
)
as
file
:
file
.
write
(
whitelist
)
whiteList
=
''
def
core
(
cardDirs
,
localroot
=
os
.
getcwd
()):
sections
,
ignore
=
get_sections
(
cardDirs
)
localIndexArr
,
orderArr
=
get_indexArr
(
sections
)
whitelist
=
''
index
=
generate_index_top
()
for
folder
in
cardDirs
:
# FolderFlag gets set to true at the first iteration
...
...
@@ -365,7 +475,7 @@ def core(cardDirs, localroot, localIndexArr, orderArr, sections, ignore):
header
=
generate_header
(
folder
,
permalink
,
shortcut
,
order
,
legacy_from
,
title
,
description
,
qms_yml
)
# add autogenerated links to whitelist
white
L
ist
+=
generate_whitelist_entry
(
folder
,
permalink
,
shortcut
)
white
l
ist
+=
generate_whitelist_entry
(
folder
,
permalink
,
shortcut
)
# add the header properly speaking
line_prepender
(
fileName
,
header
)
...
...
@@ -403,97 +513,9 @@ def core(cardDirs, localroot, localIndexArr, orderArr, sections, ignore):
print
(
"
+ New header added.
"
)
print
(
"
-----------------------
"
)
return
folderFlag
,
localIndexArr
,
whiteList
def
get_sections
(
cardDirs
):
sections
=
[]
# retrieve ignore list
ignore
=
get_ignore
()
# determine first the directories
for
direct
in
cardDirs
:
if
path
.
isdir
(
direct
)
and
has_subdirs
(
direct
):
dirs
=
os
.
listdir
(
direct
)
dirs
=
natsorted
(
dirs
)
for
d
in
dirs
:
if
d
[
0
]
!=
"
.
"
and
d
not
in
ignore
and
has_subdirs
(
direct
+
"
/
"
+
d
):
sections
.
append
(
d
)
sections
=
list
(
set
(
sections
))
sections
=
natsorted
(
sections
)
localIndexArr
=
sort_sections
(
sections
,
localIndexArr
,
orderArr
)
return
sections
,
ignore
def
get_indexArr
(
sections
):
localIndexArr
=
{
k
:
[]
for
k
in
range
(
len
(
sections
))}
orderArr
=
{
k
:
[]
for
k
in
range
(
len
(
sections
))}
return
localIndexArr
,
orderArr
def
sort_sections
(
sections
,
localIndexArr
,
orderArr
):
for
d
in
sections
:
indexS
=
sections
.
index
(
d
)
# join all subcategories to the index
# if all subcategories have a predefined order
if
len
(
orderArr
[
indexS
])
==
len
(
localIndexArr
[
indexS
])
-
1
and
len
(
orderArr
[
indexS
])
>
0
:
print
(
""
)
X
=
localIndexArr
[
indexS
][
1
:]
Y
=
orderArr
[
indexS
]
localIndexArr
[
indexS
]
=
[
x
for
_
,
x
in
sorted
(
zip
(
Y
,
X
))]
# natural sorting otherwise
else
:
localIndexArr
[
indexS
]
=
natsorted
(
localIndexArr
[
indexS
])
print
(
localIndexArr
)
index
=
generate_index
(
index
,
sections
,
localIndexArr
)
return
localIndexArr
def
generate_index_top
():
index
=
'
\n
<div class=
"
index-box-container
"
>
\n
'
return
index
def
generate_index
(
index
,
sections
,
localIndexArr
):
# determine the index
k
=
0
for
s
in
sections
:
index
+=
build_section_start
(
s
.
replace
(
"
-
"
,
"
"
).
capitalize
(),
s
)
index
+=
''
.
join
(
localIndexArr
[
k
])
index
+=
build_section_end
()
k
+=
1
# close the container
index
+=
"
\n
</div>
"
## add link to return to main index
index
+=
"""
<br><center><a href=
"
{{
'
/
'
| relative_url }}
"
>go back</a></center>
"""
index
+=
"""
<br><center><a href=
"
{{
'
/cards
'
| relative_url }}
"
>Overview of all HowTo cards</a></center>
"""
return
index
def
save_index
(
index
,
indexFile
):
# output the index
#print(index)
# Read in the file
#indexFile = "cards.md"
filedata
=
""
with
open
(
indexFile
,
'
r
'
)
as
file
:
for
line
in
file
:
filedata
+=
line
# stop reading once the index place holder has been reached
if
re
.
search
(
"
<!-- index -->
"
,
line
):
filedata
+=
"
[[ index ]]
"
break
# Replace the target string
filedata
=
filedata
.
replace
(
'
[[ index ]]
'
,
index
)
# Write the file out again
with
open
(
indexFile
,
'
w
'
)
as
file
:
file
.
write
(
filedata
)
return
index
,
whitelist
print
(
"
\n
> New index generated and saved in
"
+
indexFile
)
\ No newline at end of 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