lsup-admin 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. #!/usr/bin/env python
  2. import click
  3. import json
  4. import os
  5. import sys
  6. import lakesuperior.env_setup
  7. from lakesuperior.api import admin as admin_api
  8. from lakesuperior.config_parser import config
  9. from lakesuperior.globals import AppGlobals
  10. from lakesuperior.env import env
  11. from lakesuperior.store.ldp_rs.lmdb_store import TxnManager
  12. rdfly = env.app_globals.rdfly
  13. nonrdfly = env.app_globals.nonrdfly
  14. @click.group()
  15. def admin():
  16. pass
  17. @click.command()
  18. def bootstrap():
  19. '''
  20. Bootstrap binary and graph stores.
  21. This script will parse configuration files and initialize a filesystem and
  22. triplestore with an empty FCREPO repository.
  23. It is used in test suites and on a first run.
  24. Additional scaffolding files may be parsed to create initial contents.
  25. '''
  26. click.echo(
  27. click.style(
  28. 'WARNING: This operation will WIPE ALL YOUR DATA.\n',
  29. bold=True, fg='red')
  30. + 'Are you sure? (Please type `yes` to continue) > ', nl=False)
  31. choice = input().lower()
  32. if choice != 'yes':
  33. click.echo('Aborting.')
  34. sys.exit(1)
  35. click.echo('Initializing graph store at {}'.format(rdfly.store.path))
  36. with TxnManager(env.app_globals.rdf_store, write=True) as txn:
  37. rdfly.bootstrap()
  38. rdfly.store.close()
  39. click.echo('Graph store initialized.')
  40. click.echo('Initializing binary store at {}'.format(nonrdfly.root))
  41. nonrdfly.bootstrap()
  42. click.echo('Binary store initialized.')
  43. click.echo('Repository successfully set up. Go to town.')
  44. @click.command()
  45. @click.option(
  46. '--human', '-h', is_flag=True, flag_value=True,
  47. help='Print a human-readable string. By default, JSON is printed.')
  48. def stats(human=False):
  49. '''
  50. Print repository statistics.
  51. @param human (bool) Whether to output the data in human-readable
  52. format.
  53. '''
  54. stat_data = admin_api.stats()
  55. if human:
  56. click.echo(
  57. 'This option is not supported yet. Sorry.\nUse the `/admin/stats`'
  58. ' endpoint in the web UI for a pretty printout.')
  59. else:
  60. click.echo(json.dumps(stat_data))
  61. @click.command()
  62. def check_fixity(uid):
  63. '''
  64. [STUB] Check fixity of a resource.
  65. '''
  66. pass
  67. @click.command()
  68. def check_refint():
  69. '''
  70. [STUB] Check referential integrity.
  71. This command scans the graph store to verify that all references to
  72. resources within the repository are effectively pointing to existing
  73. resources. For repositories set up with the `referencial_integrity` option
  74. (the default), this is a pre-condition for a consistent data set.
  75. '''
  76. pass
  77. @click.command()
  78. def cleanup():
  79. '''
  80. [STUB] Clean up orphan database items.
  81. '''
  82. pass
  83. @click.command()
  84. def copy():
  85. '''
  86. [STUB] Copy (backup) repository data.
  87. This s a low-level copy, which backs up the data directories containing
  88. graph and binary data. It may not even be a necessary command since to
  89. back up the repository one just needs to copy the binary and metadata
  90. folders.
  91. '''
  92. pass
  93. @click.command()
  94. @click.argument('src')
  95. @click.argument('dest')
  96. @click.option(
  97. '--binaries', '-b', show_default=True,
  98. help='If set to `include`, full binaries are included in the dump. If '
  99. 'set to `truncate`, binaries are created as zero-byte files in the proper '
  100. 'folder structure. If set to `skip`, binaries are not exported. Data '
  101. 'folders are not created.')
  102. def dump(src, dest, binaries='include'):
  103. '''
  104. [STUB] Dump repository to disk.
  105. Dump a Fedora 4 repository to disk. The Fedora repo can be
  106. LAKEsuperior or another compatible implementation.
  107. '''
  108. pass
  109. @click.command()
  110. @click.argument('src')
  111. @click.argument('dest')
  112. def load(src, dest):
  113. '''
  114. [STUB] Load serialized repository data.
  115. Load serialized data from a filesystem location into a Fedora repository.
  116. The Fedora repo can be LAKEsuperior or another compatible implementation.
  117. '''
  118. pass
  119. admin.add_command(bootstrap)
  120. admin.add_command(check_fixity)
  121. admin.add_command(check_refint)
  122. admin.add_command(cleanup)
  123. admin.add_command(copy)
  124. admin.add_command(dump)
  125. admin.add_command(load)
  126. admin.add_command(stats)
  127. if __name__ == '__main__':
  128. admin()