You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cli.py 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/bin/env python
  2. """A command line tool for uploding stuff to pomf.se clones"""
  3. import argparse
  4. from .parse_arguments import parse_arguments
  5. from .hostlist import retrieve_online_host_list
  6. from .hostlist import generate_host_string
  7. from .hostlist import retrieve_local_host_list
  8. import gettext
  9. gettext.install("limf", "locale")
  10. def main():
  11. """Creates arguments and parses user input"""
  12. parser = argparse.ArgumentParser(
  13. description=_('Uploads selected file to working pomf.se clone'))
  14. parser.add_argument('files', metavar='file', nargs='*', type=str,
  15. help=_('Files to upload'))
  16. parser.add_argument('-c', metavar='host_number', type=int,
  17. dest='host', default=None,
  18. help=_('The number (0-n) of the selected host (default is random)'))
  19. parser.add_argument('-l', dest='only_link', action='store_const',
  20. const=True, default=False,
  21. help=_('Changes output to just link to the file'))
  22. parser.add_argument('-e', dest='encrypt', action='store_const',
  23. const=True, default=False,
  24. help=_('Encrypts then uploads the files.'))
  25. parser.add_argument('-d', dest='decrypt', action='store_const',
  26. const=True, default=False,
  27. help=_('Decrypts files from links with encrypted files'))
  28. parser.add_argument('-j', dest="local_list",
  29. default=False, help=_('Path to a local list file'))
  30. parser.add_argument('-s', dest="show_list", action='store_const',
  31. const=True, default=False,
  32. help=_('Show the host list (will not upload your files when called)'))
  33. parser.add_argument('-m', dest='limit_size', action='store_const',
  34. const=True, default=False,
  35. help=_('Do not upload file if it exceeds the certain host limit'))
  36. parser.add_argument('-nc', dest='no_cloudflare', action='store_const',
  37. const=True, default=False,
  38. help=_('Do not use hosts which use Cloudflare.'))
  39. parser.add_argument('--log-file', metavar="LOGFILE", dest="logfile",
  40. default="~/limf.log",
  41. help=_("The location of log file"))
  42. parser.add_argument('--log', dest='log', action="store_const",
  43. const=True, default=False,
  44. help=_("Enables the logging feature, default logfile is ~/limf.log"))
  45. args = parser.parse_args()
  46. try:
  47. if args.local_list:
  48. clone_list = retrieve_local_host_list(args.local_list)
  49. else:
  50. clone_list = retrieve_online_host_list()
  51. if len(min(clone_list, key=len)) < 5 and (args.limit_size or args.no_cloudflare):
  52. print(_("For newer options, please update your host_list."))
  53. exit()
  54. if args.host and not(0 <= args.host < len(clone_list)):
  55. print(generate_host_string(clone_list))
  56. exit()
  57. parse_arguments(args, clone_list)
  58. except FileNotFoundError:
  59. print(_('Plese enter valid file.'))
  60. if __name__ == '__main__':
  61. main()