Esempio n. 1
0
File: app.py Progetto: paledega/scom
    def __init__(self, parent=None):
        mainform.mainForm.__init__(self, parent)

        self.link = scom.Link()

        self.connect(self.buttonServices, SIGNAL("clicked()"),
                     self.getServices)
Esempio n. 2
0
    def driverInfo(self, driver=None):
        if driver is None:
            driver = self.driver

        if driver is None:
            return {}

        link = scom.Link()
        packages = list(link.Xorg.Driver)
        for package in packages:
            try:
                info = link.Xorg.Driver[package].getInfo()
            except dbus.exceptions.DBusException:
                continue
            alias = str(info["alias"])
            if alias == driver:
                info["package"] = package
                return info
        else:
            if driverExists(driver):
                info = {
                    "alias": driver,
                    "xorg-module": driver,
                }
                return info
            else:
                return {}
Esempio n. 3
0
    def enableDriver(self):
        package = self.driverInfo().get("package")
        oldpackage = enabledPackage()
        if package != oldpackage:
            link = scom.Link()
            if oldpackage and oldpackage.replace("-", "_") in list(
                    link.Xorg.Driver):
                link.Xorg.Driver[oldpackage].disable(timeout=2**16 - 1)

            if package:
                link.Xorg.Driver[package].enable(timeout=2**16 - 1)
Esempio n. 4
0
    def __init__(self, *args):
        QtGui.QWidget.__init__(self, None)

        # Create ui
        self.ui = mainform.Ui_mainForm()
        self.ui.setupUi(self)

        # Call Comar
        self.link = scom.Link()

        # Connect button click event to getServices method
        self.connect(self.ui.buttonServices, SIGNAL("clicked()"), self.getServices)
Esempio n. 5
0
def getAvailableDriverNames():
    drvlist = []

    link = scom.Link()
    availablePackages = list(link.Xorg.Driver)
    availableDrivers = sorg.probe.listAvailableDrivers()

    packages = [x.split(consts.package_sep) for x in list(drivers.keys()) if consts.package_sep in x]

    for d in availableDrivers:
        drvlist.append(d)

    for drv, pkg in packages:
        if pkg.replace("-", "_") in availablePackages:
            d = drv + consts.package_sep + pkg
            drvlist.append(d)
            if drv in drvlist:
                drvlist.remove(drv)

    return drvlist
Esempio n. 6
0
def get_link():
    """Connect to the SCOM daemon and return the link."""

    sockname = "/var/run/dbus/system_bus_socket"
    if ctx.dbus_sockname:
        sockname = ctx.dbus_sockname

    alternate = False
    # If SCOM package is updated, all new configuration requests should be
    # made through new SCOM service. Passing alternate=True to Link() class
    # will ensure this.
    if ctx.scom_updated:
        alternate = True

    # This function is sometimes called when scom has recently started
    # or restarting after an update. So we give scom a chance to become
    # active in a reasonable time.
    timeout = 7
    exceptions = []
    while timeout > 0:
        try:
            link = scom.Link(socket=sockname, alternate=alternate)
            link.setLocale()
            return link
        except dbus.exceptions.DBusException as e:
            if str(e) in exceptions:
                pass
            else:
                exceptions.append(str(e))
        except Exception as e:
            if str(e) in exceptions:
                pass
            else:
                exceptions.append(str(e))
        time.sleep(0.2)
        timeout -= 0.2
    raise Error(
        _("Cannot connect to SCOM: \n  \"{}\"\n").format(
            "\n  ".join(exceptions)))
