--- a/svghmi/i18n.py Wed Mar 31 08:25:18 2021 +0200
+++ b/svghmi/i18n.py Wed Mar 31 09:08:15 2021 +0200
@@ -68,11 +68,15 @@
with open(fname, 'w') as POT_file:
w.write(POT_file)
+def GetPoFiles(dirpath):
+ po_files = [fname for fname in os.listdir(dirpath) if fname.endswith(".po")]
+ po_files.sort()
+ return po_files
+
def ReadTranslations(dirpath):
""" Read all PO files from a directory and return a list of (langcode, translation_dict) tuples """
- po_files = [fname for fname in os.listdir(dirpath) if fname.endswith(".po")]
- po_files.sort()
+ po_files = GetPoFiles(dirpath)
translations = []
for po_fname in po_files:
--- a/svghmi/svghmi.py Wed Mar 31 08:25:18 2021 +0200
+++ b/svghmi/svghmi.py Wed Mar 31 09:08:15 2021 +0200
@@ -28,7 +28,8 @@
from editors.ConfTreeNodeEditor import ConfTreeNodeEditor
from XSLTransform import XSLTransform
from svghmi.i18n import EtreeToMessages, SaveCatalog, ReadTranslations,\
- MatchTranslations, TranslationToEtree, open_pofile
+ MatchTranslations, TranslationToEtree, open_pofile,\
+ GetPoFiles
from svghmi.hmi_tree import HMI_TYPES, HMITreeNode, SPECIAL_NODES
from svghmi.ui import SVGHMI_UI
from svghmi.fonts import GetFontTypeAndFamilyName, GetCSSFontFaceFromFontFile
@@ -400,13 +401,17 @@
return ret
- def GetFonts(self, _context):
+ def GetFontsFiles(self):
project_path = self.CTNPath()
fontdir = os.path.join(project_path, "fonts")
+ if os.path.isdir(fontdir):
+ return [os.path.join(fontdir,f) for f in sorted(os.listdir(fontdir))]
+ return []
+
+ def GetFonts(self, _context):
css_parts = []
- for f in sorted(os.listdir(fontdir)):
- fontfile = os.path.join(fontdir,f)
+ for fontfile in self.GetFontsFiles():
if os.path.isfile(fontfile):
css_parts.append(GetCSSFontFaceFromFontFile(fontfile))
@@ -446,13 +451,18 @@
hasher = hashlib.md5()
hmi_tree_root._hash(hasher)
- with open(svgfile, 'rb') as afile:
- while True:
- buf = afile.read(65536)
- if len(buf) > 0:
- hasher.update(buf)
- else:
- break
+ filestocheck = [svgfile] + \
+ GetPoFiles(self.CTNPath()) + \
+ self.GetFontsFiles()
+
+ for filetocheck in filestocheck:
+ with open(filetocheck, 'rb') as afile:
+ while True:
+ buf = afile.read(65536)
+ if len(buf) > 0:
+ hasher.update(buf)
+ else:
+ break
digest = hasher.hexdigest()
if os.path.exists(hash_path):