pkar.lua 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #!/usr/bin/lua
  2. local cli = require "cli"
  3. local plpath = require "pl.path"
  4. local nsm = require "volksdata.namespace"
  5. local term = require "volksdata.term"
  6. local triple = require "volksdata.triple"
  7. local graph = require "volksdata.graph"
  8. local pkar = require "pocket_archive"
  9. local sub = require "pocket_archive.submission"
  10. local repo = require "pocket_archive.repo"
  11. local gen = require "pocket_archive.generator"
  12. local dbg = require "debugger"
  13. cli.locale "en_US" -- TODO set with multilingual support.
  14. init = cli.command {
  15. "Initialize a new Pocket Archive store.",
  16. cli.flag "wipe" {
  17. "Wipe all preexisting data.",
  18. type = cli.boolean,
  19. },
  20. function(args)
  21. if args.wipe then _ = pkar.reset_store
  22. else _ = pkar.store end
  23. end
  24. }
  25. list = cli.command {
  26. "List all resource IDs.",
  27. function()
  28. for s in repo.gr:unique_terms(triple.POS_S):iter() do
  29. print(nsm.denormalize_uri(s.data))
  30. end
  31. end,
  32. }
  33. deposit = cli.command {
  34. "Deposit a package.",
  35. cli.positional "path" { "Path of the laundry list file." },
  36. cli.flag "c,cleanup" {
  37. "Remove laundry list and SIP after successful submission.",
  38. type = cli.boolean,
  39. },
  40. function(args)
  41. sub.deposit(args.path, args.cleanup)
  42. end
  43. }
  44. gen_site = cli.command {
  45. "Generate a static site from the archive.",
  46. function(args) gen.generate_site() end
  47. }
  48. dump_res = cli.command {
  49. "Generate an RDF representation of a resource.",
  50. cli.positional "id" {
  51. "ID of the resource, prefixed by `par:`",
  52. type = cli.string,
  53. },
  54. cli.flag "f,format" {
  55. "RDF format. `nt` and `ttl` are available.",
  56. type = cli.string,
  57. default = "ttl",
  58. },
  59. cli.flag "o,output" {
  60. "Output file. If not specified, output to stdout.",
  61. type = cli.string,
  62. default = "",
  63. },
  64. function(args)
  65. local s = term.new_iriref_ns(args.id)
  66. local out = repo.serialize_rsrc(s, args.format)
  67. if args.output ~= "" then
  68. local fh = assert(io.open(args.output, "w"))
  69. fh:write(out)
  70. fh:close()
  71. print("File written to ", args.output)
  72. else print(out) end
  73. end,
  74. }
  75. dump_ll = cli.command {
  76. "Generate a laundry list for a stored resource.",
  77. cli.positional "id" {
  78. "ID of the resource, prefixed by `par:`",
  79. type = cli.string,
  80. },
  81. cli.flag "o,output" {
  82. "Output file. If not specified, output to stdout.",
  83. type = cli.string,
  84. default = "",
  85. },
  86. function(args)
  87. local s = term.new_iriref_ns(args.id)
  88. local out = gen.generate_ll(s)
  89. if args.output ~= "" then
  90. local fh = assert(io.open(args.output, "w"))
  91. fh:write(out)
  92. fh:close()
  93. print("File written to ", args.output)
  94. else print(out) end
  95. end
  96. }
  97. dump_archive = cli.command {
  98. "Generate a RDF representation of the full archive.",
  99. cli.positional "path" {
  100. "Destination file path.",
  101. type = cli.string,
  102. },
  103. cli.flag "f,format" {
  104. "RDF serialization format. One of `ttl` [default], `nt`.",
  105. type = cli.string,
  106. default = "ttl",
  107. },
  108. function(args)
  109. repo.dump(args.path, args.format)
  110. print ("File written to ", args.path)
  111. end,
  112. }
  113. cli.program {
  114. "Pocket Archive command line interface.",
  115. }