logo

Archive Filter

← Back to Filter List

Archive


Creates a .tgz archive of all input documents. The use-short-names option will store documents under their short (canonical) filenames.

Aliases for this filter

  • archive
  • tgz

Converts from file formats:

  • .*

To file formats:

  • .tgz

Available settings:

SettingDescriptionDefault
add-new-filesBoolean or list of extensions/patterns to match.False
added-in-versionDexy version when this filter was first available.
additional-doc-filtersFilters to apply to additional documents created as side effects.{}
additional-doc-settingsSettings to apply to additional documents created as side effects.{}
data-typeAlias of custom data class to use to store filter output.generic
examplesTemplates which should be used as examples for this filter.[]
exclude-add-new-filesList of patterns to skip even if they match add-new-files.[]
exclude-new-files-from-dirList of directories to skip when adding new files.[]
extFile extension to output.None
extension-mapDictionary mapping input extensions to default output extensions.None
helpHelpstring for plugin.Creates a .tgz archive of all input documents. The use-short-names option will store documents under their short (canonical) filenames.
input-extensionsList of extensions which this filter can accept as input.[u'.*']
keep-originalsWhether, if additional-doc-filters are specified, the original unmodified docs should also be added.False
mkdirA directory which should be created in working dir.None
mkdirsA list of directories which should be created in working dir.[]
nodocWhether filter should be excluded from documentation.False
outputWhether to output results of this filter by default by reporters such as 'output' or 'website'.True
output-extensionsList of extensions which this filter can produce as output.[u'.tgz']
override-workspace-exclude-filtersIf True, document will be populated to other workspaces ignoring workspace-exclude-filters.False
preserve-prior-data-classWhether output data class should be set to match the input data class.False
require-outputShould dexy raise an exception if no output is produced by this filter?True
tagsTags which describe the filter.[]
use-short-namesWhether to use short, potentially non-unique names within the archive.False
variablesA dictionary of variable names and values to make available to this filter.{}
varsA dictionary of variable names and values to make available to this filter.{}
workspace-exclude-filtersFilters whose output should be excluded from workspace.[u'pyg']
workspace-includesIf set to a list of filenames or extensions, only these will be populated to working dir.None
Filter Source Code
class ArchiveFilter(DexyFilter):
    """
    Creates a .tgz archive of all input documents.

    The use-short-names option will store documents under their short
    (canonical) filenames.
    """
    aliases = ['archive', 'tgz']
    _settings = {
            'output' : True,
            'output-extensions' : ['.tgz'],
            'use-short-names' : ("Whether to use short, potentially non-unique names within the archive.", False),
            }

    def open_archive(self):
        self.archive = tarfile.open(self.output_filepath(), mode="w:gz")

    def add_to_archive(self, filepath, archivename):
        self.archive.add(filepath, arcname=archivename)

    def process(self):
        self.open_archive()

        # Place files in the archive within a directory with the same name as the archive.
        dirname = self.output_data.baserootname()

        # Figure out whether to use short names or longer, unambiguous names.
        use_short_names = self.setting("use-short-names")

        for doc in self.doc.walk_input_docs():
            if not doc.output_data().is_cached():
                raise Exception("File not on disk.")

            # Determine what this file's name within the archive should be.
            if use_short_names:
                arcname = doc.output_data().name
            else:
                arcname = doc.output_data().long_name()
            arcname = os.path.join(self.input_data.relative_path_to(arcname))
            arcname = os.path.join(dirname, arcname)

            # Add file to archive
            self.add_to_archive(doc.output_data().storage.data_file(), arcname)

        # Save the archive
        self.archive.close()

Content © 2013 Dr. Ana Nelson | Site Design © Copyright 2011 Andre Gagnon | All Rights Reserved.