1.1 --- a/moinconvert Sun Apr 14 00:01:23 2019 +0200
1.2 +++ b/moinconvert Sun Apr 14 00:07:33 2019 +0200
1.3 @@ -333,7 +333,7 @@
1.4 output.writepage(outtext, pagename)
1.5 print >>sys.stderr, pagename
1.6
1.7 - copy_attachments(p, input, output)
1.8 + copy_attachments(p, input, output, all=True)
1.9
1.10 # Install any theme resources.
1.11
2.1 --- a/moinformat/utils/copying.py Sun Apr 14 00:01:23 2019 +0200
2.2 +++ b/moinformat/utils/copying.py Sun Apr 14 00:07:33 2019 +0200
2.3 @@ -21,32 +21,43 @@
2.4
2.5 from shutil import copy
2.6
2.7 -def copy_attachments(parser, input, output):
2.8 +def copy_attachments(parser, input, output, all=False):
2.9
2.10 - "Copy attachments referenced by 'parser' from 'input' to 'output'."
2.11 + """
2.12 + For attachments referenced by the page processed by 'parser', copy them from
2.13 + 'input' to 'output'. If 'all' is set to a true value, all stored attachments
2.14 + are copied; otherwise, only those explicitly linked in the page are copied.
2.15 + """
2.16
2.17 pagename = parser.metadata.get("pagename")
2.18
2.19 if not pagename:
2.20 return
2.21
2.22 - for link_target in parser.link_targets:
2.23 -
2.24 - # Obtain attachments.
2.25 + # Obtain attachments.
2.26
2.27 - if link_target.get_type() == "attachment":
2.28 + if not all:
2.29 + filenames = []
2.30 + for link_target in parser.link_targets:
2.31 + if link_target.get_type() == "attachment":
2.32 + filenames.append(link_target.get_identifier())
2.33 + else:
2.34 + input = parser.metadata.get_input()
2.35 + filenames = input.get_attachments(pagename)
2.36
2.37 - # Obtain the attachment filename, the source location and the
2.38 - # destination.
2.39 + # Copy attachments.
2.40
2.41 - filename = link_target.get_identifier()
2.42 - input_filename = input.get_attachment_filename(pagename, filename)
2.43 - output_filename = output.get_attachment_filename(pagename, filename)
2.44 + for filename in filenames:
2.45 +
2.46 + # Obtain the source location and the destination.
2.47
2.48 - # Copy the file if possible.
2.49 + input_filename = input.get_attachment_filename(pagename, filename)
2.50 + output_filename = output.get_attachment_filename(pagename, filename)
2.51
2.52 - if input_filename and output_filename:
2.53 - output.ensure_attachments(pagename)
2.54 - copy(input_filename, output_filename)
2.55 + # Copy the file if possible.
2.56 +
2.57 + if input_filename and output_filename:
2.58 + output.ensure_attachments(pagename)
2.59 + copy(input_filename, output_filename)
2.60
2.61 # vim: tabstop=4 expandtab shiftwidth=4