sorg-cli 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. #
  4. # Copyright (C) 2005-2010 TUBITAK/UEKAE
  5. #
  6. # This program is free software; you can redistribute it and/or modify it under
  7. # the terms of the GNU General Public License as published by the Free
  8. # Software Foundation; either version 2 of the License, or (at your option)
  9. # any later version.
  10. #
  11. # Please read the COPYING file.
  12. import sys
  13. import optparse
  14. import scom
  15. import sorg
  16. from sorg.consts import package_sep
  17. from sorg.utils import *
  18. sorg_info = " Xorg AutoConfiguration tool"
  19. link = scom.Link()
  20. def safe():
  21. if link.Xorg.Display["sorg"].safeConfig():
  22. link.Xorg.Display["sorg"].syncConfigs()
  23. print("Initialized a safe configuration using VESA driver.")
  24. else:
  25. print("Failed to create a safe configuration with VESA driver.")
  26. def probe(opts):
  27. if link.Xorg.Display["sorg"].initialConfig():
  28. link.Xorg.Display["sorg"].syncConfigs()
  29. print("Created an initial configuration for your video device.")
  30. else:
  31. print("An error occured while creating an initial configuration.")
  32. def setDriver(driver):
  33. # Needed for compatibility with old sorg versions
  34. oldnames = {
  35. "fglrx/ati-drivers": "fglrx",
  36. "nvidia/xorg-video-nvidia96": "nvidia96",
  37. "nvidia/xorg-video-nvidia173": "nvidia173",
  38. "nvidia/xorg-video-nvidia185": "nvidia185",
  39. }
  40. if driver in oldnames:
  41. driver = oldnames[driver]
  42. if package_sep in driver:
  43. drv, pkg = driver.split(package_sep, 1)
  44. if pkg.replace("-", "_") not in list(link.Xorg.Driver):
  45. print("Package is not installed: %s" % pkg)
  46. sys.exit(1)
  47. link.Xorg.Display["sorg"].setDriver(driver)
  48. link.Xorg.Display["sorg"].syncConfigs()
  49. if driver:
  50. print("The video driver is set to '%s'." % driver)
  51. else:
  52. print("The video driver will be selected by the X server.")
  53. if __name__ == "__main__":
  54. parser = optparse.OptionParser(description = "%s version %s"
  55. % (sorg_info, sorg.versionString()))
  56. parser.add_option("-s", "--safe", action="store_true",
  57. dest="safe", default=False,
  58. help="setup VESA config without probing hardware")
  59. parser.add_option("-p", "--probe", action="store_true",
  60. dest="probe", default=False,
  61. help="force probing all devices, even if xorg.conf exists")
  62. parser.add_option("-d", "--driver", action="store", type="string",
  63. dest="driver", default=None, metavar="DRIVER[%sPACKAGE]" % package_sep,
  64. help="set video card driver to DRIVER")
  65. parser.add_option("-k", "--keymap", action="store", type="string",
  66. dest="keymap", default=None, metavar="LAYOUT[/VARIANT]",
  67. help="changes keyboard map")
  68. opts, args = parser.parse_args()
  69. if opts.safe:
  70. safe()
  71. elif opts.probe:
  72. probe(opts)
  73. elif opts.driver is not None:
  74. setDriver(opts.driver)
  75. elif opts.keymap:
  76. if "/" in opts.keymap:
  77. layout, variant = opts.keymap.split("/", 1)
  78. else:
  79. layout, variant = opts.keymap, ""
  80. link.Xorg.Display["sorg"].setKeymap(layout, variant)
  81. else:
  82. parser.print_help()