Debian Codegraph @

eyesjunior/helpFiles/prepareHTML

raw
1 #! /usr/bin/python3
2
3 #############################################
4 # This script updates help files for eyes17 #
5 #############################################
6 #
7 # it operates from a directory containing 'pics' and 'schematics' directories.
8 # the directory also contains all language directories,
9 # with their own 'pics' and 'schematics' inside.
10 #
11 # Script creates symlinks, if they do not exist, from the language-specific
12 # 'pics' and 'schematics' directories to the common files, except when a plain
13 # file with the same name already exists in the language-specific directory
14 #
15 ############################################
16 # Managing translation of SVG files #
17 # or a language-specific bitmap screenshot #
18 ############################################
19 #
20 # When one wants to translate a vectorial image (SVG format), one must first
21 # delete the symlink from the language tree's 'schematics' directory,
22 # rework the SVG file from the common 'schematics' directory, and save it
23 # as a plain file with the same name, but inside the language tree's directory.
24 #
25 # To install a language-specific screenshot, e.g. <lang>/pics/foo-screen.png,
26 # first delete the symlink from <lang>/pics/foo-screen.png to
27 # ../../foo-screen.png, then save a plain file in <lang>/pics/foo-screen.png
28 #
29 # BEWARE: symlinks must be removed prior to saving plain files!
30
31 import sys, argparse, os, glob
32
33 def checkAndRepairLinks (args, imgDir, globs):
34 """
35 check and repair symlinks from language-specific directories to
36 common images. There is an exception for the files missing.*, which
37 are specials; symlinks to them do not come from language-specific
38 directories.
39 :param args: parsed arguments
40 :type args: argparse.ArgumentParser
41 :param imgDir: name of an image directory ("pics","schematics")
42 :param globs: list of globbing expressions to get files (like "*.png")
43 """
44 print(f"establishing symlinks to images {', '.join(globs)} in {imgDir}")
45 # find basenames of images inside pics common directory
46 images = []
47 for g in globs:
48 images += glob.glob(os.path.join(args.destdir, imgDir, g))
49 images = [os.path.basename(img) for img in images]
50 images = [img for img in images if not img.startswith("missing.")]
51 for l in args.languages:
52 print(f"language = {l}", end=" ")
53 for img in images:
54 path=os.path.join(args.destdir,l,imgDir,img)
55 if os.path.exists(path):
56 if os.path.islink(path):
57 print(".", end="")
58 else:
59 print("o", end="")
60 else:
61 # path does not yet exist, create the symlink
62 os.symlink(
63 os.path.join('..','..',imgDir,img),
64 os.path.join(args.destdir,l,imgDir,img)
65 )
66 print('+', end="")
67 print()
68
69 if __name__ == "__main__":
70 parser = argparse.ArgumentParser(prog='prepareHTML')
71 parser.add_argument(
72 'destdir', metavar='destdir', type=str,
73 help='The directory where prepareHTML is supposed to work'
74 )
75 parser.add_argument(
76 'languages', metavar='lang', type=str, nargs='+',
77 help='list of language directories (for instance en es fr ml)'
78 )
79 args = parser.parse_args()
80 print(f"Working in {args.destdir} for languages {', '.join(args.languages)}")
81 checkAndRepairLinks (args, 'pics', ['*.jpg','*.png'])
82 checkAndRepairLinks (args, 'schematics', ['*.svg'])
83 print ("To convert RST files to HTML, please run 'make'")