-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit builds on [c6d38c1](c6d38c1), to refactor the archive in order to decouple it from its export/import to the AiiDA database. The `aiida/tools/importexport/archive` module has been created, which contains the readers and writers used to create and interact with an archive. Effectively archive formats are now defined by their associated reader and writer classes, which must inherit and implement the `ArchiveReaderAbstract` and `ArchiveWriterAbstract` interfaces respectively. `aiida/tools/importexport/dbimport` has been refactored, to interface with this new `ArchiveReaderAbstract` class, and also utilise the new `progress_reporter` context manager. Both the django and sqlalchemy backends have been "synchronized", such that conform to exactly the same code structure, which in-turn has allowed for the sharing of common code. The commit is intended to be back-compatible, in that no public API elements have been removed. However, it does: - remove the `Archive` class, replaced by the `ReaderJsonZip`/`ReaderJsonTar` classes. - remove `aiida/tools/importexport/common/progress_bar.py`, now replaced by `aiida/common/progress_reporter.py` - move `aiida/tools/importexport/dbexport/zip.py` → `aiida/tools/importexport/common/zip_folder.py` The `aiida import --verbosity DEBUG` option has been added, which sets the log level of the process, and whether the progress bars are removed. The `verdi export inspect` code has also been refactored, to utilize the `ArchiveReaderAbstract`. The `verdi export inspect --data` option has been deprecated, since access to the `data.json` file is only an implementation detail of the current archive format.
- Loading branch information
1 parent
02c8a0c
commit 2f8e845
Showing
32 changed files
with
2,768 additions
and
2,418 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# -*- coding: utf-8 -*- | ||
########################################################################### | ||
# Copyright (c), The AiiDA team. All rights reserved. # | ||
# This file is part of the AiiDA code. # | ||
# # | ||
# The code is hosted on GitHub at https://github.com/aiidateam/aiida-core # | ||
# For further information on the license, see the LICENSE.txt file # | ||
# For further information please visit http://www.aiida.net # | ||
########################################################################### | ||
"""Shared resources for the archive.""" | ||
import dataclasses | ||
import os | ||
from typing import Dict, List, Optional, Set | ||
|
||
__all__ = ('ArchiveMetadata', 'detect_archive_type') | ||
|
||
|
||
@dataclasses.dataclass | ||
class ArchiveMetadata: | ||
"""Class for storing metadata about this archive. | ||
Required fields are necessary for importing the data back into AiiDA, | ||
whereas optional fields capture information about the export/migration process(es) | ||
""" | ||
export_version: str | ||
aiida_version: str | ||
# Entity type -> database ID key | ||
unique_identifiers: Dict[str, str] = dataclasses.field(repr=False) | ||
# Entity type -> database key -> meta parameters | ||
all_fields_info: Dict[str, Dict[str, Dict[str, str]]] = dataclasses.field(repr=False) | ||
|
||
# optional data | ||
graph_traversal_rules: Optional[Dict[str, bool]] = dataclasses.field(default=None) | ||
# Entity type -> UUID list | ||
entities_starting_set: Optional[Dict[str, Set[str]]] = dataclasses.field(default=None) | ||
include_comments: Optional[bool] = dataclasses.field(default=None) | ||
include_logs: Optional[bool] = dataclasses.field(default=None) | ||
# list of migration event notifications | ||
conversion_info: List[str] = dataclasses.field(default_factory=list, repr=False) | ||
|
||
|
||
def detect_archive_type(in_path: str) -> str: | ||
"""For back-compatibility, but should be replaced with direct comparison of classes. | ||
:param in_path: the path to the file | ||
:returns: the archive type identifier (currently one of 'zip', 'tar.gz', 'folder') | ||
""" | ||
import tarfile | ||
import zipfile | ||
from aiida.tools.importexport.common.config import ExportFileFormat | ||
from aiida.tools.importexport.common.exceptions import ImportValidationError | ||
|
||
if os.path.isdir(in_path): | ||
return 'folder' | ||
if tarfile.is_tarfile(in_path): | ||
return ExportFileFormat.TAR_GZIPPED | ||
if zipfile.is_zipfile(in_path): | ||
return ExportFileFormat.ZIP | ||
raise ImportValidationError( | ||
'Unable to detect the input file format, it is neither a ' | ||
'folder, tar file, nor a (possibly compressed) zip file.' | ||
) |
Oops, something went wrong.