archivebox_remove.py 2.1 KB

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