Ejemplo n.º 1
0
 def create_base(self) -> VersionAgent:
     """Create the base version."""
     if self.base_version is None:
         create_version(True, self)
     else:
         ABUNDANT_LOGGER.warning('Cannot create duplicate base versions')
     self.load_versions()
     return self.base_version
Ejemplo n.º 2
0
def get_versions(archive_agent) -> list:
    """Get all versions."""
    version_config_path = os.path.join(archive_agent.archive_dir, 'meta', 'version_config.json')
    if not os.path.exists(version_config_path):
        ABUNDANT_LOGGER.warning('Version config missing')
        return list()

    with get_config(version_config_path) as version_config:
        return [VersionAgent(version_record['UUID'], archive_agent) for version_record in
                version_config['VersionRecords']]
Ejemplo n.º 3
0
    def get_archive(self, uuid=None, source_dir=None, archive_dir=None) -> ArchiveAgent:
        """Get the archive that matches given restraints."""
        if uuid is None and source_dir is None and archive_dir is None:
            ABUNDANT_LOGGER.warning('Must provide at least one restraint')
            raise ValueError('Must provide at least one restraint')

        archive_record = self.master_config.get_archive_record(uuid, source_dir, archive_dir)
        if archive_record is None:
            return archive_record
        return ArchiveAgent(archive_record['ArchiveDirectory'])
Ejemplo n.º 4
0
 def migrate_oldest_version_to_base(self):
     """Migrate the oldest version to the base version.
     But underneath it migrate the base version to the oldest version."""
     assert self.base_version == self.versions[0]
     if not self.versions:
         ABUNDANT_LOGGER.warning('No base version found')
     elif len(self.versions) == 1:
         ABUNDANT_LOGGER.warning('Cannot migrate when only base version exists')
     else:
         self.base_version.migrate_to_next_version()
         self.load_versions()
Ejemplo n.º 5
0
 def create_version(self) -> VersionAgent:
     """Add a new version."""
     if self.max_number_of_versions == 1:
         self.base_version.remove()
         self.create_base()
     else:
         while len(self.versions) >= self.max_number_of_versions:
             self.migrate_oldest_version_to_base()
         if self.base_version is None:
             ABUNDANT_LOGGER.warning('Cannot create non-base versions without a base version')
         else:
             create_version(False, self)
     self.load_versions()
     return self.versions[-1]
Ejemplo n.º 6
0
    def load_config(self):
        """Load the config."""
        with open("init_config.json", mode="r", encoding="utf-8") as raw_init_config:
            self.init_config = json.load(raw_init_config)
        ABUNDANT_LOGGER.info("Loaded initialisation config")

        master_config_dir = self.init_config["MasterConfigDirectory"]
        self.master_config_path = os.path.join(master_config_dir, "master_config.json")

        if not os.path.exists(self.master_config_path):
            ABUNDANT_LOGGER.warning("No master config found")
            self.save_config(use_default_template=True)

        with open(self.master_config_path, mode="r", encoding="utf-8") as raw_master_config:
            self.master_config = json.load(raw_master_config)
        ABUNDANT_LOGGER.info("Loaded master config")