gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[www_shared] 02/02: invert loop, generate site once per locale


From: gnunet
Subject: [www_shared] 02/02: invert loop, generate site once per locale
Date: Tue, 04 May 2021 22:03:51 +0200

This is an automated email from the git hooks/post-receive script.

dold pushed a commit to branch master
in repository www_shared.

commit 1e9e7661a47f73d0cd2d8889d4d6e5f8f7eca09d
Author: Florian Dold <florian@dold.me>
AuthorDate: Tue May 4 21:57:36 2021 +0200

    invert loop, generate site once per locale
---
 site.py | 135 +++++++++++++++++++++++++++++++++++-----------------------------
 1 file changed, 74 insertions(+), 61 deletions(-)

diff --git a/site.py b/site.py
index 71095f8..035d178 100644
--- a/site.py
+++ b/site.py
@@ -78,7 +78,8 @@ class SiteGenerator:
     def gen_rss(self, directory, conf, env):
         make_rss(directory, conf, env)
 
-    def run(self, root, conf, env):
+    def run_localized(self, root, conf, env, locale, tr):
+        abs_cwd = Path(".").resolve()
         # root = "../" + root
         if self.debug > 1:
             _ = Path(".")
@@ -145,72 +146,84 @@ class SiteGenerator:
                 #    return "../" + x
                 return "../" + x
 
-            # for l in glob.glob("locale/*/"):
-            # https://bugs.python.org/issue22276
-            for l in list(x for x in Path(".").glob("locale/*/") if 
x.is_dir()):
-                l = str(PurePath(l).name)
-                if self.debug > 1:
-                    print(l)
-                # locale = os.path.basename(l[:-1])
-                locale = l
-
+            content = tmpl.render(lang=locale,
+                                    lang_full=conf["langs_full"][locale],
+                                    url=url,
+                                    conf=conf,
+                                    siteconf=conf["siteconf"],
+                                    meetingnotesdata=conf["meetingnotes"],
+                                    newsdata=conf["newsposts"],
+                                    videosdata=conf["videoslist"],
+                                    self_localized=self_localized,
+                                    url_localized=url_localized,
+                                    url_static=url_static,
+                                    url_dist=url_dist,
+                                    svg_localized=svg_localized,
+                                    filename=name + "." + ext)
+
+            if root == "news":
+                out_name = "./rendered/" + locale + "/" + root + "/" + 
in_file.replace(
+                    root + '/', '').rstrip(".j2")
+            else:
+                out_name = "./rendered/" + locale + "/" + in_file.replace(
+                    root + '/', '').rstrip(".j2")
+
+            outdir = Path("rendered")
+
+            if root == "news":
+                langdir = outdir / locale / root
+            else:
+                langdir = outdir / locale
+
+            try:
+                langdir.mkdir(parents=True, exist_ok=True)
+            except FileNotFoundError as e:
+                print(e)
+
+            with codecs.open(out_name, "w", encoding='utf-8') as f:
                 try:
-                    tr = gettext.translation("messages",
-                                             localedir="locale",
-                                             languages=[locale])
-                except FileNotFoundError as e:
-                    print(f"WARNING: unable to find translations for locale 
'{locale}'", file=sys.stderr)
-                    continue
-
-                tr.gettext = i18nfix.wrap_gettext(tr.gettext)
-
-                env.install_gettext_translations(tr, newstyle=True)
-
-                if locale not in conf["langs_full"]:
-                    print(f"WARNING: skipping '{locale}, as 'langs_full' is 
not configured'", file=sys.stderr)
-                    continue
-
-                content = tmpl.render(lang=locale,
-                                      lang_full=conf["langs_full"][locale],
-                                      url=url,
-                                      conf=conf,
-                                      siteconf=conf["siteconf"],
-                                      meetingnotesdata=conf["meetingnotes"],
-                                      newsdata=conf["newsposts"],
-                                      videosdata=conf["videoslist"],
-                                      self_localized=self_localized,
-                                      url_localized=url_localized,
-                                      url_static=url_static,
-                                      url_dist=url_dist,
-                                      svg_localized=svg_localized,
-                                      filename=name + "." + ext)
+                    if self.debug > 1:
+                        print(Path.cwd())
+                    f.write(content)
+                except:
+                    print(e)
 
-                if root == "news":
-                    out_name = "./rendered/" + locale + "/" + root + "/" + 
in_file.replace(
-                        root + '/', '').rstrip(".j2")
-                else:
-                    out_name = "./rendered/" + locale + "/" + in_file.replace(
-                        root + '/', '').rstrip(".j2")
 
-                outdir = Path("rendered")
+    def run(self, root, conf, env):
+        # root = "../" + root
+        if self.debug > 1:
+            _ = Path(".")
+            q = list(_.glob("**/*.j2"))
+            print(q)
+
+        # for l in glob.glob("locale/*/"):
+        # https://bugs.python.org/issue22276
+        for l in list(x for x in Path(".").glob("locale/*/") if x.is_dir()):
+            l = str(PurePath(l).name)
+            if self.debug > 1:
+                print(l)
+            # locale = os.path.basename(l[:-1])
+            locale = l
 
-                if root == "news":
-                    langdir = outdir / locale / root
-                else:
-                    langdir = outdir / locale
+            try:
+                tr = gettext.translation("messages",
+                                            localedir="locale",
+                                            languages=[locale])
+            except FileNotFoundError as e:
+                print(f"WARNING: unable to find translations for locale 
'{locale}'", file=sys.stderr)
+                continue
+
+            tr.gettext = i18nfix.wrap_gettext(tr.gettext)
+
+            env.install_gettext_translations(tr, newstyle=True)
+
+            if locale not in conf["langs_full"]:
+                print(f"WARNING: skipping '{locale}, as 'langs_full' is not 
configured'", file=sys.stderr)
+                continue
+
+            self.run_localized(root, conf, env, locale, tr)
 
-                try:
-                    langdir.mkdir(parents=True, exist_ok=True)
-                except FileNotFoundError as e:
-                    print(e)
 
-                with codecs.open(out_name, "w", encoding='utf-8') as f:
-                    try:
-                        if self.debug > 1:
-                            print(Path.cwd())
-                        f.write(content)
-                    except:
-                        print(e)
 
 # Deprecated alias.  Should be removed once all sites have
 # been updated.

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]