Esempio n. 7
0
def main():
    if len(sys.argv) == 1:
        printUsage()

    link = scom.Link()
    link.setLocale()

    if sys.argv[1] == "list-apps":
        try:
            model = sys.argv[2]
        except IndexError:
            model = None
        if model:
            try:
                _group, _class = model.split(".")
            except ValueError:
                print("Invalid model name")
                return -1
            apps = list(scom.Call(link, _group, _class))
        else:
            apps, interfaces = introspect(link, "/package")
        for app in apps:
            print(app)
    elif sys.argv[1] == "list-models":
        try:
            app = sys.argv[2]
        except IndexError:
            print("Application name is required.")
            return -1
        apps, interfaces = introspect(link, "/package/%s" % app)
        for interface in interfaces:
            print(interface)
    elif sys.argv[1] == "list-methods":
        try:
            app = sys.argv[2]
            model = sys.argv[3]
        except IndexError:
            print("Application and model name are required.")
            return -1
        apps, interfaces = introspect(link, "/package/%s" % app)
        if model in interfaces:
            for method in interfaces[model]:
                print(method)
    elif sys.argv[1] == "register":
        try:
            app = sys.argv[2]
            model = sys.argv[3]
            script = os.path.realpath(sys.argv[4])
        except IndexError:
            printUsage()
        link.register(app, model, script)
    elif sys.argv[1] == "remove":
        try:
            app = sys.argv[2]
        except IndexError:
            printUsage()
        link.remove(app)
    elif sys.argv[1] == "call":
        try:
            app = sys.argv[2]
            model = sys.argv[3]
            method = sys.argv[4]
        except IndexError:
            printUsage()
        try:
            _group, _class = model.split(".")
        except ValueError:
            print("Invalid model name")
            return -1
        met = scom.Call(link, _group, _class, app, method)
        try:
            if len(sys.argv) > 5:
                args = []
                for i in sys.argv[5:]:
                    if i.startswith("[") or i.startswith("(") or i.startswith("{"):
                        args.append(eval(i))
                    else:
                        args.append(i)
                print(met.call(*args))
            else:
                print(met.call())
        except dbus.exceptions.DBusException as e:
            if e._dbus_error_name.endswith(".Scom.PolicyKit"):
                print("Access to '%s' PolicyKit action required." % e.get_dbus_message())
            else:
                print("Error:")
                print("  %s" % e.get_dbus_message())
            return -1
    else:
        printUsage()

    return 0
Esempio n. 8
0
def saveXorgConfig(card):
    parser = XorgParser()

    secFlags    = XorgSection("ServerFlags")
    secDevice   = XorgSection("Device")
    secScr      = XorgSection("Screen")
    secLay      = XorgSection("ServerLayout")

    parser.sections = [
        secFlags,
        secDevice,
        secScr,
        secLay
    ]

    if jailEnabled():
        jailOpts = {
                "DontVTSwitch" : "true",
                }
        secFlags.options.update(jailOpts)

    # Device section
    secDevice.set("Identifier", "VideoCard")
    drvInfo = card.driverInfo()
    if drvInfo:
        secDevice.set("Driver", drvInfo["xorg-module"])

    if card.driver == "fglrx":
        card.depth = 24

    # Monitor sections
    for name, output in list(card.outputs.items()):
        identifier = "Monitor[%s]" % name

        monSec = XorgSection("Monitor")
        parser.sections.append(monSec)
        monSec.set("Identifier", identifier)

        if name in card.monitors:
            monSec.set("VendorName",  card.monitors[name].vendor)
            monSec.set("ModelName",   card.monitors[name].model)
            monSec.set("HorizSync",   unquoted(card.monitors[name].hsync))
            monSec.set("VertRefresh", unquoted(card.monitors[name].vref ))

        secDevice.options["Monitor-%s" % name] = identifier

        if output.ignored:
            monSec.options["Ignore"] = "true"
            continue

        if output.enabled:
            monSec.options["Enable"] = "true"
        else:
            monSec.options["Disable"] = "true"

        if output.mode:
            monSec.options["PreferredMode"] = output.mode

        if output.refresh_rate:
            monSec.options["TargetRefresh"] = output.refresh_rate

        if output.rotation:
            monSec.options["Rotate"] = output.rotation

        if output.right_of:
            monSec.options["RightOf"] = output.right_of
        elif output.below:
            monSec.options["Below"] = output.below

    # Screen section
    secScr.set("Identifier", "Screen")
    secScr.set("Device", "VideoCard")
    if card.depth:
        secScr.set("DefaultDepth", card.depth)

    if "default" in card.outputs:
        output = card.outputs["default"]
        secScr.set("Monitor", "Monitor[default]")

        if output.mode:
            subsec = XorgSection("Display")
            if card.depth:
                subsec.set("Depth", card.depth)
            subsec.set("Modes", output.mode, "800x600", "640x480")
            secScr.sections = [subsec]

    # Layout section
    secLay.set("Identifier", "Layout")
    secLay.set("Screen", "Screen")

    # If this driver has an Xorg.Driver script,
    # call its methods to update sections.
    pkg = drvInfo.get("package")
    if pkg:
        link = scom.Link()
        opts = dbus.Dictionary(secDevice.options, signature="ss")
        try:
            secDevice.options = link.Xorg.Driver[pkg].getDeviceOptions(
                                    card.bus_id, opts)
        except dbus.exceptions.DBusException:
            pass

    # Backup and save xorg.conf
    backup(consts.xorg_conf_file)

    f = open(consts.xorg_conf_file, "w")
    f.write(parser.toString())

    f = open(consts.configured_bus_file, "w")
    f.write(card.bus_id)