[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[www_shared] branch master updated: cleanup
From: |
gnunet |
Subject: |
[www_shared] branch master updated: cleanup |
Date: |
Thu, 06 May 2021 19:07:39 +0200 |
This is an automated email from the git hooks/post-receive script.
dold pushed a commit to branch master
in repository www_shared.
The following commit(s) were added to refs/heads/master by this push:
new 4e83d96 cleanup
4e83d96 is described below
commit 4e83d962573f95f1bc82440c983638aeeda69e98
Author: Florian Dold <florian@dold.me>
AuthorDate: Thu May 6 19:05:18 2021 +0200
cleanup
---
fileproc.py | 93 ---------------------------------------------------------
make_sitemap.py | 51 -------------------------------
site.py | 42 +++++++++++++++++++++++++-
3 files changed, 41 insertions(+), 145 deletions(-)
diff --git a/fileproc.py b/fileproc.py
deleted file mode 100644
index 3a1d1ba..0000000
--- a/fileproc.py
+++ /dev/null
@@ -1,93 +0,0 @@
-# Copyright (C) 2019 GNUnet e.V.
-#
-# This code is derived from code contributed to GNUnet e.V.
-# by nikita <nikita@n0.is>
-#
-# Permission to use, copy, modify, and/or distribute this software for
-# any purpose with or without fee is hereby granted.
-#
-# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
-# WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
-# WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
-# AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
-# DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
-# OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
-# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-# PERFORMANCE OF THIS SOFTWARE.
-#
-# SPDX-License-Identifier: 0BSD
-
-from pathlib import Path
-import os
-import shutil
-
-def copy_tree(source, destination):
- destination.mkdir(parents=True, exist_ok=True)
- for _ in os.listdir(source):
- i = source / _
- o = destination / _
- if i.is_dir():
- copy_tree(i, o)
- else:
- shutil.copy2(str(i), str(o))
-
-
-def copy_files(kind, conf, locale, inlist, ptarget):
- o = Path(ptarget)
- for item in conf[inlist]:
- i = Path(kind + "/" + item["file"])
- # print(i)
- for t in item["targets"]:
- d_loc = o / locale / t
- d = o / t
- # print(d)
- if i.is_file() is not False:
- d_loc.write_text(i.read_text())
- print("copied " + str(i) + " to " + str(d_loc) + "...")
- d.write_text(i.read_text())
- print("copied " + str(i) + " to " + str(d) + "...")
-
-
-def rm_rf(directory):
- directory = Path(directory)
- for child in directory.glob('*'):
- if child.is_file():
- child.unlink()
- else:
- rm_rf(child)
- # directory.rmdir()
-
-
-def fileop(infile, outfile, action):
- """
- infile: inputfile, Path object
- outfile: outputfile, Path object
- action: action if any, String
- """
- i = Path(infile)
- o = Path(outfile)
- outdir = Path("rendered")
- if i.is_file() is not False:
- if action == "copy":
- # Write content of i to o.
- o.write_text(i.read_text())
- if action == "link":
- o.symlink_to(i)
-
-
-def write_name(filename, infile, locale, replacer):
- return "./rendered/" + locale + "/" + infile.replace(replacer,
- '').rstrip(".j2")
-
-
-def localized(filename, locale, *args):
- if len(args) == 0:
- return "../" + locale + "/" + filename
- ext = kwargs.get('ext', None)
- if ext is not None:
- lf = filename + "." + locale + "." + ext
- lp = Path(lf)
- if locale == "en" or not lp.is_file():
- return "../" + filename + "." + ext
- else:
- return "../" + lf
diff --git a/make_sitemap.py b/make_sitemap.py
deleted file mode 100644
index 3bccc32..0000000
--- a/make_sitemap.py
+++ /dev/null
@@ -1,51 +0,0 @@
-# Copyright (C) 2019 GNUnet e.V.
-#
-# This code is derived from code contributed to GNUnet e.V.
-# by nikita <nikita@n0.is>
-#
-# Permission to use, copy, modify, and/or distribute this software for any
-# purpose with or without fee is hereby granted.
-#
-# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE
-# LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
-# OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
-# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
-# ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
-# THIS SOFTWARE.
-#
-# SPDX-License-Identifier: 0BSD
-#
-# A sitemap generator.
-
-import sys
-from pathlib import Path
-from datetime import datetime
-
-def main():
- if len(sys.argv) >= 2 and sys.argv[1] == "-i":
- i = sys.argv[2]
- else:
- i = "rendered"
-
- p = Path(i)
- links = sorted(p.rglob("*.html"))
- t0 = datetime.now()
- timestamp = t0.strftime("%Y-%m-%d")
-
- o = Path("sitemap.xml")
- with o.open("w") as f:
- f.write('<?xml version="1.0" encoding="UTF-8"?>\n')
- f.write('<urlset\n')
- f.write('xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\n')
-
f.write('xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 ')
- f.write('http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"\n')
- f.write('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n')
- for link in links:
- f.write('<url><loc>' + str(link).lstrip("rendered") +
'</loc><lastmod>' + timestamp + '</lastmod><priority>1.0</priority></url>\n')
- f.write('</urlset>\n')
-
-
-if __name__ == "__main__":
- main()
diff --git a/site.py b/site.py
index 1b0eacf..985feb4 100644
--- a/site.py
+++ b/site.py
@@ -17,6 +17,7 @@
#
# SPDX-License-Identifier: 0BSD
import os
+import shutil
import os.path
import sys
import re
@@ -26,6 +27,7 @@ import codecs
import jinja2
from pathlib import Path, PurePosixPath, PurePath
from ruamel.yaml import YAML
+from datetime import datetime
# Make sure the current directory is in the search path when trying
# to import i18nfix.
@@ -33,7 +35,6 @@ sys.path.insert(0, ".")
import inc.i18nfix as i18nfix
from inc.textproc import cut_news_text, cut_article
-from inc.fileproc import copy_files, copy_tree
from inc.time import time_rfc822, time_now, conv_date_rfc822
@@ -95,6 +96,16 @@ def make_helpers(root, in_file, locale):
)
+def copytree(src, dst, symlinks=False, ignore=None):
+ for item in os.listdir(src):
+ s = os.path.join(src, item)
+ d = os.path.join(dst, item)
+ if os.path.isdir(s):
+ shutil.copytree(s, d, symlinks, ignore, dirs_exist_ok=True)
+ else:
+ shutil.copy2(s, d)
+
+
class SiteGenerator:
def __init__(self, debug=0, root="."):
self.root = Path(root).resolve()
@@ -169,9 +180,34 @@ class SiteGenerator:
except:
print(e)
+ def emit_sitemap(self):
+ p = self.root / "rendered"
+ links = sorted(p.rglob("*.html"))
+ t0 = datetime.now()
+ timestamp = t0.strftime("%Y-%m-%d")
+
+ o = p / "sitemap.xml"
+ with o.open("w") as f:
+ f.write('<?xml version="1.0" encoding="UTF-8"?>\n')
+ f.write("<urlset\n")
+ f.write('xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\n')
+
f.write('xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 ')
+
f.write('http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"\n')
+ f.write('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n')
+ for link in links:
+ f.write(
+ "<url><loc>"
+ + str(link).lstrip("rendered")
+ + "</loc><lastmod>"
+ + timestamp
+ + "</lastmod><priority>1.0</priority></url>\n"
+ )
+ f.write("</urlset>\n")
+
def run(self):
conf = self.config
root = self.root
+
for l in root.glob("locale/*/"):
if not l.is_dir():
@@ -204,3 +240,7 @@ class SiteGenerator:
continue
self.run_localized(locale, tr)
+
+ self.emit_sitemap()
+
+ copytree(root / "static", root / "rendered")
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [www_shared] branch master updated: cleanup,
gnunet <=