Exemplo n.º 1
0
def updateData(filepath):
    parse = ciksemel.parse(filepath)

    iconFound = False
    immoduleFound = False

    for icon in parse.tags("File"):
        path = icon.getTagData("Path")
        if path.startswith("usr/share/icons/hicolor") and not iconFound:
            os.system("/usr/bin/gtk-update-icon-cache -f /usr/share/icons/hicolor")
            iconFound = True
            if immoduleFound:
                return

        if fnmatch.fnmatch(path, "usr/lib/gtk-2.0/*immodules/*.so") and not immoduleFound:
            os.system("/usr/bin/gtk-query-immodules-2.0 --update-cache")
            immoduleFound = True
            if iconFound:
                return

        if fnmatch.fnmatch(path, "usr/lib32/gtk-2.0/*immodules/*.so") and not immoduleFound:
            os.system("/usr/bin/gtk-query-immodules-2.0-32bit --update-cache")
            immoduleFound = True
            if iconFound:
                return
Exemplo n.º 2
0
def updateCache(filepath):
    doc = ciksemel.parse(filepath)
    for item in doc.tags("File"):
        path = item.getTagData("Path")
        if path.startswith("usr/share/fonts"):
            subprocess.call(["/usr/bin/fc-cache"])
            return
Exemplo n.º 3
0
def getKeymap():
    layout = None
    variant = ""

    try:
        doc = ciksemel.parse(consts.config_file)

        keyboard = doc.getTag("Keyboard")
        if keyboard:
            layout = keyboard.getTagData("Layout")
            variant = keyboard.getTagData("Variant") or ""

    except OSError:
        pass

    if not layout:
        from sulinpython.localedata import languages

        try:
            language = file("/etc/mudur/language").read().strip()
        except IOError:
            language = "en"

        if language not in languages:
            language = "en"

        keymap = languages[language].keymaps[0]
        layout = keymap.xkb_layout
        variant = keymap.xkb_variant

    return layout, variant
Exemplo n.º 4
0
    def readxml(self, uri, tmpDir='/tmp', sha1sum=False,
                compress=None, sign=None, copylocal=False):
        uri = File.make_uri(uri)
        try:
            localpath = File.download(uri, tmpDir, sha1sum=sha1sum,
                                      compress=compress, sign=sign, copylocal=copylocal)
        except IOError as e:
            raise Error(_("Cannot read URI {0}: {1}").format(uri, str(e)))

        st = io.StringIO()

        try:
            from inary.libraries.preprocess import preprocess
            preprocess.preprocess(
                infile=localpath,
                outfile=st,
                defines=inary.config.Config().values.directives)
            st.seek(0)
        except BaseException:
            st = open(localpath)

        try:
            self.doc = iks.parse(localpath)
            return self.doc
        except Exception as err:
            raise Error(_("File \"{}\" has invalid XML: {}\n").format(localpath,
                                                                      str(err)))
Exemplo n.º 5
0
def checkPaths(filepath):
    doc = ciksemel.parse(filepath)

    for item in doc.tags("File"):
        path = item.getTagData("Path")
        if path.startswith("usr/share/fonts/"):
            updateIndex()
            break
Exemplo n.º 6
0
def updateData(filepath):
    parse = ciksemel.parse(filepath)

    for icon in parse.tags("File"):
        path = icon.getTagData("Path")
        if path.startswith("usr/share/applications"):
            os.system("/usr/bin/update-desktop-database -q")
            return
Exemplo n.º 7
0
def updateData(filepath):
    parse = ciksemel.parse(filepath)

    for icon in parse.tags("File"):
        path = icon.getTagData("Path")
        if path.startswith("usr/lib/gdk-pixbuf-2.0/2.10.0/loaders"):
            os.system("/usr/bin/gdk-pixbuf-query-loaders --update-cache")
            return
