tested with another website, fixed bugs
authorSabine Engelhardt (Becker) <frosch@atari-frosch.de>
Tue, 11 Apr 2017 21:43:45 +0000 (23:43 +0200)
committerSabine Engelhardt (Becker) <frosch@atari-frosch.de>
Tue, 11 Apr 2017 21:43:45 +0000 (23:43 +0200)
.gitignore
filters/atarifrosch.py
filters/saphisecke.py [new file with mode: 0755]
filters/saphisecke.py~ [new file with mode: 0755]
fullsettings.py
preparesite.py
sites/atarifrosch/DEFAULTS/__pycache__/settings.cpython-34.pyc [deleted file]
sites/atarifrosch/DEFAULTS/settings.py

index 8be87d5..57e3ed8 100644 (file)
@@ -1,4 +1,5 @@
 __pycache__/
 */__pycache/
 html/
+sites/
 
index 8e3644b..c130715 100755 (executable)
@@ -7,6 +7,8 @@ targetpath = "/home/frosch/projekte/htmlglue/sites/atarifrosch/"
 logfile = targetpath + "preparesite.log"
 loglevel = 5
 
+oldenc = "iso8859-15"
+
 ignoredirs = []
 ignoredirs.append("/bilder")
 ignoredirs.append("/bilder/18c3")
diff --git a/filters/saphisecke.py b/filters/saphisecke.py
new file mode 100755 (executable)
index 0000000..eea2e14
--- /dev/null
@@ -0,0 +1,53 @@
+#!/usr/bin/env python3
+# -*- coding: utf8 -*-
+
+origpath = "/srv/saphisecke/"
+fileext = ".html"
+targetpath = "/home/frosch/projekte/htmlglue/sites/saphisecke/"
+logfile = targetpath + "preparesite.log"
+loglevel = 5
+
+oldenc = "iso8859-1"
+
+ignoredirs = []
+ignoredirs.append("/bilder")
+ignoredirs.append("/bilder/orig")
+ignoredirs.append("/stats")
+ignoredirs.append("/susilein/work")
+ignoredirs.append("/susilein/work/bak")
+
+ignorefiles = ["STANDARD.html"]
+
+ignorehtml = [] 
+# This defines a keyword from the first line and a keyword from the
+# last line that has to be ignored. %% is the placeholder between start
+# and end.
+# Only preparesite.py changes this into a dictionary.
+# Do NOT ignore the menu here, as it needs a special 'treatment'.
+
+ignorehtml.append('<body> == <div id="head">')
+ignorehtml.append('<div id="foot"> == </html>')
+
+menustart = '<div id="navi">'
+menuend = '<!-- div#navi -->'
+firstmenuitem = 'menuitem.append(["htm", "", "/index.html", "Startseite"])\n'
+
+headlinekey = "<h1>"
+
+contentstart = '<div id="content">'
+contentend = '</div><!-- div#content -->'
+
+# while reading the content, we can replace a few things
+# that are mostly left from the iso-latin age …
+replacement = {}
+replacement["<li> "] = "<li>"
+replacement["<p> "] = "<p>"
+replacement[" </"] = "</"
+replacement["&bdquo;"] = "„"
+replacement["&rdquo;"] = "“"
+replacement["&mdash;"] = "–"
+replacement["&reg;"] = "®"
+replacement["(tm)"] = "™"
+replacement["..."] = "…"
+replacement["&middot;"] = "·"
+replacement['<html xmlns="http://www.w3.org/1999/xhtml">'] = '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">'
diff --git a/filters/saphisecke.py~ b/filters/saphisecke.py~
new file mode 100755 (executable)
index 0000000..5d05faf
--- /dev/null
@@ -0,0 +1,52 @@
+#!/usr/bin/env python3
+# -*- coding: utf8 -*-
+
+origpath = "/srv/saphisecke/"
+fileext = ".html"
+targetpath = "/home/frosch/projekte/htmlglue/sites/saphisecke/"
+logfile = targetpath + "preparesite.log"
+loglevel = 5
+
+oldenc = "iso8859-1"
+
+ignoredirs = []
+ignoredirs.append("/bilder")
+ignoredirs.append("/bilder/orig")
+ignoredirs.append("/stats")
+ignoredirs.append("/susilein/work")
+ignoredirs.append("/susilein/work/bak")
+
+ignorefiles = ["STANDARD.html"]
+
+ignorehtml = [] 
+# This defines a keyword from the first line and a keyword from the
+# last line that has to be ignored. %% is the placeholder between start
+# and end.
+# Only preparesite.py changes this into a dictionary.
+# Do NOT ignore the menu here, as it needs a special 'treatment'.
+
+ignorehtml.append('<body> == <div id="head">')
+ignorehtml.append('<div id="foot"> == </html>')
+
+menustart = '<div id="navi">'
+menuend = '<!-- div#navi -->'
+firstmenuitem = 'menuitem.append(["htm", "", "/index.html", "Startseite"])\n'
+
+headlinekey = "<h1>"
+
+contentstart = '<div id="content">'
+contentend = '</div><!-- div#content -->'
+
+# while reading the content, we can replace a few things
+# that are mostly left from the iso-latin age …
+replacement = {}
+replacement["<li> "] = "<li>"
+replacement["<p> "] = "<p>"
+replacement[" </"] = "</"
+replacement["&bdquo;"] = "„"
+replacement["&rdquo;"] = "“"
+replacement["&mdash;"] = "–"
+replacement["&reg;"] = "®"
+replacement["(tm)"] = "™"
+replacement["..."] = "…"
+replacement["&middot;"] = "·"
index 7e48027..230483c 100644 (file)
@@ -15,7 +15,7 @@ def makehead(contentfile, targetfile, myurl):
 # this function that creates the footer section, using a SNIPPETS file, the
 # timestamp of the content file, and the current date/time. Of course you
 # don't have to use this and can build your footer the way you want it :-)
