admin.py 1.5 KB

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