Common utility functions, classes, and exceptions
aiida.tools.importexport.common.
Archive
Bases: object
object
Utility class to operate on exported archive files or directories.
The main usage should be to construct the class with the filepath of the export archive as an argument. The contents will be lazily unpacked into a sand box folder which is constructed upon entering the instance within a context and which will be automatically cleaned upon leaving that context. Example:
with Archive('/some/path/archive.aiida') as archive: archive.version
FILENAME_DATA
FILENAME_METADATA
__dict__
__enter__
Instantiate a SandboxFolder into which the archive can be lazily unpacked.
__exit__
Clean the sandbox folder if it was instatiated.
__init__
Initialize self. See help(type(self)) for accurate signature.
__module__
__weakref__
list of weak references to the object (if defined)
_read_json_file
Read the contents of a JSON file from the unpacked archive contents.
filename – the filename relative to the sandbox folder
a dictionary with the loaded JSON content
conversion_info
Return information about migration events that were applied to this archive.
list of conversion notifications
data
Return the loaded content of the data file
dictionary with contents of data file
ensure_unpacked
Decorator to ensure that the archive is unpacked before entering the decorated function.
ensure_within_context
Decorator to ensure that the instance is called within a context manager.
filepath
Return the filepath of the archive
the archive filepath
folder
Return the sandbox folder
sandbox folder aiida.common.folders.SandboxFolder
aiida.common.folders.SandboxFolder
get_data_statistics
Return dictionary with statistics about data content, i.e. how many entries of each entity type it contains.
a dictionary with basic details
get_info
Return a dictionary with basic information about the archive.
meta_data
Return the loaded content of the meta data file
dictionary with contents of meta data file
unpack
Unpack the archive and store the contents in a sandbox.
unpacked
Return whether the archive has been unpacked into the sandbox folder.
version_aiida
Return the version of AiiDA the archive was created with.
version number
version_format
Return the version of the archive format.
extract_zip
Extract the nodes to be imported from a zip file.
infile (str) – file path
folder (SandboxFolder) – a temporary folder used to extract the file tree
SandboxFolder
nodes_export_subfolder (str) – name of the subfolder for AiiDA nodes
silent (bool) – suppress progress bar
TypeError – if parameter types are not respected
CorruptArchive – if the archive misses files or files have incorrect formats
extract_tar
Extract the nodes to be imported from a (possibly zipped) tar file.
folder (SandboxFolder) – a temporary fodler used to extract the file tree
extract_tree
Prepare to import nodes from plain file system tree by copying in the given sandbox folder.
Note
the contents of the unpacked archive directory are copied into the sandbox folder, because the files will anyway haven to be copied to the repository at some point. By copying the contents of the source directory now and continuing operation only on the sandbox folder, we do not risk to modify the source files accidentally. During import then, the node files from the sandbox can be moved to the repository, so they won’t have to be copied again in any case.
infile (str) – absolute filepath point to the unpacked archive directory
folder (SandboxFolder) – a temporary folder to which the archive contents are copied
ExportImportException
Bases: aiida.common.exceptions.AiidaException
aiida.common.exceptions.AiidaException
Base class for all AiiDA export/import module exceptions.
ArchiveExportError
Bases: aiida.tools.importexport.common.exceptions.ExportImportException
aiida.tools.importexport.common.exceptions.ExportImportException
Base class for all AiiDA export exceptions.
ArchiveImportError
Base class for all AiiDA import exceptions.
CorruptArchive
Raised when an operation is applied to a corrupt export archive, e.g. missing files or invalid formats.
IncompatibleArchiveVersionError
Raised when trying to import an export archive with an incompatible schema version.
ExportValidationError
Bases: aiida.tools.importexport.common.exceptions.ArchiveExportError
aiida.tools.importexport.common.exceptions.ArchiveExportError
Raised when validation fails during export, e.g. for non-sealed ProcessNode s.
ProcessNode
ImportUniquenessError
Bases: aiida.tools.importexport.common.exceptions.ArchiveImportError
aiida.tools.importexport.common.exceptions.ArchiveImportError
Raised when the user tries to violate a uniqueness constraint.
Similar to UniquenessError.
UniquenessError
ImportValidationError
Raised when validation fails during import, e.g. for parameter types and values.
ArchiveMigrationError
Base class for all AiiDA export archive migration exceptions.
MigrationValidationError
Bases: aiida.tools.importexport.common.exceptions.ArchiveMigrationError
aiida.tools.importexport.common.exceptions.ArchiveMigrationError
Raised when validation fails during migration of export archives.
DanglingLinkError
Bases: aiida.tools.importexport.common.exceptions.MigrationValidationError
aiida.tools.importexport.common.exceptions.MigrationValidationError
Raised when an export archive is detected to contain dangling links when importing.
ProgressBarError
Something is wrong with setting up the tqdm progress bar
get_progress_bar
Set up, cache and return cached tqdm progress bar
close_progress_bar
Close instantiated progress bar
Utility functions and classes to interact with AiiDA export archives.
aiida.tools.importexport.common.archive.
Configuration file for AiiDA Import/Export module
Module that defines the exceptions thrown by AiiDA’s export/import module.
Archive.
aiida.tools.importexport.common.exceptions.
Have a single tqdm progress bar instance that should be handled using the functions in this module
aiida.tools.importexport.common.progress_bar.
Utility functions for import/export of AiiDA entities
aiida.tools.importexport.common.utils.
HTMLGetLinksParser
Bases: html.parser.HTMLParser
html.parser.HTMLParser
If a filter_extension is passed, only links with extension matching the given one will be returned.
Initialize and reset this instance.
If convert_charrefs is True (the default), all character references are automatically converted to the corresponding Unicode characters.
get_links
Return the links that were found during the parsing phase.
handle_starttag
Store the urls encountered, if they match the request.
export_shard_uuid
Sharding of the UUID for the import/export
uuid (str) – UUID to be sharded (v4)
Sharded UUID as a subfolder path
str
get_valid_import_links
Open the given URL, parse the HTML and return a list of valid links where the link file has a .aiida extension.
schema_to_entity_names
Mapping from classes path to entity names (used by the SQLA import/export) This could have been written much simpler if it is only for SQLA but there is an attempt the SQLA import/export code to be used for Django too.