admin.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import logging
  2. import lmdb
  3. from lakesuperior.env import env
  4. from lakesuperior.store.ldp_rs.lmdb_store import TxnManager
  5. __doc__ = '''
  6. Admin API.
  7. This module contains maintenance utilities and stats.
  8. '''
  9. logger = logging.getLogger(__name__)
  10. app_globals = env.app_globals
  11. def stats():
  12. '''
  13. Get repository statistics.
  14. @return dict Store statistics, resource statistics.
  15. '''
  16. repo_stats = {'rsrc_stats': env.app_globals.rdfly.count_rsrc()}
  17. with TxnManager(env.app_globals.rdf_store) as txn:
  18. repo_stats['store_stats'] = env.app_globals.rdf_store.stats()
  19. return repo_stats
  20. def dump(src, dest, start='/', binary_handling='include'):
  21. '''
  22. Dump a whole LDP repository or parts of it to disk.
  23. @param src (rdflib.term.URIRef) Webroot of source repository. This must
  24. correspond to the LDP root node (for Fedora it can be e.g.
  25. `http://localhost:8080fcrepo/rest/`) and is used to determine if URIs
  26. retrieved are managed by this repository.
  27. @param dest (rdflib.URIRef) Base URI of the destination. This can be any
  28. container in a LAKEsuperior server. If the resource exists, it must be an
  29. LDP container. If it does not exist, it will be created.
  30. @param start (tuple|list) List of starting points to retrieve resources
  31. from. It would typically be the repository root in case of a full dump
  32. or one or more resources in the repository for a partial one.
  33. @binary_handling (string) One of 'include', 'truncate' or 'split'.
  34. '''
  35. # 1. Retrieve list of resources.
  36. if not isinstance(start, list) and not isinstance(start, tuple):
  37. start = (start,)
  38. subjects = _gather_subjects(src, start)
  39. def _gather_subjects(webroot, start_pts):
  40. env = lmdb.open('/var/tmp/
  41. for start in start_pts:
  42. if not start.startswith('/'):
  43. raise ValueError('Starting point {} does not begin with a slash.'
  44. .format(start))
  45. pfx = src.rstrip('/') + start