2
2
3
3
import argparse
4
4
import json
5
- import os
6
5
from pathlib import Path
7
6
from copy import deepcopy
8
7
11
10
import toml
12
11
from jinja2 import Environment , FileSystemLoader
13
12
13
+ README_GEN_DIR = Path (__file__ ).resolve ().parent
14
+ APPS_REPO_ROOT = README_GEN_DIR .parent .parent
15
+
14
16
15
17
def value_for_lang (values : Dict , lang : str ):
16
18
if not isinstance (values , dict ):
@@ -27,20 +29,18 @@ def generate_READMEs(app_path: Path):
27
29
if not app_path .exists ():
28
30
raise Exception ("App path provided doesn't exists ?!" )
29
31
30
- if os . path . exists (app_path / "manifest.json" ):
32
+ if (app_path / "manifest.json" ). exists ( ):
31
33
manifest = json .load (open (app_path / "manifest.json" ))
32
34
else :
33
35
manifest = toml .load (open (app_path / "manifest.toml" ))
34
36
35
37
upstream = manifest .get ("upstream" , {})
36
38
37
- catalog = toml .load (
38
- open (Path (os .path .abspath (__file__ )).parent .parent .parent / "apps.toml" )
39
- )
39
+ catalog = toml .load ((APPS_REPO_ROOT / "apps.toml" ).open (encoding = "utf-8" ))
40
40
from_catalog = catalog .get (manifest ["id" ], {})
41
41
42
42
antifeatures_list = toml .load (
43
- open ( Path ( os . path . abspath ( __file__ )). parent . parent . parent / "antifeatures.toml" )
43
+ ( APPS_REPO_ROOT / "antifeatures.toml" ). open ( encoding = "utf-8 " )
44
44
)
45
45
46
46
if not upstream and not (app_path / "doc" / "DISCLAIMER.md" ).exists ():
@@ -49,17 +49,19 @@ def generate_READMEs(app_path: Path):
49
49
)
50
50
return
51
51
52
- env = Environment (loader = FileSystemLoader (Path (__file__ ).parent / "templates" ))
52
+ env = Environment (loader = FileSystemLoader (README_GEN_DIR / "templates" ))
53
+
54
+ screenshots : List [str ] = []
53
55
54
- screenshots : List [str ]
55
- screenshots = []
56
- if (app_path / "doc" / "screenshots" ).exists ():
56
+ screenshots_dir = app_path / "doc" / "screenshots"
57
+ if screenshots_dir .exists ():
57
58
# only pick files (no folder) on the root of 'screenshots'
58
- for entry in os .scandir (os .path .join (app_path , "doc" , "screenshots" )):
59
- if os .DirEntry .is_file (entry ):
60
- # ignore '.gitkeep' or any file whose name begins with a dot
61
- if not entry .name .startswith ("." ):
62
- screenshots .append (os .path .relpath (entry .path , app_path ))
59
+ for entry in screenshots_dir .iterdir ():
60
+ if not entry .is_file ():
61
+ continue
62
+ if entry .name .startswith ("." ):
63
+ continue
64
+ screenshots .append (str (entry .relative_to (app_path )))
63
65
64
66
# parse available README template and generate a list in the form of:
65
67
# > [("en", ""), ("fr", "_fr"), ...]
@@ -133,7 +135,7 @@ def generate_READMEs(app_path: Path):
133
135
description = "Automatically (re)generate README for apps"
134
136
)
135
137
parser .add_argument (
136
- "app_path" , help = "Path to the app to generate/update READMEs for"
138
+ "app_path" , type = Path , help = "Path to the app to generate/update READMEs for"
137
139
)
138
140
139
141
args = parser .parse_args ()
0 commit comments