archivebox_remove.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/usr/bin/env python3
  2. __package__ = 'archivebox.cli'
  3. __command__ = 'archivebox remove'
  4. import sys
  5. import argparse
  6. from typing import Optional, List, IO
  7. from ..main import remove
  8. from ..util import docstring
  9. from ..config import OUTPUT_DIR
  10. from ..logging_util import SmartFormatter, accept_stdin
  11. @docstring(remove.__doc__)
  12. def main(args: Optional[List[str]]=None, stdin: Optional[IO]=None, pwd: Optional[str]=None) -> None:
  13. parser = argparse.ArgumentParser(
  14. prog=__command__,
  15. description=remove.__doc__,
  16. add_help=True,
  17. formatter_class=SmartFormatter,
  18. )
  19. parser.add_argument(
  20. '--yes', # '-y',
  21. action='store_true',
  22. help='Remove links instantly without prompting to confirm.',
  23. )
  24. parser.add_argument(
  25. '--delete', # '-r',
  26. action='store_true',
  27. help=(
  28. "In addition to removing the link from the index, "
  29. "also delete its archived content and metadata folder."
  30. ),
  31. )
  32. parser.add_argument(
  33. '--before', #'-b',
  34. type=float,
  35. help="List only URLs bookmarked before the given timestamp.",
  36. default=None,
  37. )
  38. parser.add_argument(
  39. '--after', #'-a',
  40. type=float,
  41. help="List only URLs bookmarked after the given timestamp.",
  42. default=None,
  43. )
  44. parser.add_argument(
  45. '--filter-type',
  46. type=str,
  47. choices=('exact', 'substring', 'domain', 'regex','tag'),
  48. default='exact',
  49. help='Type of pattern matching to use when filtering URLs',
  50. )
  51. parser.add_argument(
  52. 'filter_patterns',
  53. nargs='*',
  54. type=str,
  55. help='URLs matching this filter pattern will be removed from the index.'
  56. )
  57. command = parser.parse_args(args or ())
  58. filter_str = None
  59. if not command.filter_patterns:
  60. filter_str = accept_stdin(stdin)
  61. remove(
  62. filter_str=filter_str,
  63. filter_patterns=command.filter_patterns,
  64. filter_type=command.filter_type,
  65. before=command.before,
  66. after=command.after,
  67. yes=command.yes,
  68. delete=command.delete,
  69. out_dir=pwd or OUTPUT_DIR,
  70. )
  71. if __name__ == '__main__':
  72. main(args=sys.argv[1:], stdin=sys.stdin)