Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add local maintenance with defragment_storage #673

Merged
merged 2 commits into from Feb 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 34 additions & 3 deletions pyiron_base/project/maintenance.py
Expand Up @@ -2,7 +2,6 @@
import os
import pkgutil
import warnings
from _warnings import warn

import pandas
from git import Repo, InvalidGitRepositoryError
Expand All @@ -27,7 +26,7 @@ def __init__(self, project):
self._project = project
self._global = GlobalMaintenance()
self._update = UpdateMaintenance(self._project)
self._local = None
self._local = LocalMaintenance(self._project)

@property
def global_status(self):
Expand All @@ -37,6 +36,10 @@ def global_status(self):
def update(self):
return self._update

@property
def local(self):
return self._local

@staticmethod
def get_repository_status():

Expand Down Expand Up @@ -69,6 +72,34 @@ def get_repository_status():
return report


class LocalMaintenance:
def __init__(self, project):
self._project = project


def defragment_storage(
self,
recursive: bool = True,
progress: bool = True,
**kwargs: dict,
):
"""
Iterate over the jobs within the current project and it is sub projects and rewrite the hdf file

Args:
recursive (bool): search subprojects [True/False] - True by default
progress (bool): if True (default), add an interactive progress bar to the iteration
**kwargs (dict): Optional arguments for filtering with keys matching the project database column name
(eg. status="finished"). Asterisk can be used to denote a wildcard, for zero or more
instances of any character
"""
for job in self._project.iter_jobs(
recursive=recursive, progress=progress, convert_to_object=False, **kwargs
):
hdf = job.project_hdf5
hdf.rewrite_hdf(job.name)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be a good idea to remove the job_name argument for rewrite_hdf in this PR itself?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not really sure. Looking at rewrite_hdf I sort of had the feeling that this only rewrites the job itself and not (necessarily) the overall file. I wanted to do (and probably include some tests into base) to see if it actually correctly rewrites the whole hdf file if multiple jobs are in there or has a latent bug for such cases.



class UpdateMaintenance:
def __init__(self, project):
self._project = project
Expand Down Expand Up @@ -146,7 +177,7 @@ def __init__(self):
"""
connection_string = state.database.sql_connection_string
if "postgresql" not in connection_string:
warn(
warnings.warn(
"""
The database statistics is only available for a Postgresql database
"""
Expand Down