def check_dkms(metapath, filepath, action): if piksemel.parse(metapath).getTag("Package").getTagData( "Name") == "kernel-module-headers": kver = get_kver() arch = piksemel.parse(metapath).getTag("Package").getTagData( "Architecture").replace("_", "-") # rebuild if /usr/src/*/dkms.conf exists for d in os.walk("/usr/src").next()[1]: if os.path.isfile("/usr/src/%s/dkms.conf" % d): m = re.match(r"(?P<name>[^\/]+)-(?P<version>[^-]+)", d).groupdict() run_dkms(action, m["name"], m["version"], kver, arch) generate_initrd(kver) if raise_install: raise BuildModuleError("\n\t".join(raise_install)) return parse = piksemel.parse(filepath) for fp in parse.tags("File"): path = fp.getTagData("Path") # build if package has /usr/src/*/dkms.conf if path.endswith("/dkms.conf") and path.startswith("usr/src/"): m = re.match(r".*\/(?P<name>[^\/]+)-(?P<version>[^-]+)\/[^\/]+", path).groupdict() kver = get_kver() arch = piksemel.parse(metapath).getTag("Package").getTagData( "Architecture").replace("_", "-") run_dkms(action, m["name"], m["version"], kver, arch) if raise_install: raise BuildModuleError(raise_install.pop()) generate_initrd(kver) return
def extract_pspecs(path, language): messages = [] paks = find_pspecs(path) for pak in paks: msg = Message() msg.reference = pak[len(path):] + ":summary" doc = iks.parse(pak + "/pspec.xml") source = doc.getTag("Source") for item in source.tags("Summary"): lang = item.getAttribute("xml:lang") if not lang or lang == "en": msg.msgid = item.firstChild().data() elif lang == language: msg.msgstr = item.firstChild().data() messages.append(msg) msg = Message() msg.reference = pak[len(path):] + ":description" doc = iks.parse(pak + "/pspec.xml") source = doc.getTag("Source") for item in source.tags("Description"): lang = item.getAttribute("xml:lang") if not lang or lang == "en": msg.msgid = item.firstChild().data() elif lang == language: msg.msgstr = item.firstChild().data() messages.append(msg) return messages
def updateInitrd(filepath): parse = piksemel.parse(filepath) for xmlfile in parse.tags("File"): path = xmlfile.getTagData("Path") if not path.startswith("/"): path = "/%s" % path # Just in case if path.startswith("/lib/modules"): # Handle the proper case of modules version = path.split("/")[3] cmd = "/sbin/depmod %s" % version os.system(cmd) cmd = "dracut -N -f --kver %s" % version os.system(cmd) initname = "/boot/initramfs-%s.img" % version if os.path.exists("/boot/efi/pisi"): try: shutil.copy(initname, "/boot/efi/pisi/initramfs") except Exception, e: print("Failed to copy efi boot") if os.path.exists("/proc/cmdline" ) and not os.path.exists("/sys/firmware/efi"): os.system("/usr/sbin/update-grub") break
def updateData(filepath): parse = piksemel.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
def read_translations(self, path): if not os.path.exists(path): return try: doc = piksemel.parse(path) except Exception, e: raise Error(_("File '%s' has invalid XML") % (path) )
def domodules(filepath): doc = piksemel.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
def getSourceIndex(indexfile): if indexfile.endswith(".bz2"): import bz2 data = file(indexfile).read() data = bz2.decompress(data) doc = piksemel.parseString(data) else: doc = piksemel.parse(indexfile) sources = {} packages = {} base = [] for tag in doc.tags("SpecFile"): name = tag.getTag("Source").getTagData("Name") sources[name] = {} version = tag.getTag("History").getTag("Update").getTagData("Version") release = tag.getTag("History").getTag("Update").getAttribute("release") sources[name]["version"] = "%s-%s" % (version, release) sources[name]["deps"] = [] sources[name]["packages"] = [] for pak in tag.tags("Package"): packages[pak.getTagData("Name")] = name sources[name]["packages"].append(pak.getTagData("Name")) deps = tag.getTag("Source").getTag("BuildDependencies") if deps: sources[name]["deps"] = [] for dep in deps.tags("Dependency"): sources[name]["deps"].append(dep.firstChild().data()) if tag.getTag("Source").getTagData("PartOf") in ["system.base", "system.devel"]: base.extend(sources[name]["packages"]) return sources, packages, base
def make_index(self, package_list): doc = piksemel.newDocument("PISI") # since new PiSi (pisi 2) needs component info in index file, we need to copy it from original index that user specified indexpath = fetch_uri(self.base_uri, self.cache_dir, self.index_name, None, False) if indexpath.endswith(".bz2"): import bz2 data = open(indexpath).read() data = bz2.decompress(data) doc_index = piksemel.parseString(data) elif indexpath.endswith(".xz"): try: import lzma except ImportError: print "Install python-pyliblzma package, or try a different index format." return data = open(indexpath).read() data = lzma.decompress(data) doc_index = piksemel.parseString(data) else: doc_index = piksemel.parse(indexpath) # old PiSi needs obsoletes list, so we need to copy it too. for comp_node in doc_index.tags("Distribution"): doc.insertNode(comp_node) for name in package_list: doc.insertNode(self.packages[name].node) for comp_node in doc_index.tags("Component"): doc.insertNode(comp_node) return doc.toPrettyString()
def parseOperations(self): operations = [] operationList = [] files = filter(lambda x:x.endswith(".xml"), os.listdir(working_path)) for file in files: operationList.append([file, (file.split("_")[1]).split(".")[0]]) operationList.sort() for operation in range(0, len(operationList)): op_file = operationList[operation][0] op_type = operationList[operation][1] doc = piksemel.parse(working_path + "/" + op_file) parent = doc.getTag("Operation") for i in parent.tags("Packages"): packages = [] if op_type == "install": for x in i.tags("PackageURI"): packages.append(pkgs_path + "/" + str(x.firstChild().data())) else: for x in i.tags("Package"): packages.append(str(x.firstChild().data())) operations.append([op_type, packages]) return operations
def readxmlfile(self, file): raise Exception("not implemented") try: self.doc = iks.parse(file) return self.doc except Exception, e: raise Error(_("File '%s' has invalid XML") % (localpath))
def readxml(self, uri, tmpDir='/tmp', sha1sum=False, compress=None, sign=None, copylocal=False): uri = pisi.file.File.make_uri(uri) # workaround for repo index files to fix # rev. 17027 regression (http://liste.pardus.org.tr/gelistirici/2008-February/011133.html) compressed = str(uri).endswith(".bz2") or str(uri).endswith(".gz") if uri.is_local_file() and not compressed: # this is a local file localpath = uri.path() else: # this is a remote file, first download it into tmpDir localpath = pisi.file.File.download(uri, tmpDir, sha1sum=sha1sum, compress=compress, sign=sign, copylocal=copylocal) try: self.doc = iks.parse(localpath) return self.doc except Exception, e: raise Error(_("File '%s' has invalid XML") % (localpath))
def get_repo_doc(self, repo_name): if not self.has_repo(repo_name): raise RepoError(_("Repository %s does not exist.") % repo) repo = self.get_repo(repo_name) index_path = repo.indexuri.get_uri() #FIXME Local index files should also be cached. if File.is_compressed(index_path) or repo.indexuri.is_remote_file(): index = os.path.basename(index_path) index_path = pisi.util.join_path(ctx.config.index_dir(), repo_name, index) if File.is_compressed(index_path): index_path = os.path.splitext(index_path)[0] if not os.path.exists(index_path): ctx.ui.warning(_("%s repository needs to be updated") % repo_name) return piksemel.newDocument("PISI") try: return piksemel.parse(index_path) except Exception as e: raise RepoError(_("Error parsing repository index information. Index file does not exist or is malformed."))
def fromXML(self, filename=None, clear=False): """Load configuration from specified filename. (default: ~/.lider.xml)""" create_new = False if not filename: filename = os.path.join(os.environ["HOME"], ".lider.xml") create_new = True if not os.path.exists(filename): if create_new: file(filename, "w").write("<Lider></Lider>") else: raise DomainConfigMissing, i18n("Domain configuration file is missing.") try: doc = piksemel.parse(filename) except (piksemel.ParseError, MemoryError): raise DomainXMLParseError, i18n("Domain configuration file has syntax errors.") if clear: self.clear() for tag in doc.tags(): if tag.name() == "Domain": label = unicode(tag.getAttribute("label")) host = tag.getTagData("Host") base_dn = tag.getTagData("BaseDN") bind = tag.getTag("Bind") if bind: bind_dn = bind.getTagData("DN") bind_password = bind.getTagData("Password") else: bind_dn = "" bind_password = "" connection = Connection(label, host, base_dn, bind_dn, bind_password) self.connections.append(connection)
def domodules(filepath): doc = piksemel.parse(filepath) for item in doc.tags("File"): path = item.getTagData("Path") if path.startswith("lib/modules/"): subprocess.call(["/sbin/update-modules"]) return
def updateXMLCatalog(filepath): parse = piksemel.parse(filepath) for xmlfile in parse.tags("File"): path = xmlfile.getTagData("Path") if "/share/xml/" in path: os.system("/usr/bin/build-docbook-catalog --version=4.5") break
def updateIconCache(filepath): parse = piksemel.parse(filepath) for icon in parse.tags("File"): path = icon.getTagData("Path") if path.startswith("usr/share/icons/hicolor"): os.system("/usr/bin/gtk-update-icon-cache -f /usr/share/icons/hicolor") return
def getKeymap(): layout = None variant = "" try: doc = piksemel.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 pardus.localedata import languages try: language = file("/etc/mudur/language").read().strip() except IOError: language = "en" if not languages.has_key(language): language = "en" keymap = languages[language].keymaps[0] layout = keymap.xkb_layout variant = keymap.xkb_variant return layout, variant
def installGconfSchemas(filepath): os.environ['GCONF_CONFIG_SOURCE'] = 'xml:merged:/etc/gconf/gconf.xml.defaults' parse = piksemel.parse(filepath) for schema in parse.tags("File"): path = schema.getTagData("Path") if path.startswith("etc/gconf/schemas"): os.system("/usr/bin/gconftool-2 --makefile-install-rule /%s" % path)
def read_translations(self, path): if not os.path.exists(path): return try: doc = piksemel.parse(path) except Exception, e: raise Error(_("File '%s' has invalid XML") % (path))
def main(args): global data doc = piksemel.parse(args) data = yaliKickstartData() data.language = doc.getTagData("language") data.keyData.X = doc.getTagData("keymap") data.rootPassword = doc.getTagData("root_password") data.hostname = doc.getTagData("hostname") usrsTag = doc.getTag("users") for p in usrsTag.tags(): info = yaliUser() info.autologin = p.getAttribute("autologin") info.username = p.getTagData("username") info.realname = p.getTagData("realname") info.password = p.getTagData("password") if (p.getTagData("groups") != None): info.groups = p.getTagData("groups").split(",") data.users.append(info) partitioning = doc.getTag("partitioning") data.partitioningType = partitioning.getAttribute("partitioning_type") for q in partitioning.tags(): partinfo = yaliPartition() partinfo.partitionType = q.getAttribute("partition_type") partinfo.format = q.getAttribute("format") partinfo.ratio = q.getAttribute("ratio") partinfo.fsType = q.getAttribute("fs_type") partinfo.mountPoint = q.getAttribute("mountpoint") partinfo.disk = q.firstChild().data() data.partitioning.append(partinfo) return data
def updateSystemFonts (filepath): parse = piksemel.parse (filepath) for xmlfile in parse.tags("File"): path = xmlfile.getTagData ("Path") if "/share/fonts/" in path: os.system ("fc-cache -fv") break
def dotexmfupdate(metapath): doc = piksemel.parse(metapath) for item in doc.tags("Source"): sourcename = item.getTagData("Name") if sourcename.startswith("texlive-"): subprocess.call(["/usr/bin/texmf-update"]) return
def updateData(filepath): parse = piksemel.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-3.0/*immodules/*.so") and not immoduleFound: os.system("/usr/bin/gtk-query-immodules-3.0 --update-cache") immoduleFound = True if iconFound: return if fnmatch.fnmatch(path, "usr/lib32/gtk-3.0/*immodules/*.so") and not immoduleFound: os.system("/usr/bin/gtk-query-immodules-3.0-32bit --update-cache") immoduleFound = True if iconFound: return
def get_repo_doc(self, repo_name): if not self.has_repo(repo_name): raise RepoError(_("Repository %s does not exist.") % repo) repo = self.get_repo(repo_name) index_path = repo.indexuri.get_uri() #FIXME Local index files should also be cached. if File.is_compressed(index_path) or repo.indexuri.is_remote_file(): index = os.path.basename(index_path) index_path = pisi.util.join_path(ctx.config.index_dir(), repo_name, index) if File.is_compressed(index_path): index_path = os.path.splitext(index_path)[0] if not os.path.exists(index_path): ctx.ui.warning(_("%s repository needs to be updated") % repo_name) return piksemel.newDocument("PISI") try: return piksemel.parse(index_path) except Exception, e: raise RepoError(_("Error parsing repository index information. Index file does not exist or is malformed."))
def getDesktopNumber(self): try: FILE_PATH="%s/.config/xfce4/xfconf/xfce-perchannel-xml/xfwm4.xml"%os.environ["HOME"] parse_file=piksemel.parse(FILE_PATH) x = parse_file.getTag("property") temp_file_path="%s/.config/.tempf.txt"%os.environ["HOME"] temp_file=open(temp_file_path,"w") temp_file.write(x.toString()) temp_file.close() temp_file=open(temp_file_path) a=temp_file.read() x=re.search("<property name=\"workspace_count\" type=\"int\" value=\".*/>",a) deger= len(x.group().split("=")[3]) if deger==5: number= int(x.group().split("=")[3][-4]) os.remove(temp_file_path) return number else: number1= int(x.group().split("=")[3][-4]) number2= int(x.group().split("=")[3][-5]) os.remove(temp_file_path) return int(str(number2)+str(number1)) except: # default desktop number value is 4 return 4
def updateDesktopDatabase (filepath): parse = piksemel.parse (filepath) for xmlfile in parse.tags("File"): path = xmlfile.getTagData ("Path") if "/share/applications/" in path: os.system ("/usr/bin/update-desktop-database") break
def groupList(): import piksemel gdefs = {} doc = piksemel.parse("/etc/comar/security-comments.xml") for item in doc.getTag("groups").tags(): dict = {} for tag in item.tags("purpose"): lang = tag.getAttribute("xml:lang") if not lang: lang = "en" dict[lang] = tag.firstChild().data() dict2 = {} for tag in item.tags("comment"): lang = tag.getAttribute("xml:lang") if not lang: lang = "en" dict2[lang] = tag.firstChild().data() gdefs[item.getAttribute("name")] = (_(dict), _(dict2)) def format(defs, dict, gid): item = dict[gid] if defs.has_key(item.name): d = defs[item.name] return "%s\t%s\t%s\t%s" % (item.gid, item.name, d[0], d[1]) else: return "%s\t%s" % (item.gid, item.name) db = Database(for_read=True) ret = "\n".join(map(lambda x: format(gdefs, db.groups, x), db.groups)) return ret
def updateGLibSchemas (filepath): parse = piksemel.parse (filepath) for xmlfile in parse.tags("File"): path = xmlfile.getTagData ("Path") if "/share/glib-2.0/schemas/" in path: os.system ("glib-compile-schemas /usr/share/glib-2.0/schemas") break
def getDesktopNumber(self): try: FILE_PATH = "%s/.gconf/apps/metacity/general/" % os.environ[ "HOME"] + "%gconf.xml" parse_file = piksemel.parse(FILE_PATH) x = parse_file.getTag("entry") temp_file_path = "%s/.tempf.txt" % os.environ["HOME"] temp_file = open(temp_file_path, "w") temp_file.write(x.toString()) temp_file.close() temp_file = open(temp_file_path) a = temp_file.read() x = re.search("<entry name=\"num_workspaces\".*/>", a) deger = len(x.group().split("=")[4]) if deger == 5: number = int(x.group()[-4]) os.remove(temp_file_path) return number else: number1 = int(x.group()[-4]) number2 = int(x.group()[-5]) os.remove(temp_file_path) a = int(str(number2) + str(number1)) return a except: # default desktop number value 4 return 4
def __add_to_revdeps(self, package, revdeps): metadata_xml = os.path.join(self.package_path(package), ctx.const.metadata_xml) try: meta_doc = piksemel.parse(metadata_xml) pkg = meta_doc.getTag("Package") except: pkg = None if pkg is None: # If package info is broken or not available, skip it. ctx.ui.warning( _("Installation info for package '%s' is broken. " "Reinstall it to fix this problem.") % package ) del self.installed_db[package] return deps = pkg.getTag("RuntimeDependencies") if deps: for dep in deps.tags("Dependency"): revdep = revdeps.setdefault(dep.firstChild().data(), {}) revdep[package] = dep.toString() for anydep in deps.tags("AnyDependency"): for dep in anydep.tags("Dependency"): revdep = revdeps.setdefault(dep.firstChild().data(), {}) revdep[package] = anydep.toString()
def updateSystemFonts(filepath): parse = piksemel.parse(filepath) for xmlfile in parse.tags("File"): path = xmlfile.getTagData("Path") if "/share/fonts/" in path: os.system("fc-cache -fv") break
def main(args): global data doc=piksemel.parse(args) data=yaliKickstartData() data.language=doc.getTagData("language") data.keyData.X=doc.getTagData("keymap") data.rootPassword=doc.getTagData("root_password") data.hostname=doc.getTagData("hostname") usrsTag=doc.getTag("users") for p in usrsTag.tags(): info=yaliUser() info.autologin=p.getAttribute("autologin") info.username=p.getTagData("username") info.realname=p.getTagData("realname") info.password=p.getTagData("password") if(p.getTagData("groups")!=None): info.groups=p.getTagData("groups").split(",") data.users.append(info) partitioning=doc.getTag("partitioning") data.partitioningType=partitioning.getAttribute("partitioning_type") for q in partitioning.tags(): partinfo=yaliPartition() partinfo.partitionType=q.getAttribute("partition_type") partinfo.format=q.getAttribute("format") partinfo.ratio=q.getAttribute("ratio") partinfo.fsType=q.getAttribute("fs_type") partinfo.mountPoint=q.getAttribute("mountpoint") partinfo.disk=q.firstChild().data() data.partitioning.append(partinfo) return data
def updateCache(filepath): doc = piksemel.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
def getDesktopNumber(self): try: FILE_PATH="%s/.gconf/apps/metacity/general/"%os.environ["HOME"]+"%gconf.xml" parse_file=piksemel.parse(FILE_PATH) x = parse_file.getTag("entry") temp_file_path="%s/.tempf.txt"%os.environ["HOME"] temp_file=open(temp_file_path,"w") temp_file.write(x.toString()) temp_file.close() temp_file=open(temp_file_path) a=temp_file.read() x=re.search("<entry name=\"num_workspaces\".*/>",a) deger= len(x.group().split("=")[4]) if deger==5: number= int(x.group()[-4]) os.remove(temp_file_path) return number else: number1= int(x.group()[-4]) number2= int(x.group()[-5]) os.remove(temp_file_path) a= int(str(number2)+str(number1)) return a except: # default desktop number value 4 return 4
def updatePixbufLoaders(filepath): parse = piksemel.parse(filepath) for xmlfile in parse.tags("File"): path = xmlfile.getTagData("Path") if "/lib/gtk-2.0" in path or "/lib/gdk-pixbuf-2.0" in path: os.system("gdk-pixbuf-query-loaders --update-cache") break
def parse_index(self, console=None, update_repo=False): path = fetch_uri(self.base_uri, self.cache_dir, self.index_name, console, update_repo) if path.endswith(".bz2"): import bz2 data = file(path).read() data = bz2.decompress(data) doc = piksemel.parseString(data) else: doc = piksemel.parse(path) for tag in doc.tags('Package'): p = Package(tag) self.packages[p.name] = p self.size += p.size self.inst_size += p.inst_size self.components[p.component] = [] for name in self.packages: p = self.packages[name] for name2 in p.depends: if self.packages.has_key(name2): self.packages[name2].revdeps.append(p.name) else: print "Error: package %s depends on non existing package %s" % (p.name, name2) if self.components.has_key(p.component): self.components[p.component].append(p.name) from pisi.graph import Digraph, CycleException dep_graph = Digraph() for name in self.packages: p = self.packages[name] for dep in p.depends: dep_graph.add_edge(name, dep) try: dep_graph.dfs() except CycleException, c: print "Error: Cyclic dependency detected: %s" % " -> ".join(c.cycle) sys.exit(1)
def updateDesktopDatabase(filepath): parse = piksemel.parse(filepath) for xmlfile in parse.tags("File"): path = xmlfile.getTagData("Path") if "/share/applications/" in path: os.system("/usr/bin/update-desktop-database") break
def open(self, filename): try: doc = piksemel.parse(filename) except OSError, e: if e.errno == 2: return _("Project file '%s' does not exists!" % filename) raise
def parsexmldata(self): xmldata = piksemel.parse(self.tfile) for sroottag in xmldata.tags('Source'):#Source blok bilgilerini al self.SourceName = sroottag.getTagData('Name') try: for stag in sroottag.tags('Summary'): slang = stag.getAttribute('xml:lang') scontent = stag.firstChild().data() self.SourceSummary[slang] = scontent except: print "Source(Summary) Yok" try: for dtag in sroottag.tags('Description'): dlang = dtag.getAttribute('xml:lang') dcontent = dtag.firstChild().data() self.SourceDescription[dlang] = dcontent except: print "Source(Description) yok" for droottag in xmldata.tags('Package'):#Package blok bilgilerini al self.PackageName = droottag.getTagData('Name') try: for stag in droottag.tags('Summary'): slang = stag.getAttribute('xml:lang') scontent = stag.firstChild().data() self.PackageSummary[slang] = scontent except: print "Package(Summary) Yok" try: for dtag in droottag.tags('Description'): dlang = dtag.getAttribute('xml:lang') dcontent = dtag.firstChild().data() self.PackageDescription[dlang] = dcontent except: print "Package(Description) yok"
def getDesktopNumber(self): try: FILE_PATH = "%s/.config/xfce4/xfconf/xfce-perchannel-xml/xfwm4.xml" % os.environ[ "HOME"] parse_file = piksemel.parse(FILE_PATH) x = parse_file.getTag("property") temp_file_path = "%s/.config/.tempf.txt" % os.environ["HOME"] temp_file = open(temp_file_path, "w") temp_file.write(x.toString()) temp_file.close() temp_file = open(temp_file_path) a = temp_file.read() x = re.search( "<property name=\"workspace_count\" type=\"int\" value=\".*/>", a) deger = len(x.group().split("=")[3]) if deger == 5: number = int(x.group().split("=")[3][-4]) os.remove(temp_file_path) return number else: number1 = int(x.group().split("=")[3][-4]) number2 = int(x.group().split("=")[3][-5]) os.remove(temp_file_path) return int(str(number2) + str(number1)) except: # default desktop number value is 4 return 4
def updateData(filepath): parse = piksemel.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 > /etc/gtk-2.0/gtk.immodules") immoduleFound = True if iconFound: return if fnmatch.fnmatch(path, "usr/lib32/gtk-2.0/*immodules/*.so") and not immoduleFound: immodulesdir = "/etc/gtk-2.0/32bit" if not os.path.exists(immodulesdir): os.makedirs(immodulesdir, 0755) os.system("/usr/bin/gtk-query-immodules-2.0-32bit > %s/gtk.immodules" % immodulesdir) immoduleFound = True if iconFound: return
def readxml(self, uri, tmpDir='/tmp', sha1sum=False, compress=None, sign=None, copylocal = False): uri = pisi.file.File.make_uri(uri) # workaround for repo index files to fix # rev. 17027 regression (http://liste.pardus.org.tr/gelistirici/2008-February/011133.html) compressed = pisi.file.File.is_compressed(str(uri)) if uri.is_local_file() and not compressed: # this is a local file localpath = uri.path() if not tmpDir == '/tmp': # copy file for autocompletion import shutil shutil.copy(localpath, tmpDir) else: # this is a remote file, first download it into tmpDir localpath = pisi.file.File.download(uri, tmpDir, sha1sum=sha1sum, compress=compress,sign=sign, copylocal=copylocal) try: self.doc = iks.parse(localpath) return self.doc except OSError, e: raise Error(_("Unable to read file (%s): %s") %(localpath,e))
def removeByteCompiled(filepath): doc = piksemel.parse(filepath) # collect paths in set and then remove empty ones dirs = set() for item in doc.tags("File"): path = item.getTagData("Path") if path.endswith(".py"): d, f = os.path.split(path) r, e = os.path.splitext(f) dirs.add(d) dirs.add("%s/__pycache__" % d) try: os.unlink("/%sc" % path) except OSError: pass try: os.unlink("/%so" % path) except OSError: pass try: os.unlink("%s/__pycache__/%s.cpython-32%sc" % (d,r,e)) except OSError: pass try: os.unlink("%s/__pycache__/%s.cpython-32%so" % (d,r,e)) except OSError: pass # remove empy dirs dirs = list(dirs) dirs.sort(reverse=True) for d in dirs: if not os.listdir(d): os.rmdir(d)
def readxml(self, uri, tmpDir='/tmp', sha1sum=False, compress=None, sign=None, copylocal = False): uri = pisilinux.file.File.make_uri(uri) # workaround for repo index files to fix # rev. 17027 regression (http://liste.pardus.org.tr/gelistirici/2008-February/011133.html) compressed = pisilinux.file.File.is_compressed(str(uri)) if uri.is_local_file() and not compressed: # this is a local file localpath = uri.path() if not tmpDir == '/tmp': # copy file for autocompletion import shutil shutil.copy(localpath, tmpDir) else: # this is a remote file, first download it into tmpDir localpath = pisilinux.file.File.download(uri, tmpDir, sha1sum=sha1sum, compress=compress,sign=sign, copylocal=copylocal) try: self.doc = iks.parse(localpath) return self.doc except OSError as e: raise Error(_("Unable to read file (%s): %s") %(localpath,e)) except Exception as e: raise Error(_("File '%s' has invalid XML") % (localpath) )
def updatePixbufLoaders (filepath): parse = piksemel.parse (filepath) for xmlfile in parse.tags("File"): path = xmlfile.getTagData ("Path") if "/lib/gtk-2.0" in path or "/lib/gdk-pixbuf-2.0" in path: os.system ("gdk-pixbuf-query-loaders --update-cache") break
def update_pspecs(path, language, po): for msg in po.messages: if not msg.msgstr: continue if "fuzzy" in msg.flags: continue name, tag = msg.reference.split(':') name = os.path.join(path, name, "pspec.xml") tag = tag.title() doc = iks.parse(name) source = doc.getTag("Source") data = None for item in source.tags(tag): lang = item.getAttribute("xml:lang") if lang == language: item.firstChild().hide() item.appendData(msg.msgstr) data = doc.toString() if not data: if tag == "Description": item = source.getTag("Archive").previousTag() else: item = source.getTag("Description").previousTag() item = item.appendSiblingData("\n ") new = item.appendSibling(tag) new.setAttribute("xml:lang", language) new.appendData(msg.msgstr) data = doc.toString() if data: f = file(name, "w") f.write(pspec_header) f.write(data) f.write("\n") f.close()
def updateData(filepath): parse = piksemel.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-3.0/*immodules/*.so") and not immoduleFound: os.system("/usr/bin/gtk-query-immodules-3.0 > /etc/gtk-3.0/gtk.immodules") immoduleFound = True if iconFound: return if fnmatch.fnmatch(path, "usr/lib32/gtk-3.0/*immodules/*.so") and not immoduleFound: immodulesdir = "/etc/gtk-3.0/32bit" if not os.path.exists(immodulesdir): os.makedirs(immodulesdir, 0755) os.system("/usr/bin/gtk-query-immodules-3.0-32bit > %s/gtk.immodules" % immodulesdir) immoduleFound = True if iconFound: return
def make_index(self, package_list): doc = piksemel.newDocument("PISI") # since new PiSi (pisi 2) needs component info in index file, we need to copy it from original index that user specified indexpath = fetch_uri(self.base_uri, self.cache_dir, self.index_name, None, False) if indexpath.endswith(".bz2"): import bz2 data = file(indexpath).read() data = bz2.decompress(data) doc_index = piksemel.parseString(data) else: doc_index = piksemel.parse(indexpath) # old PiSi needs obsoletes list, so we need to copy it too. for comp_node in doc_index.tags("Distribution"): doc.insertNode(comp_node) for name in package_list: doc.insertNode(self.packages[name].node) for comp_node in doc_index.tags("Component"): doc.insertNode(comp_node) return doc.toPrettyString()
def getSourceIndex(indexfile): if indexfile.endswith(".bz2"): import bz2 data = file(indexfile).read() data = bz2.decompress(data) doc = piksemel.parseString(data) else: doc = piksemel.parse(indexfile) sources = {} packages = {} base = [] for tag in doc.tags("SpecFile"): name = tag.getTag("Source").getTagData("Name") sources[name] = {} version = tag.getTag('History').getTag('Update').getTagData('Version') release = tag.getTag('History').getTag('Update').getAttribute( 'release') sources[name]["version"] = "%s-%s" % (version, release) sources[name]["deps"] = [] sources[name]["packages"] = [] for pak in tag.tags("Package"): packages[pak.getTagData("Name")] = name sources[name]["packages"].append(pak.getTagData("Name")) deps = tag.getTag("Source").getTag("BuildDependencies") if deps: sources[name]["deps"] = [] for dep in deps.tags("Dependency"): sources[name]["deps"].append(dep.firstChild().data()) if tag.getTag("Source").getTagData("PartOf") in [ "system.base", "system.devel" ]: base.extend(sources[name]["packages"]) return sources, packages, base
def byteCompile(filepath): doc = piksemel.parse(filepath) for item in doc.tags("File"): path = item.getTagData("Path") if path.endswith(".py"): call(["/usr/bin/python", "%s/py_compile.py" % pythonPath, "/%s" % path], stderr=PIPE, stdout=PIPE) call(["/usr/bin/python","-O", "%s/py_compile.py" % pythonPath, "/%s" % path], stderr=PIPE, stdout=PIPE)
def __add_to_revdeps(self, package, revdeps): metadata_xml = os.path.join(self.package_path(package), ctx.const.metadata_xml) try: meta_doc = piksemel.parse(metadata_xml) pkg = meta_doc.getTag("Package") except: pkg = None if pkg is None: # If package info is broken or not available, skip it. ctx.ui.warning( _("Installation info for package '%s' is broken. " "Reinstall it to fix this problem.") % package) del self.installed_db[package] return deps = pkg.getTag('RuntimeDependencies') if deps: for dep in deps.tags("Dependency"): revdep = revdeps.setdefault(dep.firstChild().data(), {}) revdep[package] = dep.toString() for anydep in deps.tags("AnyDependency"): for dep in anydep.tags("Dependency"): revdep = revdeps.setdefault(dep.firstChild().data(), {}) revdep[package] = anydep.toString()
def update_ld_so_cache(filepath): doc = piksemel.parse(filepath) for item in doc.tags("File"): path = item.getTagData("Path") if path.startswith("etc/ld.so.conf.d"): subprocess.call(["/sbin/ldconfig", "-X"]) return
def doenv(filepath): doc = piksemel.parse(filepath) for item in doc.tags("File"): path = item.getTagData("Path") if path.endswith(".so") or path.startswith("etc/env.d"): updenv = imp.load_source("updenv", "/sbin/update-environment") updenv.update_environment("/") return