gnunet-svn
[Top][All Lists]
Advanced

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

[www_shared] branch master updated (99a0de7 -> 1e9e766)


From: gnunet
Subject: [www_shared] branch master updated (99a0de7 -> 1e9e766)
Date: Tue, 04 May 2021 22:03:49 +0200

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

dold pushed a change to branch master
in repository www_shared.

    from 99a0de7  better error messages
     new 9f19bf9  make localized self URLs absolute
     new 1e9e766  invert loop, generate site once per locale

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 site.py | 161 ++++++++++++++++++++++++++++++++++++----------------------------
 1 file changed, 92 insertions(+), 69 deletions(-)

diff --git a/site.py b/site.py
index 344a493..035d178 100644
--- a/site.py
+++ b/site.py
@@ -36,7 +36,7 @@ from inc.textproc import cut_news_text, cut_article
 from inc.fileproc import copy_files, copy_tree
 from inc.make_rss import *
 
-class gen_site:
+class SiteGenerator:
     def __init__(self, debug):
         self.debug = debug
 
@@ -78,13 +78,15 @@ class gen_site:
     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(".")
             q = list(_.glob("**/*.j2"))
             print(q)
-        # for in_file in glob.glob(root + "/*.j2"):
+        abs_cwd = Path(".").resolve()
+
         for in_file in Path(".").glob(root + "/*.j2"):
             in_file = str(in_file)
             if self.debug > 1:
@@ -93,16 +95,22 @@ class gen_site:
                                  in_file.rstrip(".j2")).groups()
             tmpl = env.get_template(in_file)
 
-            def self_localized(other_locale):
+            def self_localized(other_locale, relative=False):
                 """
                 Return URL for the current page in another locale.
                 """
-                if root == "news":
-                    return "../../" + other_locale + "/news/" + 
in_file.replace(
-                       root + '/', '').rstrip(".j2")
+                abs_file = Path(in_file).resolve()
+                baseurl = os.environ.get("BASEURL")
+                if relative or not baseurl:
+                    if root == "news":
+                        return "../../" + other_locale + "/news/" + 
in_file.replace(
+                           root + '/', '').rstrip(".j2")
+                    else:
+                        return "../" + other_locale + "/" + in_file.replace(
+                           root + '/', '').rstrip(".j2")
                 else:
-                    return "../" + other_locale + "/" + in_file.replace(
-                       root + '/', '').rstrip(".j2")
+                    return baseurl + other_locale + "/" + 
str(Path(abs_file).relative_to(abs_cwd)).rstrip(".j2")
+
 
             def url_localized(filename):
                 if root == "news":
@@ -138,70 +146,85 @@ class gen_site:
                 #    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:
+                    if self.debug > 1:
+                        print(Path.cwd())
+                    f.write(content)
+                except:
+                    print(e)
 
 
-                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)
+    def run(self, root, conf, env):
+        # root = "../" + root
+        if self.debug > 1:
+            _ = Path(".")
+            q = list(_.glob("**/*.j2"))
+            print(q)
 
-                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")
+        # 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
 
-                outdir = Path("rendered")
+            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)
 
-                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:
-                        if self.debug > 1:
-                            print(Path.cwd())
-                        f.write(content)
-                    except e as Error:
-                        print(e)
+# Deprecated alias.  Should be removed once all sites have
+# been updated.
+gen_site = SiteGenerator

-- 
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]