-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcrapshoot
executable file
·83 lines (71 loc) · 2.63 KB
/
crapshoot
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python2.7
#
# crapshoot - testing driver management
#
# Copyright 2017 Ikey Doherty <[email protected]>
#
# 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.
#
from doflicky import OSContext
from doflicky.driver.nvidia import DriverBundleNvidia
from doflicky.driver.broadcom import DriverBundleBroadcom
import pisi
from pisi.db.installdb import InstallDB
class BundleSet:
drivers = None
allDrivers = None
uniqueDrivers = None
emul32Triggers = None
db = None
context = None
def __init__(self):
""" Initialise the potential driver bundle set """
self.drivers = [
DriverBundleNvidia(),
DriverBundleBroadcom(),
]
self.allDrivers = list()
self.uniqueDrivers = list()
self.emul32Triggers = dict()
self.context = OSContext()
self.db = InstallDB()
for driver in self.drivers:
for pkg in driver.triggers_emul32():
if self.db.has_package(pkg):
self.emul32Triggers[driver] = True
def detect(self):
""" Perform main detection routine """
for driver in self.drivers:
if driver.is_present():
self.add_driver(driver)
def add_driver(self, driver):
""" Attempt to add a driver to the set and avoid conflicts """
base = driver.get_base()
self.allDrivers.append(driver)
if base is not None:
otherDrivers = [x for x in self.uniqueDrivers if x.get_base() == base]
for existing in otherDrivers:
if existing.get_priority() > driver:
print("DEBUG: {} shadowed by existing {}".format(
driver.get_name(), existing.get_name()))
return
elif driver.get_priority() > existing.get_priority():
self.uniqueDrivers.remove(existing)
self.uniqueDrivers.append(driver)
if len(otherDrivers) < 1:
self.uniqueDrivers.append(driver)
else:
self.uniqueDrivers.append(driver)
if __name__ == "__main__":
bs = BundleSet()
bs.detect()
for driver in bs.uniqueDrivers:
print("Found supported hardware: %s" % driver.get_name())
emul32 = False
if driver in bs.emul32Triggers:
emul32 = True
pkgs = driver.get_packages(bs.context, emul32)
print("Packages: %s" % ", ".join(pkgs))