Exemplo n.º 8
0
def updateCaches(filepath):
    parse = ciksemel.parse(filepath)
    GIO_MODULE_PATH = "usr/lib32/gio/modules"

    for icon in parse.tags("File"):
        path = icon.getTagData("Path")
        if path.startswith(GIO_MODULE_PATH):
            os.system("/usr/bin/32/gio-querymodules /%s" % GIO_MODULE_PATH)
            break
Exemplo n.º 9
0
def updateMimeTypes(filepath):
    parse = ciksemel.parse(filepath)
    paths = set()
    for icon in parse.tags("File"):
        path = icon.getTagData("Path")
        if "/share/mime/packages/" in path and path.endswith(".xml"):
            paths.add("/%s" % path.partition("packages/")[0])

    for p in paths:
        os.system("/usr/bin/update-mime-database %s" % p)
Exemplo n.º 10
0
def byteCompile(filepath):
    doc = ciksemel.parse(filepath)
    for item in doc.tags("File"):
        path = item.getTagData("Path")
        if path.endswith(".el") and not os.path.exists("/%sc" % path):
            subprocess.call([
                "/usr/bin/emacs", "--no-init-file", "--no-site-file",
                "--multibyte", "-batch", "-f", "batch-byte-compile",
                "/%s" % path
            ])
Exemplo n.º 11
0
def removeByteCompiled(filepath):
    doc = ciksemel.parse(filepath)
    for item in doc.tags("File"):
        path = item.getTagData("Path")
        if path.endswith(".el"):
            try:
                # Remove .elc
                os.unlink("/%sc" % path)
            except OSError:
                pass
Exemplo n.º 12
0
def saveDeviceInfo(card):
    if not os.path.exists(consts.config_dir):
        os.mkdir(consts.config_dir, 0o755)

    try:
        doc = ciksemel.parse(consts.config_file)
    except OSError:
        doc = ciksemel.newDocument("ZORG")

    for tag in doc.tags("Card"):
        if tag.getAttribute("busId") == card.bus_id:
            tag.hide()
            break

    cardTag = doc.insertTag("Card")
    cardTag.setAttribute("busId", card.bus_id)

    addTag(cardTag, "VendorId", card.vendor_id)
    addTag(cardTag, "ProductId", card.product_id)

    if card.driver:
        addTag(cardTag, "Driver", card.driver)

    if card.depth:
        addTag(cardTag, "Depth", str(card.depth))

    # Save output info
    outputs = cardTag.insertTag("Outputs")
    for name, output in list(card.outputs.items()):
        out = outputs.insertTag("Output")
        out.setAttribute("name", name)
        addTag(out, "Enabled", "true" if output.enabled else "false")
        addTag(out, "Ignored", "true" if output.ignored else "false")
        if output.mode:
            addTag(out, "Mode", output.mode)
        if output.refresh_rate:
            addTag(out, "RefreshRate", output.refresh_rate)
        if output.rotation:
            addTag(out, "Rotation", output.rotation)
        if output.right_of:
            addTag(out, "RightOf", output.right_of)
        if output.below:
            addTag(out, "Below", output.below)

        if name in card.monitors:
            mon = card.monitors[name]
            monitor = out.insertTag("Monitor")
            addTag(monitor, "Vendor", mon.vendor)
            addTag(monitor, "Model", mon.model)
            addTag(monitor, "HorizSync", mon.hsync)
            addTag(monitor, "VertRefresh", mon.vref)

    f = open(consts.config_file, "w")
    f.write(doc.toPrettyString().replace("\n\n", ""))
Exemplo n.º 13
0
def installGconfSchemas(filepath):
    os.environ[
        'GCONF_CONFIG_SOURCE'] = 'xml:merged:/etc/gconf/gconf.xml.defaults'
    parse = ciksemel.parse(filepath)
    schemas = []
    for schema in parse.tags("File"):
        path = schema.getTagData("Path")
        if path.startswith("etc/gconf/schemas"):
            schemas.append("/" + path)

    if schemas:
        os.system("/usr/bin/gconftool-2 --makefile-install-rule %s" %
                  " ".join(schemas))