-def makefooter(contentfile, targetfile, myurl):
+def makefoot(contentfile, targetfile, myurl):
     from os import path
     from datetime import datetime
     from time import strftime
@@ -152,15 +152,13 @@ addcssfile = ["akv.css all"]
 # .htm files must exist in the SNIPPETS directory of the theme. Don't add
 # css files this way, use the addcssfile variable instead. Optional.
 # Variable type: list of strings
-addmeta = ["meta.flattrverify.htm"]
-# (BTW, flattrverify is needed only once: in the <head> section of the
-# start page in order to identify your site to flattr.com.)
+addmeta = [""]
 
 # You can add additional HTML code to the <head> section. Optional. You can
 # also add inline (!) CSS for an individual page by adding another SNIPPETS
 # file to this list in the .py file of that page.
 # Variable type: list of strings
-addhead = ["flattrscript.htm", "akvhead.htm"]
+addhead = ["akvhead.htm"]
 
 ## Now for the content section:
 
@@ -180,17 +178,6 @@ addtobody["[MYURL]"] = myurl
 addtobody["[AKVSBODY]"] = "akvsbody.htm"
 addtobody["[LOGO]"] = "logo.htm"
 
-# You will need to add these variables in order to be able to use a flattr
-# button on the current page. myurl (created earlier), Thing number, and
-# Thing name are needed to call the flattr api correctly.
-# Be reminded that you need to place the 'flattrscript.htm' snippet in the
-# <head> section of the page in order to get the flattr button to work.
-addtobody["[FLATTRBUTTON]"] = "flattrbutton.htm"
-# Although the 'thing' is a number, we need a string here, not a digit!
-addtobody["[FLATTRTHING]"] = "000000"
-# You also need to state the name of your flattr thing.
-addtobody["[THINGNAME]"] = "this-is-my-flattr-thing"
-
 # As the menu is not given as an .htm file, but built by htmlglue while
 # processing a menu.py of a (sub)directory of the theme, we cannot use a
 # dictionary like addtobody to add static menu entries from the SNIPPETS on
index 4a9f6d4..24e4825 100755 (executable)
@@ -10,27 +10,19 @@ from defaults import myversion
 
 # functions
 
-def checkenc(curfile):
+def checkenc(curfile, tmpfile, oldenc):
     logging.debug('Checking %s for old encoding.', curfile)
-    with open(curfile, 'r', encoding='iso8859-15') as f:
+    with open(curfile, 'r', encoding=oldenc) as f:
         firstline = f.readline().strip()
