admin.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import logging
  2. from lakesuperior.config_parser import parse_config
  3. from lakesuperior.env import env
  4. from lakesuperior.globals import AppGlobals
  5. from lakesuperior.migrator import Migrator
  6. from lakesuperior.store.ldp_nr.default_layout import DefaultLayout as FileLayout
  7. from lakesuperior.store.ldp_rs.lmdb_store import TxnManager
  8. __doc__ = """
  9. Admin API.
  10. This module contains maintenance utilities and stats.
  11. """
  12. logger = logging.getLogger(__name__)
  13. def stats():
  14. """
  15. Get repository statistics.
  16. :rtype: dict
  17. :return: Store statistics, resource statistics.
  18. """
  19. import lakesuperior.env_setup
  20. repo_stats = {'rsrc_stats': env.app_globals.rdfly.count_rsrc()}
  21. with TxnManager(env.app_globals.rdf_store) as txn:
  22. repo_stats['store_stats'] = env.app_globals.rdf_store.stats()
  23. return repo_stats
  24. def migrate(src, dest, start_pts=None, list_file=None, **kwargs):
  25. """
  26. Migrate an LDP repository to a new LAKEsuperior instance.
  27. See :py:meth:`Migrator.__init__`.
  28. """
  29. if start_pts:
  30. if not isinstance(
  31. start_pts, list) and not isinstance(start_pts, tuple):
  32. start_pts = (start_pts,)
  33. elif not list_file:
  34. start_pts = ('/',)
  35. return Migrator(src, dest, **kwargs).migrate(start_pts, list_file)
  36. def integrity_check(config_dir=None):
  37. """
  38. Check integrity of the data set.
  39. At the moment this is limited to referential integrity. Other checks can
  40. be added and triggered by different argument flags.
  41. """
  42. if config_dir:
  43. env.app_globals = AppGlobals(parse_config(config_dir))
  44. else:
  45. import lakesuperior.env_setup
  46. with TxnManager(env.app_globals.rdfly.store):
  47. return { t for t in env.app_globals.rdfly.find_refint_violations()}