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
0a77f845
Verified
Commit
0a77f845
authored
5 years ago
by
Laurent Heirendt
Browse files
Options
Downloads
Patches
Plain Diff
check existence of folder
parent
7474bbca
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
+89
-89
89 additions, 89 deletions
.ci/generateIndex.py
with
89 additions
and
89 deletions
.ci/generateIndex.py
+
89
−
89
View file @
0a77f845
import
os
,
re
folder
=
"
internal
"
from
os
import
path
def
line_prepender
(
filename
,
line
):
with
open
(
filename
,
'
r+
'
)
as
f
:
...
...
@@ -57,11 +56,12 @@ sections = []
# determine first the directories
for
direct
in
cardDirs
:
dirs
=
os
.
listdir
(
direct
)
if
path
.
isdir
(
direct
):
dirs
=
os
.
listdir
(
direct
)
for
d
in
dirs
:
if
d
[
0
]
!=
"
.
"
:
sections
.
append
(
d
)
for
d
in
dirs
:
if
d
[
0
]
!=
"
.
"
:
sections
.
append
(
d
)
sections
=
list
(
set
(
sections
))
sections
.
sort
()
...
...
@@ -70,89 +70,89 @@ index = ""
localIndexArr
=
[[]]
*
len
(
sections
)
for
folder
in
cardDirs
:
# check
here
if folder exists
dirs
=
os
.
l
is
t
dir
(
folder
)
dirs
=
sorted
(
dirs
)
for
d
in
dirs
:
if
d
[
0
]
!=
"
.
"
:
# set the header of the section
#index += "\n### " + d.replace("-", " ").capitalize() + "\n"
# get the index of the section
indexS
=
sections
.
index
(
d
)
#print(indexS)
if
len
(
localIndexArr
[
indexS
])
==
0
:
localIndexArr
[
indexS
]
=
[
"
\n
"
]
# walk through the folders with all the cards
for
root
,
dirs
,
files
in
os
.
walk
(
folder
+
"
/
"
+
d
):
for
file
in
files
:
i
f
file
.
endswith
(
"
.md
"
)
:
file
Name
=
os
.
path
.
join
(
root
,
file
)
# ignore subsections (.md files that start with _)
if
file
[
0
]
!=
"
_
"
:
print
(
"
> Generating header for:
"
+
fileName
)
# remove the previous header
remove_header
(
localroot
,
root
,
file
,
8
)
# 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
)
# define the header for each card
header
=
"
---
\n
"
header
+
=
"
layout: page
\n
"
header
+=
"
permalink:
"
+
permalink
+
"
\n
"
header
+=
"
shortcut:
"
+
shortcut
+
"
\n
"
header
+=
"
redirect_from:
\n
"
header
+=
"
- /cards/
"
+
shortcut
+
"
\n
"
header
+=
"
-
/internal
/cards/
"
+
shortcut
+
"
\n
"
header
+=
"
---
"
# add the header properly speaking
line_prepender
(
fileName
,
header
)
# open file and get the title after the header
count
=
0
title
=
""
bp
=
9
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
:]
#index += " * [" + title + "](./" + root + "/" + "\n"
localIndexArr
[
indexS
].
append
(
"
* [
"
+
title
+
"
](./
"
+
root
+
"
/
"
+
"
)
\n
"
)
# output
print
(
"
+ New header added.
"
)
print
(
"
-----------------------
"
)
# join all subcategories to the index
localIndexArr
[
indexS
].
sort
()
#index += ''.join(localIndexArr
)
# check if folder exists
if
path
.
isdir
(
folder
)
:
dirs
=
os
.
listdir
(
folder
)
dirs
=
sorted
(
dirs
)
for
d
in
dirs
:
if
d
[
0
]
!=
"
.
"
:
# set the header of the section
#index += "\n### " + d.replace("-", " ").capitalize() + "\n"
# get the index of the section
indexS
=
sections
.
index
(
d
)
#print(indexS)
if
len
(
localIndexArr
[
indexS
]
)
==
0
:
localIndexArr
[
indexS
]
=
[
"
\n
"
]
# walk through the folders with all the cards
for
root
,
dirs
,
file
s
in
os
.
walk
(
folder
+
"
/
"
+
d
)
:
f
or
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
)
# remove the previous header
remove_header
(
localroot
,
root
,
file
,
8
)
# 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
)
# define the header for each card
header
=
"
---
\n
"
header
+=
"
layout: page
\n
"
header
+=
"
permalink:
"
+
permalink
+
"
\n
"
header
+=
"
shortcut:
"
+
shortcut
+
"
\n
"
header
+=
"
redirect_from:
\n
"
header
+=
"
- /cards/
"
+
shortcut
+
"
\n
"
header
+=
"
- /internal/cards/
"
+
shortcut
+
"
\n
"
header
+=
"
---
"
# add the header properly speaking
line_prepender
(
fileName
,
header
)
# open file and get the title after the header
count
=
0
title
=
""
bp
=
9
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
:]
#index += "
* [" + title + "](./" + root + "/" + "\n"
localIndexArr
[
indexS
].
append
(
"
* [
"
+
title
+
"
](./
"
+
root
+
"
/
"
+
"
)
\n
"
)
# output
print
(
"
+ New header added.
"
)
print
(
"
-----------------------
"
)
# join all subcategories to the index
localIndexArr
[
indexS
].
sort
(
)
print
(
localIndexArr
)
...
...
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