diff options
Diffstat (limited to 'inc/site.py')
-rw-r--r-- | inc/site.py | 50 |
1 files changed, 38 insertions, 12 deletions
diff --git a/inc/site.py b/inc/site.py index 67e5afa8..9fd9ac87 100644 --- a/inc/site.py +++ b/inc/site.py | |||
@@ -6,29 +6,51 @@ import gettext | |||
6 | import glob | 6 | import glob |
7 | import codecs | 7 | import codecs |
8 | import jinja2 | 8 | import jinja2 |
9 | import hashlib | 9 | from pathlib import Path, PurePosixPath, PurePath |
10 | from pathlib import Path, PurePosixPath | ||
11 | from ruamel.yaml import YAML | 10 | from ruamel.yaml import YAML |
12 | import inc.i18nfix | 11 | import inc.i18nfix as i18nfix |
13 | from inc.textproc import cut_news_text | 12 | from inc.textproc import cut_news_text |
14 | from inc.fileproc import copy_files | 13 | from inc.fileproc import copy_files, copy_tree |
15 | 14 | ||
16 | 15 | ||
17 | class gen_site: | 16 | class gen_site: |
17 | def __init__(self, debug): | ||
18 | self.debug = debug | ||
19 | |||
18 | def load_config(self, name="www.yml"): | 20 | def load_config(self, name="www.yml"): |
19 | yaml = YAML(typ='safe') | 21 | yaml = YAML(typ='safe') |
20 | site_configfile = Path(name) | 22 | site_configfile = Path(name) |
21 | return yaml.load(site_configfile) | 23 | return yaml.load(site_configfile) |
22 | 24 | ||
25 | def copy_trees(self, directory): | ||
26 | """ Take a directory name (string) and pass it to copy_tree() as Path object. """ | ||
27 | i = Path(directory) | ||
28 | o = Path("rendered/" + directory) | ||
29 | copy_tree(i, o) | ||
30 | |||
23 | def gen_abstract(self, conf, name, member, pages, length): | 31 | def gen_abstract(self, conf, name, member, pages, length): |
32 | if self.debug: | ||
33 | print("generating abstracts...") | ||
24 | for item in conf[name]: | 34 | for item in conf[name]: |
25 | item[member] = cut_news_text(item[pages], length) | 35 | item[member] = cut_news_text(item[pages], length) |
36 | if self.debug: | ||
37 | print("cwd: " + str(Path.cwd())) | ||
38 | if self.debug > 1: | ||
39 | print(conf["newsposts"]) | ||
40 | if self.debug: | ||
41 | print("[done] generating abstracts") | ||
26 | 42 | ||
27 | def run(self, root, conf, env): | 43 | def run(self, root, conf, env): |
28 | # os.chdir("..") | 44 | # root = "../" + root |
29 | print(os.getcwd()) | 45 | if self.debug: |
30 | root = "../" + root | 46 | _ = Path(".") |
31 | for in_file in glob.glob(root + "/*.j2"): | 47 | q = list(_.glob("**/*.j2")) |
48 | print(q) | ||
49 | # for in_file in glob.glob(root + "/*.j2"): | ||
50 | for in_file in Path(".").glob(root + "/*.j2"): | ||
51 | in_file = str(in_file) | ||
52 | if self.debug: | ||
53 | print(in_file) | ||
32 | name, ext = re.match(r"(.*)\.([^.]+)$", | 54 | name, ext = re.match(r"(.*)\.([^.]+)$", |
33 | in_file.rstrip(".j2")).groups() | 55 | in_file.rstrip(".j2")).groups() |
34 | tmpl = env.get_template(in_file) | 56 | tmpl = env.get_template(in_file) |
@@ -74,8 +96,14 @@ class gen_site: | |||
74 | # return "../" + x | 96 | # return "../" + x |
75 | return "../" + x | 97 | return "../" + x |
76 | 98 | ||
77 | for l in glob.glob("locale/*/"): | 99 | # for l in glob.glob("locale/*/"): |
78 | locale = os.path.basename(l[:-1]) | 100 | # https://bugs.python.org/issue22276 |
101 | for l in list(x for x in Path(".").glob("locale/*/") if x.is_dir()): | ||
102 | l = str(PurePath(l).name) | ||
103 | if self.debug: | ||
104 | print(l) | ||
105 | # locale = os.path.basename(l[:-1]) | ||
106 | locale = l | ||
79 | 107 | ||
80 | tr = gettext.translation("messages", | 108 | tr = gettext.translation("messages", |
81 | localedir="locale", | 109 | localedir="locale", |
@@ -106,8 +134,6 @@ class gen_site: | |||
106 | root + '/', '').rstrip(".j2") | 134 | root + '/', '').rstrip(".j2") |
107 | 135 | ||
108 | outdir = Path("rendered") | 136 | outdir = Path("rendered") |
109 | if outdir.exists() is False: | ||
110 | sys.exit(1) | ||
111 | 137 | ||
112 | if root == "news": | 138 | if root == "news": |
113 | langdir = outdir / locale / root | 139 | langdir = outdir / locale / root |