MythTV master
scan.py
Go to the documentation of this file.
1# smolt - Fedora hardware profiler
2#
3# Copyright (C) 2007 Mike McGrath
4# Copyright (C) 2011 Sebastian Pipping <sebastian@pipping.org>
5#
6# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 2 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program; if not, write to the Free Software
18# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19
20import smolt
21import json
22
23try:
24 from urllib2 import urlopen
25except ImportError:
26 from urllib.request import urlopen
27
28try:
29 import urlparse as parse
30except ImportError:
31 from urllib import parse
32
33from i18n import _
34from smolt_config import get_config_attr
35
36def rating(profile, smoonURL, gate):
37 print("")
38 print(_("Current rating for vendor/model."))
39 print("")
40 scanURL='%s/client/host_rating?vendor=%s&system=%s' % (smoonURL, parse.quote(profile.host.systemVendor), parse.quote(profile.host.systemModel))
41 r = json.load(urlopen(scanURL))['ratings']
42 rating_system = { '0' : _('Unrated/Unknown'),
43 '1' : _('Non-working'),
44 '2' : _('Partially-working'),
45 '3' : _('Requires 3rd party drivers'),
46 '4' : _('Works, needs additional configuration'),
47 '5' : _('Works out of the box')
48 }
49 print("\tCount\tRating")
50 print("\t-----------------")
51 for rate in r:
52 print("\t%s\t%s" % (r[rate], rating_system[rate]))
53
54def scan(profile, smoonURL, gate):
55 print(_("Scanning %s for known errata.\n" % smoonURL))
56 devices = []
57 for VendorID, DeviceID, SubsysVendorID, SubsysDeviceID, Bus, Driver, Type, Description in profile.deviceIter():
58 if VendorID:
59 devices.append('%s/%04x/%04x/%04x/%04x' % (Bus,
60 int(VendorID or 0),
61 int(DeviceID or 0),
62 int(SubsysVendorID or 0),
63 int(SubsysDeviceID or 0)) )
64 searchDevices = 'NULLPAGE'
65 devices.append('System/%s/%s' % ( parse.quote(profile.host.systemVendor), parse.quote(profile.host.systemModel) ))
66 for dev in devices:
67 searchDevices = "%s|%s" % (searchDevices, dev)
68 scanURL='%ssmolt-w/api.php' % smoonURL
69 scanData = 'action=query&titles=%s&format=json' % searchDevices
70 try:
71 r = json.load(urlopen(scanURL, bytes(scanData, 'latin1')))
72 except ValueError:
73 print("Could not wiki for errata!")
74 return
75 found = []
76
77 for page in r['query']['pages']:
78 try:
79 if int(page) > 0:
80 found.append('\t%swiki/%s' % (smoonURL, r['query']['pages'][page]['title']))
81 except KeyError:
82 pass
83
84 if found:
85 print(_("\tErrata Found!"))
86 for f in found: print("\t%s" % f)
87 else:
88 print(_("\tNo errata found, if this machine is having issues please go to"))
89 print(_("\tyour profile and create a wiki page for the device so others can"))
90 print(_("\tbenefit"))
91
92if __name__ == "__main__":
93 from gate import create_passing_gate
95 smoonURL = get_config_attr("SMOON_URL", "http://smolts.org/")
96 profile = smolt.create_profile(gate, smolt.read_uuid())
97 scan(profile, smoonURL, gate)
98 rating(profile, smoonURL, gate)
def create_passing_gate()
Definition: gate.py:91
def scan(profile, smoonURL, gate)
Definition: scan.py:54
def rating(profile, smoonURL, gate)
Definition: scan.py:36
def get_config_attr(attr, default="")
Definition: smolt_config.py:22
static void print(const QList< uint > &raw_minimas, const QList< uint > &raw_maximas, const QList< float > &minimas, const QList< float > &maximas)