Kaydet (Commit) e4d191e5 authored tarafından Suleyman Poyraz's avatar Suleyman Poyraz

write a urgent package analyzer(but not finished should fix errors) and firmwares system literal

üst 499f8463
# -*- coding: utf-8 -*-
#
# Copyright (C) 2018, Suleyman POYRAZ (Zaryob)
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# Please read the COPYING file.
#
import ciksemel
import bz2
import sys
import os
def loadFile(_file):
try:
f = open(_file)
d = [a.lstrip().rstrip("\n") for a in f]
d = [x for x in d if not (x.startswith("#") or x == "")]
f.close()
return d
except:
return []
def getXmlData(_file):
if os.path.exists(_file):
return ciksemel.parse(_file)
elif os.path.exists("%s.bz2" % _file):
indexdata = bz2.decompress(file("%s.bz2" % _file).read())
return ciksemel.parseString(indexdata)
else:
print("%s not found" % indexfile)
sys.exit(1)
def fillPackageDict(tag, _hasSpecFile, packageOf):
PackagePartOf = tag.getTagData("PartOf")
PackageName = tag.getTagData("Name")
if _hasSpecFile:
PackagePackagerName = tag.getTag("Packager").getTagData("Name")
else:
PackagePackagerName = tag.getTag("Source").getTag("Packager").getTagData("Name")
fullpath = "%s/%s" % (PackagePartOf.replace(".", "/"), PackageName)
if not PackagePackagerName in packageOf:
packageOf[PackagePackagerName] = []
packageOf[PackagePackagerName].append(fullpath)
def parseXmlData(_index):
packageOf = {}
hasSpecFile = _index.getTag("SpecFile")
if hasSpecFile:
for i in _index.tags("SpecFile"):
parent = i.getTag("Source")
fillPackageDict(parent, hasSpecFile, packageOf)
else:
for parent in _index.tags("Package"):
fillPackageDict(parent, hasSpecFile, packageOf)
return packageOf
def findRequiredPackages(packageList, packagersList):
pkgdict = {}
for pkg in packageList:
for packager in packagersList:
for sourcePackage in packagersList[packager]:
if sourcePackage.endswith("/%s" % pkg):
if not packager in pkgdict:
pkgdict[packager] = []
pkgdict[packager].append(pkg)
return pkgdict
def urgent_packages(index, packages):
indexfile = "%s/%s" % (index, "inary-index.xml")
packageList = loadFile(packages)
xmldata = getXmlData(indexfile)
packagers = parseXmlData(xmldata)
requiredPackages = findRequiredPackages(packageList, packagers)
tmp = list(requiredPackages.keys())
tmp.sort()
for i in tmp:
print("-> %s" % i)
for k in requiredPackages[i]:
print("\t%s" % k)
# -*- coding: utf-8 -*-
#
# Copyright (C) 2018, Suleyman POYRAZ (Zaryob)
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# Please read the COPYING file.
#
import os
import sys
import inary
import inary.context as ctx
import inary.util
#Gettext
import gettext
__trans = gettext.translation('inary', fallback=True)
_ = __trans.gettext
FW_PATH = "/lib/firmware"
INSTALDB = inary.db.installdb.InstallDB()
COMPONENTDB = inary.db.componentdb.ComponentDB()
class Error(inary.Error):
pass
def get_firmwares():
ctx.ui.info(inary.util.colorize("Extracting firmware list for %s..." % os.uname()[2], "green"))
d = {}
modules = [os.path.basename(mod.replace(".ko", "")) for mod in \
os.popen("modprobe -l").read().strip().split("\n")]
for mod in modules:
fws = os.popen("modinfo -F firmware %s" % mod).read().strip()
if fws:
try:
d[mod].extend(fws.split("\n"))
except KeyError:
d[mod] = fws.split("\n")
return d
def get_firmware_package(firmware):
try:
fw_packages = COMPONENTDB.get_packages("hardware.firmware")
unavailable_fw_packages = set(fw_packages).difference(INSTALLDB.list_installed())
if unavailable_fw_packages:
ctx.ui.info(inary.util.colorize("The following firmwares are not installed:", "yellow"))
ctx.ui.info("\n".join(unavailable_fw_packages))
for module, firmwares in list(get_firmwares().items()):
ctx.ui.info("\n %s requires the following firmwares:" % module)
for fw in firmwares:
ctx.ui.info(" * %s" % fw, noln = True)
try:
firmware = inary.api.search_file(fw)[0][0]
except:
pass
ctx.ui.info(" (%s)" % (inary.util.colorize(firmware, 'green') if firmware else \
inary.util.colorize("missing", 'red')))
except:
raise Error()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment