-
Notifications
You must be signed in to change notification settings - Fork 3
geonetwork datadir checker useless ressources #35
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
Merged
Merged
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
8143ed2
first tries for geonetwork datadir checker useless ressources
jeanmi151 4118c63
continue work for adding geonetwork datadir check inside gaia
jeanmi151 711c282
feat(datadir): some desgin to show result of datadir check
mmohadIGN 09587e1
add debug function entry point
jeanmi151 ee47cdd
add back the build in docker compose
jeanmi151 1fa5c5d
rework WIP as a task the geonetwork datadir checker
jeanmi151 a726891
continue but still not working
jeanmi151 20971c2
continue testing
jeanmi151 7902e43
finaly something working
jeanmi151 038ab38
make dynamic folder search and change home dashboard
jeanmi151 c9848a0
add total count
jeanmi151 a471ce2
revert wrong merge
jeanmi151 ea4ef11
continue test and dev, take care about reviews
jeanmi151 57c1f49
make geonetwork datadir dynamic + filesizeformat using jinja2
jeanmi151 4b71648
activate debug route only if debug is ON
jeanmi151 2fc440f
cleaning before ready for reviews
jeanmi151 1818d19
cleaning before ready for reviews2
jeanmi151 87fd6db
taking review into account
jeanmi151 a6bc3b5
correct database arguments variables
jeanmi151 503f7c1
correct docker file and compose
jeanmi151 e6150ea
working way to request database without providing the Metadata class
jeanmi151 1aab1e6
move the query to get all metadata for dynamic updates
jeanmi151 60ae883
Merge branch 'master' into datadir_gn_checker
jeanmi151 880b596
result of gn checker in beautifull table
jeanmi151 bab4179
changing the path printed
jeanmi151 1f339ac
removing UnusedFileRes from GetPbStr
jeanmi151 5746c68
changing total path count
jeanmi151 ee317d6
taking reviews into account
jeanmi151 b3914f7
reset pboverviews when there is no problemo!
jeanmi151 154b395
remove useless imports
jeanmi151 ab94d92
name_for_collection_relationship drop
jeanmi151 8587893
run black tool in all files
jeanmi151 0b9e744
use formatter for printing bytes from frontend
jeanmi151 e142a86
refactor bytes Formatter
jeanmi151 4822c19
remove useless import now
jeanmi151 8e6e4e8
remove useless print for debug
jeanmi151 412e2c9
change way to print debug
jeanmi151 9344e95
remove useless Base
jeanmi151 de5f08b
remove import declarative_base gn_datadir.py
jeanmi151 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,107 @@ | ||
| #!/bin/env python3 | ||
| # -*- coding: utf-8 -*- | ||
| # vim: ts=4 sw=4 et | ||
| from celery import shared_task | ||
| from geordash.logwrap import get_logger | ||
| from flask import current_app as app | ||
| from sqlalchemy import create_engine, MetaData, select, Table | ||
| from sqlalchemy.engine import URL | ||
| from sqlalchemy.ext.automap import automap_base | ||
| from sqlalchemy.exc import OperationalError | ||
| from sqlalchemy.orm import sessionmaker | ||
| import glob | ||
| from pathlib import Path | ||
|
|
||
|
|
||
| def get_folder_size(folder): | ||
| return sum(file.stat().st_size for file in Path(folder).rglob("*")) | ||
|
|
||
|
|
||
| class GeonetworkDatadirChecker: | ||
| def __init__(self, conf): | ||
| url = URL.create( | ||
| drivername="postgresql", | ||
| username=conf.get("jdbc.username", "geonetwork"), | ||
| host=conf.get("jdbc.host", "geonetwork"), | ||
| port=conf.get("jdbc.port", "geonetwork"), | ||
| password=conf.get("jdbc.password", "geonetwork"), | ||
| database=conf.get("jdbc.database", "geonetwork"), | ||
| ) | ||
|
|
||
| engine = create_engine( | ||
| url, | ||
| connect_args={ | ||
| "options": f"-csearch_path={conf.get('jdbc.schema', 'geonetwork')}" | ||
| }, | ||
| ) | ||
| self.sessionm = sessionmaker(bind=engine) | ||
| self.sessiono = self.sessionm() | ||
|
|
||
| # Perform database reflection to analyze tables and relationships | ||
| m = MetaData(schema=conf.get("jdbc.schema", "geonetwork")) | ||
| Table("metadata", m, autoload_with=engine) | ||
| Base = automap_base(metadata=m) | ||
| Base.prepare() | ||
| self.Metadata = Base.classes.metadata | ||
|
|
||
| def session(self): | ||
| try: | ||
| self.sessiono.execute(select(1)) | ||
| except OperationalError: | ||
| print("Reconnecting to the database...") | ||
| self.sessiono = self.sessionm() | ||
| return self.sessiono | ||
|
|
||
| def get_meta_list(self): | ||
| return self.session().query(self.Metadata).all() | ||
|
|
||
|
|
||
| @shared_task(bind=True) | ||
| def check_gn_meta(self): | ||
| get_logger("CheckGNDatadir").debug("Start gn datadir checker") | ||
| metadatabase = app.extensions["gndc"] | ||
| gnmetadatas = metadatabase.get_meta_list() | ||
| geonetwork_dir_path = app.extensions["conf"].get("geonetwork.dir", "geonetwork") | ||
| geonetwork_datadir_path = ( | ||
| app.extensions["conf"] | ||
| .get("geonetwork.data.dir", "geonetwork") | ||
| .replace("${geonetwork.dir}", geonetwork_dir_path) | ||
| ) | ||
| # self.gnmetadatas.sort(key=lambda x: x.id) | ||
| meta = dict() | ||
| meta["searching_path"] = geonetwork_datadir_path | ||
| meta["problems"] = list() | ||
| total_could_be_deleted = 0 | ||
| for foldermeta in glob.glob(geonetwork_datadir_path + "*/*"): | ||
| idmeta = foldermeta.split("/")[-1] | ||
| subpath = foldermeta.split("/")[-2] | ||
| get_logger("CheckGNDatadir").debug(foldermeta) | ||
| existing_index = 0 | ||
|
|
||
| for index, item in enumerate(gnmetadatas): | ||
| if item.id == int(idmeta): | ||
| existing_index = index | ||
| break | ||
| if existing_index: | ||
| continue | ||
| else: | ||
| # append useless folder | ||
| meta["problems"].append( | ||
| { | ||
| "url": subpath + "/" + idmeta, | ||
| "problem": get_folder_size(foldermeta), | ||
| } | ||
| ) | ||
| total_could_be_deleted += get_folder_size(foldermeta) | ||
| get_logger("CheckGNDatadir").debug("finish gn datadir checker") | ||
|
|
||
| if len(meta["problems"]) > 0: | ||
| meta["problems"].append( | ||
| { | ||
| "type": "UnusedFileResTotal", | ||
| "size": total_could_be_deleted, | ||
| "total": get_folder_size(geonetwork_datadir_path), | ||
| } | ||
| ) | ||
|
|
||
| return meta | ||
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.