forked from ScoDoc/ScoDoc
refactor templates to zip
This commit is contained in:
parent
230c7d488e
commit
ccd1a0daba
@ -170,6 +170,15 @@ def add_local_file_to_zip(zipfile, ziproot, pathname, path_in_zip):
|
||||
# zipfile.writestr(rooted_path_in_zip, data)
|
||||
|
||||
|
||||
def add_refs_to_register(register, directory):
|
||||
"""Ajoute les fichiers trouvés dans directory au registre (dictionaire) sous la forme
|
||||
filename => pathname
|
||||
"""
|
||||
length = len(directory)
|
||||
for pathname in list_directory_filenames(directory):
|
||||
filename = pathname[length+1:]
|
||||
register[filename] = pathname
|
||||
|
||||
def add_pe_stuff_to_zip(zipfile, ziproot):
|
||||
"""Add auxiliary files to (already opened) zip
|
||||
Put all local files found under config/doc_poursuites_etudes/local
|
||||
@ -178,30 +187,16 @@ def add_pe_stuff_to_zip(zipfile, ziproot):
|
||||
|
||||
Also copy logos
|
||||
"""
|
||||
register = {}
|
||||
# first add standard (distrib references)
|
||||
distrib_dir = os.path.join(REP_DEFAULT_AVIS, "distrib")
|
||||
distrib_pathnames = list_directory_filenames(
|
||||
distrib_dir
|
||||
) # eg /opt/scodoc/tools/doc_poursuites_etudes/distrib/modeles/toto.tex
|
||||
l = len(distrib_dir)
|
||||
distrib_filenames = {x[l + 1 :] for x in distrib_pathnames} # eg modeles/toto.tex
|
||||
|
||||
add_refs_to_register(register=register, directory=distrib_dir)
|
||||
# then add local references (some oh them may overwrite distrib refs)
|
||||
local_dir = os.path.join(REP_LOCAL_AVIS, "local")
|
||||
local_pathnames = list_directory_filenames(local_dir)
|
||||
l = len(local_dir)
|
||||
local_filenames = {x[l + 1 :] for x in local_pathnames}
|
||||
|
||||
for filename in distrib_filenames | local_filenames:
|
||||
if filename in local_filenames:
|
||||
add_local_file_to_zip(
|
||||
zipfile, ziproot, os.path.join(local_dir, filename), "avis/" + filename
|
||||
)
|
||||
else:
|
||||
add_local_file_to_zip(
|
||||
zipfile,
|
||||
ziproot,
|
||||
os.path.join(distrib_dir, filename),
|
||||
"avis/" + filename,
|
||||
)
|
||||
add_refs_to_register(register=register, directory=local_dir)
|
||||
# at this point register contains all refs (filename, pathname) to be saved
|
||||
for filename, pathname in register.items():
|
||||
add_local_file_to_zip(zipfile, ziproot, pathname, "avis/" + filename)
|
||||
|
||||
# Logos: (add to logos/ directory in zip)
|
||||
logos_names = ["logo_header.jpg", "logo_footer.jpg"]
|
||||
|
Loading…
Reference in New Issue
Block a user