inary-cli 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #!/usr/bin/env python3
  2. #
  3. # Main fork Pisi: Copyright (C) 2005 - 2011, Tubitak/UEKAE
  4. #
  5. # Copyright (C) 2016 - 2018, Suleyman POYRAZ (AquilaNipalensis)
  6. #
  7. # This program is free software; you can redistribute it and/or modify it under
  8. # the terms of the GNU General Public License as published by the Free
  9. # Software Foundation; either version 2 of the License, or (at your option)
  10. # any later version.
  11. #
  12. # Please read the COPYING file.
  13. #
  14. import errno
  15. import traceback
  16. import signal
  17. import os
  18. import sys
  19. import traceback
  20. if os.path.exists("/usr/lib/sulin"):
  21. sys.path.insert(0,"/usr/lib/sulin")
  22. import inary
  23. import inary.cli
  24. import inary.context as ctx
  25. import inary.db
  26. from inary.errors import Error, ParserError
  27. import inary.util
  28. from inary.cli import inarycli
  29. import gettext
  30. gettext.bindtextdomain('inary', "/usr/share/locale")
  31. gettext.textdomain('inary')
  32. __trans = gettext.translation('inary', fallback=True)
  33. _ = __trans.gettext
  34. def sig_handler(sig, frame):
  35. if sig == signal.SIGTERM:
  36. exit()
  37. def exit():
  38. inary.util.noecho(False)
  39. sys.exit(1)
  40. def handle_exception(exception, value, tb):
  41. signal.signal(signal.SIGINT, signal.SIG_IGN) # disable further interrupts
  42. ui = inary.cli.CLI() # make a temporary UI
  43. show_traceback = False
  44. if isinstance(value, ParserError):
  45. show_traceback = True
  46. ui.error(_("\nUnhandled internal exception.\n"
  47. "Please file a bug report to <https://github.com/SulinOS/inary/issues>."))
  48. elif isinstance(value, Error):
  49. ui.error(_("Program terminated."))
  50. elif isinstance(value, KeyboardInterrupt):
  51. ui.error(_("\nKeyboard Interrupt [Ctrl-C]: Exiting..."))
  52. exit()
  53. elif isinstance(value, EOFError):
  54. ui.error(_("\nKeyboard Interrupt [Ctrl-D]: Exiting..."))
  55. exit()
  56. elif isinstance(value, IOError) and value.errno == errno.EPIPE:
  57. # Ignore broken pipe errors
  58. sys.exit(0)
  59. else:
  60. # For any other exception (possibly Python exceptions) show
  61. # the traceback!
  62. show_traceback = ctx.get_option('debug')
  63. ui.error(_("System error. Program terminated."))
  64. if show_traceback:
  65. ui.error("{}: {}".format(exception, str(value)))
  66. else:
  67. msg = str(value)
  68. if msg:
  69. ui.error(msg)
  70. ui.info(_("Please use 'inary help' for general help."))
  71. if show_traceback:
  72. ui.info(_("\nTraceback:"))
  73. traceback.print_tb(tb)
  74. elif not isinstance(value, inary.errors.Error):
  75. ui.info(_("Use --debug to see a traceback."))
  76. exit()
  77. # This is blocking WSL bash to supply stability of packages
  78. # created by packagers.
  79. def blc_wsl():
  80. """Dont allow fucking WSL"""
  81. f = str(os.uname()).lower()
  82. if (("microsoft" in f) or ("wsl" in f) or inary.util.get_cpuinfo("microcode") == "0xffffffff"):
  83. ui = inary.cli.CLI()
  84. ui.error(_("Using inary in WSL environment is not allowed."))
  85. exit(1)
  86. if __name__ == "__main__":
  87. blc_wsl()
  88. sys.excepthook = handle_exception
  89. signal.signal(signal.SIGTERM, sig_handler)
  90. cli = inary.cli.inarycli.InaryCLI()
  91. if cli.command.name[1] in "rdb sf".split():
  92. ctx.filesdb = inary.db.filesdb.FilesDB()
  93. cli.run_command()