software-properties-dbus 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. #
  4. # Copyright © 2010 Harald Sitter <apachelogger@ubuntu.com>
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2 of the License, or
  9. # any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License along
  17. # with this program; if not, write to the Free Software Foundation, Inc.,
  18. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. import dbus
  20. import locale
  21. import logging
  22. import os
  23. import optparse
  24. import sys
  25. from gi.repository import GLib
  26. from softwareproperties.dbus.SoftwarePropertiesDBus import (
  27. SoftwarePropertiesDBus,
  28. )
  29. if __name__ == '__main__':
  30. if sys.getfilesystemencoding() == "ascii" and not "LANG" in os.environ:
  31. try:
  32. locale.setlocale(locale.LC_ALL, "C.UTF-8")
  33. os.putenv("LC_CTYPE", "C.UTF-8")
  34. except locale.Error:
  35. pass
  36. # parser
  37. parser = optparse.OptionParser()
  38. parser.add_option(
  39. '--debug', action='store_true', default=False,
  40. help="Enable debugging messages.")
  41. parser.add_option(
  42. '--datadir', default=None,
  43. help="Set alternative datadir (useful for debugging)")
  44. parser.add_option(
  45. '--session-bus', default=False, action="store_true",
  46. help="Run on the session bus (useful for testing)")
  47. (options, args) = parser.parse_args()
  48. if options.debug:
  49. logging.basicConfig(level=logging.DEBUG)
  50. else:
  51. logging.basicConfig(level=logging.INFO)
  52. # create the server
  53. dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
  54. datadir=options.datadir
  55. if options.session_bus:
  56. bus = dbus.SessionBus()
  57. else:
  58. bus = dbus.SystemBus()
  59. server = SoftwarePropertiesDBus(bus, datadir=datadir)
  60. mainloop = GLib.MainLoop()
  61. mainloop.run()