-        # <?xml version='1.0' encoding='ISO-8859-1'?>
         logging.debug('Found: %s', firstline)
         if firstline.startswith("<?xml"):
             logging.debug('%s has old encoding.', curfile)
-            firstlineparts = firstline.split("encoding")
-            enc = firstlineparts[1].replace("=", "")
-            enc = enc.replace("'", "")
-            enc = enc.replace("?>", "")
-            enc = enc.strip()
-            if enc.startswith("ISO-"):
-                enc = enc.replace("ISO-", "iso")
-            logging.debug('Changing encoding of %s from %s to utf8.', curfile, enc)
-            with open(curfile, 'r', encoding=enc) as toconv:
+            with open(curfile, 'r', encoding=oldenc) as toconv:
                 cont = toconv.read()
-            with open(curfile, 'w', encoding='utf8') as toconv:
+            with open(tmpfile, 'w', encoding='utf8') as toconv:
                 toconv.write(cont)
-            logging.debug('Successfully changed encoding of <%s>.', curfile)
+            logging.debug('Successfully saved reencoded version to <%s>.', tmpfile)
+            return True
 
 def checkfolder(curpath):
     igndir = False
@@ -42,18 +34,26 @@ def checkfolder(curpath):
 
 # end of functions
 
+mypath = os.path.dirname(sys.argv[0])
 sitename = sys.argv[1]
 filterpath = "filters/"
 sys.path.insert(0, filterpath)
 flt = __import__(sitename)
 
-# first we take care for logging, logging is important
+if not flt.targetpath.endswith("/"):
+    targetpath = flt.targetpath + "/"
+else:
+    targetpath = flt.targetpath
+logging.debug('Target path is <%s>.', targetpath)
+
 try:
     flt.logfile
 except NameError:
     logfile = sitename + ".log"
 else:
     logfile = flt.logfile
+if not os.path.exists(logfile):
+    logfile = mypath + "/prepare-" + sitename + ".log"
 
 try:
     flt.loglevel
@@ -78,7 +78,29 @@ elif loglevel == 1:
 else:
     logging.basicConfig(format='%(asctime)s %(message)s', datefmt=dateformat, filename=logfile,level=logging.INFO)
     logging.error('could not identify loglevel, using INFO as default')
-                                                                                                                                                                  
+
+
+if not os.path.exists(targetpath):
+    os.mkdir(targetpath)
+    cssdir = targetpath + "/CSS"
+    os.mkdir(cssdir)
+    defaultsdir = targetpath + "/DEFAULTS"
+    os.mkdir(defaultsdir)
+    snippetdir = targetpath + "/SNIPPETS"
+    os.mkdir(snippetdir)
+    fullsettings = mypath + "/fullsettings.py"
+    localsettings = defaultsdir + "/settings.py"
+    import shutil
+    shutil.copyfile(fullsettings, localsettings)
+    initfile = targetpath + "/__init__.py"
+    init = open(initfile, "w")
+    init.close()
+    call(["/bin/chmod", "755", initfile])
+    outline = "Please edit <" + localsettings + ">!"
+    print(outline)
+    print("Without a correct filter the site cannot be prepared for htmlglue.")
+    logging.critical('Please edit DEFAULTS/settings.py.')
+    sys.exit()
 
 if not flt.origpath.startswith("/"):
     print("This is no full path.  Aborted.")
@@ -94,28 +116,6 @@ else:
     fileext = flt.fileext
 logging.debug('HTML files end with <%s>.', fileext)
 
-if not flt.targetpath.endswith("/"):
-    targetpath = flt.targetpath + "/"
-else:
-    targetpath = flt.targetpath
-logging.debug('Target path is <%s>.', targetpath)
-
-if not os.path.exists(targetpath):
-    os.mkdir(targetpath, "0755")
-    newdir = targetpath + "/CSS"
-    os.mkdir(newdir, "0755")
-    newdir = targetpath + "/DEFAULTS"
-    setfile = newdir + "/settings.py"
-    call(["/bin/touch", setfile])
-    call(["/bin/chmod", "755", setfile])
-    os.mkdir(newdir, "0755")
-    newdir = targetpath + "/SNIPPETS"
-    os.mkdir(newdir, "0755")
-    print("Please create at least DEFAULTS/settings.py.")
-    print("Without a filter the site cannot be prepared for htmlglue.")
-    logging.critical('Please create at least DEFAULTS/settings.py.')
-    exit()
-
 settingpath = targetpath + "DEFAULTS/"
 logging.debug('Settings will be searched in <%s>.', settingpath)
 sys.path.insert(1, settingpath)
