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.
 
 
 
 
 

60 lines
2.1 KiB

  1. #!/usr/bin/python -S
  2. # -*- python -*-
  3. # reportbug - Report a bug in the Debian distribution.
  4. # Written by Chris Lawrence <lawrencc@debian.org>
  5. # Copyright (C) 1999-2008 Chris Lawrence
  6. # Copyright (C) 2008-2017 Sandro Tosi <morph@debian.org>
  7. #
  8. # This program is freely distributable per the following license:
  9. #
  10. # Permission to use, copy, modify, and distribute this software and its
  11. # documentation for any purpose and without fee is hereby granted,
  12. # provided that the above copyright notice appears in all copies and that
  13. # both that copyright notice and this permission notice appear in
  14. # supporting documentation.
  15. #
  16. # I DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  17. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL I
  18. # BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
  19. # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  20. # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  21. # ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  22. # SOFTWARE.
  23. __all__ = ['text_ui', 'urwid_ui', 'gtk2_ui']
  24. UIS = {'text': 'A text-oriented console user interface',
  25. 'urwid': 'A menu-based console user interface',
  26. 'gtk2': 'A graphical (GTK+) user interface.'}
  27. # Only the available UIs
  28. AVAILABLE_UIS = {}
  29. # List of already loaded ui, we can give back to requestors
  30. __LOADED_UIS = {}
  31. for uis in list(UIS.keys()):
  32. try:
  33. # let's try to import the ui...
  34. ui_module = __import__('reportbug.ui', fromlist=[uis + '_ui'])
  35. # ... and check if it's really imported
  36. ui = getattr(ui_module, uis + '_ui')
  37. # then we can finally add it to AVAILABLE_UIS
  38. AVAILABLE_UIS[uis] = UIS[uis]
  39. __LOADED_UIS[uis] = ui
  40. except:
  41. # we can't import uis, so just skip it
  42. pass
  43. def getUI(ui):
  44. """Returns the requested UI, or default to text if not available"""
  45. if ui in __LOADED_UIS:
  46. print("loading %s" % ui)
  47. return __LOADED_UIS[ui]
  48. else:
  49. print("defaulting to text ui")
  50. return __LOADED_UIS['text']