-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathreadme-creator.py
92 lines (73 loc) · 2.88 KB
/
readme-creator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import glob
import os
import logging
from pathlib import Path
################################################################################
# logger
logger = logging.getLogger("palette-creator")
logger.setLevel(logging.INFO)
ConsoleOutputHandler = logging.StreamHandler()
logger.addHandler(ConsoleOutputHandler)
################################################################################
# constants
README_HEADER = """# C4-PlantUML-Themes
C4-PlantUML-Themes autogenerated from ColorBrewer and Seaborn palettes. See the C4-Plant UML [Themes](https://github.com/plantuml-stdlib/C4-PlantUML/blob/master/Themes.md) page for more information on the variables set by each theme.
Usage:
```
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' START - Handle local PlantUML render and remote hosting
'
!$THEME_NAME = cb_div_RdGy_9
'
!if (%getenv("LOCAL_EDIT_BLOG_ROOT") == "")
!$THEME_ROOT_PATH = "https://YOUR_HOSTNAME/resources/"
!else
!$THEME_ROOT_PATH = %getenv("LOCAL_EDIT_BLOG_ROOT") + "/resources/"
!endif
!define INCLUDE(a,b) ##a##b
' Define the theme name we're going to use
!if (%getenv("LOCAL_EDIT_BLOG_ROOT") == "")
!theme $THEME_NAME from https://YOUR_HOSTNAME/resources/palettes
!else
!theme $THEME_NAME from resources/palettes
!endif
!include INCLUDE($THEME_ROOT_PATH, c4-theme-common.puml)
' END - Handle local PlantUML render and remote hosting
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
```
where _c4-theme-common.puml_ is as follows (depends on [PlantUML PR 295](https://github.com/plantuml-stdlib/C4-PlantUML/pull/295) or later):
```
!include INCLUDE($THEME_ROOT_PATH, C4-PlantUML/C4.puml)
!include INCLUDE($THEME_ROOT_PATH, C4-PlantUML/C4_Component.puml)
!include INCLUDE($THEME_ROOT_PATH, C4-PlantUML/C4_Container.puml)
!include INCLUDE($THEME_ROOT_PATH, C4-PlantUML/C4_Context.puml)
!include INCLUDE($THEME_ROOT_PATH, C4-PlantUML/C4_Deployment.puml)
!include INCLUDE($THEME_ROOT_PATH, C4-PlantUML/C4_Dynamic.puml)
skinparam DefaultFontName Open Sans
skinparam Handwritten false
skinparam TitleFontSize 24
```
The generated theme files are below:
"""
################################################################################
# main
readme_text = README_HEADER
theme_files = glob.glob("./palettes/*.puml")
theme_files.sort()
for each_file in theme_files:
logger.info("Checking file: %s", each_file)
path_base = each_file.removesuffix(".puml")
file_palette_path = path_base + ".png"
file_preview_path = path_base + "-example.png"
file_basename = Path(each_file).name
readme_section = """
## {0}
| Palette | Image |
| ------------- | ------------- |
| [![{1}]({1})]({2}) | [![{3}]({3})]({2}) |
""".format(
file_basename, file_palette_path, each_file, file_preview_path
)
readme_text += readme_section
with open("README.md", "w") as readme_output:
readme_output.write(readme_text)