admin.py 1.5 KB

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