@@ -174,9 +174,13 @@ for dirpath, dirs, files in os.walk(origpath):
             igndir = checkfolder(curpath)
             if not igndir:
                 curfile = os.path.join(dirpath, filename)
+                tmpfile = os.path.join(dirpath, "preptmp.html")
                 logging.info('Next file to process is <%s>.', curfile)
+                newenc = False
                 # first check for an old encoding
-                checkenc(curfile)
+                newenc = checkenc(curfile, tmpfile, flt.oldenc)
+                if newenc:
+                    curfile = tmpfile
 
                 htmlfile = open(curfile, "rt")
                 logging.debug('Successfully opened <%s> for processing.', curfile)
@@ -313,8 +317,9 @@ for dirpath, dirs, files in os.walk(origpath):
                             if contentpart != settings.dcpublisher:
                                 pyfile.write("dcpublisher = '" + contentpart + ln)
                         elif "DC.Coverage" in curline:
-                            if contentpart != settings.dccoverage:
-                                pyfile.write("dccoverage = '" + contentpart + ln)
+                            if settings.dccoverage != "":
+                                if contentpart != settings.dccoverage:
+                                    pyfile.write("dccoverage = '" + contentpart + ln)
                         elif "DC.Rights" in curline:
                             if contentpart != settings.dcrights:
                                 pyfile.write("dcrights = '" + contentpart + ln)
@@ -348,7 +353,13 @@ for dirpath, dirs, files in os.walk(origpath):
                         elif "stylesheet" in curline:
                             csspart = curline.split('href="')[1]
                             csspart = csspart.split('"', 1)[0]
-                            csspart = csspart.rsplit("/")[1]
+                            csspart = csspart.strip()
+                            slash = csspart.count("/")
+                            if slash > 1:
+                                csspart = csspart.rsplit("/")[1]
+                            else:
+                                csspart = csspart.replace("/", "")
+
                             if csspart != settings.stylesheet:
                                 # <link rel="stylesheet" media="all" href="/akv.css" type="text/css" />
                                 media = curline.split('media="')[1]
@@ -417,3 +428,7 @@ for dirpath, dirs, files in os.walk(origpath):
                     menu.close()
                     call(["/bin/chmod", "755", menufile])
                     logging.debug('Successfully created menu.py for <%s>.', curpath)
+                    if newenc:
+                        os.remove(tmpfile)
+                        logging.debug('Deleted temporary source file <%s>.', tmpfile)
+                
\ No newline at end of file
diff --git a/sites/atarifrosch/DEFAULTS/__pycache__/settings.cpython-34.pyc b/sites/atarifrosch/DEFAULTS/__pycache__/settings.cpython-34.pyc
deleted file mode 100644 (file)
index 810e92a..0000000
Binary files a/sites/atarifrosch/DEFAULTS/__pycache__/settings.cpython-34.pyc and /dev/null differ
index d55eec8..23a84c6 100755 (executable)
@@ -1,7 +1,7 @@
 #!/usr/bin/env python3
 # -*- coding: utf8 -*-
 
-def makefooter(contentfile, targetfile, myurl):
+def makefoot(contentfile, targetfile, myurl):
     from os import path
     from datetime import datetime
     from time import strftime
@@ -50,9 +50,9 @@ menupos = "above"
 
 metakeywords = "atari-frosch, atari, computer, depression, autismus"
 
-# dictionary of variables within content files which need to be replaced
-# can be extended in $file.py files
-
 replacement = {}
-replacement["[FLATTRBUTTON]"] = "flattrbutton.htm"
-replacement["[FLATTRSCRIPT]"] = "flattrscript.htm"
+
+headline = "Qua®k!"
+
+# uncomment for use in htmlglue; preparesite would stop with an error message
+# pagefoot = makefoot(contentfile, targetfile, myurl)