Exemplo n.º 14
0
def updateCaches(filepath):
    parse = ciksemel.parse(filepath)
    GIO_MODULE_PATH = "usr/lib/gio/modules"
    GSCHEMAS_MODULE_PATH = "usr/share/glib-2.0/schemas"

    for icon in parse.tags("File"):
        path = icon.getTagData("Path")
        if path.startswith(GIO_MODULE_PATH):
            os.system("/usr/bin/gio-querymodules /%s" % GIO_MODULE_PATH)
            break

    for icon in parse.tags("File"):
        path = icon.getTagData("Path")
        if path.startswith(GSCHEMAS_MODULE_PATH):
            os.system("/usr/bin/glib-compile-schemas /%s" %
                      GSCHEMAS_MODULE_PATH)
            return
Exemplo n.º 15
0
def saveKeymap(layout, variant=""):
    if not os.path.exists(consts.config_dir):
        os.mkdir(consts.config_dir, 0o755)

    try:
        doc = ciksemel.parse(consts.config_file)
    except OSError:
        doc = ciksemel.newDocument("ZORG")

    keyboardTag = doc.getTag("Keyboard")

    if keyboardTag:
        keyboardTag.hide()

    keyboardTag = doc.insertTag("Keyboard")
    keyboardTag.insertTag("Layout").insertData(layout)
    if variant:
        keyboardTag.insertTag("Variant").insertData(variant)

    f = file(consts.config_file, "w")
    f.write(doc.toPrettyString().replace("\n\n", ""))
Exemplo n.º 16
0
def getDeviceInfo(busId):
    if not os.path.exists(consts.config_file):
        return

    doc = ciksemel.parse(consts.config_file)

    cardTag = None
    for tag in doc.tags("Card"):
        if tag.getAttribute("busId") == busId:
            cardTag = tag
            break

    if not cardTag:
        return

    device = VideoDevice(busId=busId)

    device.saved_vendor_id  = cardTag.getTagData("VendorId")
    device.saved_product_id = cardTag.getTagData("ProductId")

    driver = cardTag.getTagData("Driver")
    activeConfigTag = cardTag.getTag("ActiveConfig")

    if driver:
        device.driver = driver
    elif activeConfigTag:
        driver = activeConfigTag.getTagData("Driver")
        if driver:
            device.driver = driver

    depth = cardTag.getTagData("Depth")
    if depth:
        device.depth = int(depth)

    def addMonitor(output, tag):
        mon = Monitor()
        mon.vendor = tag.getTagData("Vendor") or ""
        mon.model  = tag.getTagData("Model") or "Unknown Monitor"
        mon.hsync  = tag.getTagData("HorizSync") or mon.hsync
        mon.vref   = tag.getTagData("VertRefresh") or mon.vref
        device.monitors[output] = mon

    # Get output info
    outputsTag = cardTag.getTag("Outputs")
    if outputsTag:
        for outputTag in outputsTag.tags("Output"):
            name = outputTag.getAttribute("name")
            output = Output(name)
            device.outputs[name] = output

            enabled = outputTag.getTagData("Enabled")
            if enabled:
                output.setEnabled(enabled == "true")
            ignored = outputTag.getTagData("Ignored")
            if ignored:
                output.setIgnored(ignored == "true")

            mode = outputTag.getTagData("Mode") or ""
            rate = outputTag.getTagData("RefreshRate") or ""
            output.setMode(mode, rate)

            rotation = outputTag.getTagData("Rotation")
            if rotation:
                output.setOrientation(rotation)

            rightOf = outputTag.getTagData("RightOf")
            below = outputTag.getTagData("Below")
            if rightOf:
                output.setPosition("RightOf", rightOf)
            elif below:
                output.setPosition("Below", below)

            monitorTag = outputTag.getTag("Monitor")
            if monitorTag:
                addMonitor(name, monitorTag)

    return device