Advertisement
Guest User

blah2

a guest
Jan 16th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.62 KB | None | 0 0
  1. import glob
  2. import os, sys
  3. import subprocess
  4.  
  5. from pciids import *
  6.  
  7. class SYSfs:
  8.     def __init__(self):
  9.         self.pci = PCI()
  10.         self.modules = Modules()
  11.  
  12. def rF(p,f):
  13.     if os.path.isfile("%s/%s" % (p,f)):
  14.         return open("%s/%s" % (p,f)).readline().replace("0x","").strip()
  15.     else:
  16.         return ""
  17.  
  18. class Device:
  19.     def __init__(self,p):
  20.         self.path = p
  21.         self.vendor = rF(p,"vendor")
  22.         self.device = rF(p,"device")
  23.         self.subdevice = "%s:%s" % (rF(p,"subsystem_vendor") , rF(p,"subsystem_device"))
  24.         print pciids.deviceStr(self.vendor, self.device, self.subdevice)
  25.  
  26. class PCI:
  27.     def __init__(self):
  28.         self.path = "/sys/bus/pci/devices/0*"
  29.         self.devices = {}
  30.         self.inspect()
  31.  
  32.     def inspect(self):
  33.         devPaths = glob.glob(self.path)
  34.         for dp in devPaths:
  35.             self.devices[dp] = Device(dp)
  36.  
  37. #rfcomm                 58009  4
  38. class Module:
  39.     def __init__(self, line):
  40.         parse = line.split()
  41.         self.name = parse[0]
  42.         self.size = int(parse[1])
  43.         self.usedBy = int(parse[2])
  44.         self.uses = []
  45.         for u in parse[3:]:
  46.             self.uses.append(u)
  47.  
  48.         print self.name
  49.         for u in self.uses:
  50.             print "  ", u
  51.  
  52. class Modules:
  53.     def __init__(self):
  54.         self.modules = {}
  55.         proc = subprocess.Popen(["lsmod"], shell=True, stdout=subprocess.PIPE)
  56.         out = proc.communicate()[0].splitlines()
  57.         for l in out[1:]:
  58.             name = l.split()[0]
  59.             self.modules[name] = Module(l)
  60.  
  61. if (__name__ == "__main__"):
  62.     s = SYSfs()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement