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
222e5754
Verified
Commit
222e5754
authored
2 years ago
by
Laurent Heirendt
Browse files
Options
Downloads
Patches
Plain Diff
simplify
parent
be3ac30f
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
library.py
+109
-96
109 additions, 96 deletions
library.py
with
109 additions
and
96 deletions
library.py
+
109
−
96
View file @
222e5754
...
...
@@ -288,107 +288,120 @@ def get_title(localroot, root, file):
return
title
,
qms_yml
,
yml_file
def
core
(
localroot
,
folder
,
localIndexArr
,
orderArr
,
whiteList
,
folderFlag
,
d
,
sections
):
# get the index of the section
indexS
=
sections
.
index
(
d
)
maxOrder
=
0
if
len
(
localIndexArr
[
indexS
])
==
0
:
localIndexArr
[
indexS
]
=
[
"
\n
"
]
for
root
,
dirs
,
files
in
os
.
walk
(
folder
+
"
/
"
+
d
):
for
file
in
files
:
if
file
.
endswith
(
"
.md
"
):
fileName
=
os
.
path
.
join
(
root
,
file
)
# ignore subsections (.md files that start with _)
if
file
[
0
]
!=
"
_
"
:
print
(
"
> Generating header for:
"
+
fileName
)
# save order and legacy section
order
=
save_tag
(
localroot
,
root
,
file
,
"
card_order
"
)
legacy_from
=
save_legacy_from
(
localroot
,
root
,
file
)
description
=
save_tag
(
localroot
,
root
,
file
,
"
description
"
)
# extract the title from the QMS metadata
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
)
# generate a permalink
permalink
=
"
/
"
+
root
+
"
/
"
# generate the shortcut
shortcut
=
re
.
sub
(
folder
,
''
,
root
)
# remove the first /
shortcut
=
shortcut
[
1
:]
# replace the / with a :
shortcut
=
re
.
sub
(
'
/
'
,
'
:
'
,
shortcut
)
if
len
(
order
)
>
0
:
# find the maximum of existing orders
if
folderFlag
:
if
len
(
orderArr
[
indexS
])
>
0
:
maxOrder
=
max
(
orderArr
[
indexS
])
else
:
maxOrder
=
0
# after determining the max order, set the folder flag to False to avoid another entry into the same block of code
folderFlag
=
False
tmp
=
orderArr
[
indexS
].
copy
()
tmp
.
append
(
maxOrder
+
int
(
order
))
orderArr
[
indexS
]
=
tmp
else
:
orderArr
[
indexS
]
=
[]
# generate the header for each card
header
=
generate_header
(
folder
,
permalink
,
shortcut
,
order
,
legacy_from
,
title
,
description
,
qms_yml
)
# add autogenerated links to whitelist
whiteList
+=
generate_whitelist_entry
(
folder
,
permalink
,
shortcut
)
# add the header properly speaking
line_prepender
(
fileName
,
header
)
# open file and get the title after the header
if
"
qms
"
in
root
:
header_offset
=
3
else
:
header_offset
=
1
if
not
qms_yml
:
count
=
0
title
=
""
bp
=
n
+
header_offset
with
open
(
fileName
,
'
r
'
)
as
f
:
for
line
in
f
:
count
+=
1
if
count
==
bp
:
if
len
(
line
)
>
2
:
title
=
line
break
def
core
(
cardDirs
,
localroot
,
localIndexArr
,
orderArr
,
sections
,
ignore
):
whiteList
=
''
for
folder
in
cardDirs
:
# FolderFlag gets set to true at the first iteration
folderFlag
=
True
# check if folder exists
if
path
.
isdir
(
folder
)
and
folder
not
in
ignore
:
dirs
=
os
.
listdir
(
folder
)
dirs
=
natsorted
(
dirs
)
for
d
in
dirs
:
if
d
[
0
]
!=
"
.
"
and
d
not
in
ignore
and
has_subdirs
(
folder
+
"
/
"
+
d
):
# get the index of the section
indexS
=
sections
.
index
(
d
)
maxOrder
=
0
if
len
(
localIndexArr
[
indexS
])
==
0
:
localIndexArr
[
indexS
]
=
[
"
\n
"
]
for
root
,
dirs
,
files
in
os
.
walk
(
folder
+
"
/
"
+
d
):
for
file
in
files
:
if
file
.
endswith
(
"
.md
"
):
fileName
=
os
.
path
.
join
(
root
,
file
)
# ignore subsections (.md files that start with _)
if
file
[
0
]
!=
"
_
"
:
print
(
"
> Generating header for:
"
+
fileName
)
# save order and legacy section
order
=
save_tag
(
localroot
,
root
,
file
,
"
card_order
"
)
legacy_from
=
save_legacy_from
(
localroot
,
root
,
file
)
description
=
save_tag
(
localroot
,
root
,
file
,
"
description
"
)
# extract the title from the QMS metadata
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
)
# generate a permalink
permalink
=
"
/
"
+
root
+
"
/
"
# generate the shortcut
shortcut
=
re
.
sub
(
folder
,
''
,
root
)
# remove the first /
shortcut
=
shortcut
[
1
:]
# replace the / with a :
shortcut
=
re
.
sub
(
'
/
'
,
'
:
'
,
shortcut
)
if
len
(
order
)
>
0
:
# find the maximum of existing orders
if
folderFlag
:
if
len
(
orderArr
[
indexS
])
>
0
:
maxOrder
=
max
(
orderArr
[
indexS
])
else
:
maxOrder
=
0
# after determining the max order, set the folder flag to False to avoid another entry into the same block of code
folderFlag
=
False
tmp
=
orderArr
[
indexS
].
copy
()
tmp
.
append
(
maxOrder
+
int
(
order
))
orderArr
[
indexS
]
=
tmp
else
:
bp
+=
1
orderArr
[
indexS
]
=
[]
# remove first and last chars
title
=
title
.
rstrip
(
"
\n\r
"
)
title
=
title
[
2
:]
# open file and get the title after the header
#list_titles.append({ 'name': name, 'link': build_link(name + ' -- ' + title, permalink)}
)
# generate the header for each card
header
=
generate_header
(
folder
,
permalink
,
shortcut
,
order
,
legacy_from
,
title
,
description
,
qms_yml
)
localIndexArr
[
indexS
].
append
(
build_link
(
title
,
root
))
# add autogenerated links to whitelist
whiteList
+=
generate_whitelist_entry
(
folder
,
permalink
,
shortcut
)
# output
print
(
"
+ New header added.
"
)
print
(
"
-----------------------
"
)
# add the header properly speaking
line_prepender
(
fileName
,
header
)
# open file and get the title after the header
if
"
qms
"
in
root
:
header_offset
=
3
else
:
header_offset
=
1
if
not
qms_yml
:
count
=
0
title
=
""
bp
=
n
+
header_offset
with
open
(
fileName
,
'
r
'
)
as
f
:
for
line
in
f
:
count
+=
1
if
count
==
bp
:
if
len
(
line
)
>
2
:
title
=
line
break
else
:
bp
+=
1
# remove first and last chars
title
=
title
.
rstrip
(
"
\n\r
"
)
title
=
title
[
2
:]
# open file and get the title after the header
#list_titles.append({ 'name': name, 'link': build_link(name + ' -- ' + title, permalink)})
localIndexArr
[
indexS
].
append
(
build_link
(
title
,
root
))
# output
print
(
"
+ New header added.
"
)
print
(
"
-----------------------
"
)
return
folderFlag
,
localIndexArr
,
whiteList
...
...
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