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 
20 import smolt
21 import json, urllib
22 from i18n import _
23 from smolt_config import get_config_attr
24 
25 def rating(profile, smoonURL, gate):
26  print ""
27  print _("Current rating for vendor/model.")
28  print ""
29  scanURL='%s/client/host_rating?vendor=%s&system=%s' % (smoonURL, urllib.quote(profile.host.systemVendor), urllib.quote(profile.host.systemModel))
30  r = json.load(urllib.urlopen(scanURL))['ratings']
31  rating_system = { '0' : _('Unrated/Unknown'),
32  '1' : _('Non-working'),
33  '2' : _('Partially-working'),
34  '3' : _('Requires 3rd party drivers'),
35  '4' : _('Works, needs additional configuration'),
36  '5' : _('Works out of the box')
37  }
38  print "\tCount\tRating"
39  print "\t-----------------"
40  for rate in r:
41  print "\t%s\t%s" % (r[rate], rating_system[rate])
42 
43 def scan(profile, smoonURL, gate):
44  print _("Scanning %s for known errata.\n" % smoonURL)
45  devices = []
46  for VendorID, DeviceID, SubsysVendorID, SubsysDeviceID, Bus, Driver, Type, Description in profile.deviceIter():
47  if VendorID:
48  devices.append('%s/%04x/%04x/%04x/%04x' % (Bus,
49  int(VendorID or 0),
50  int(DeviceID or 0),
51  int(SubsysVendorID or 0),
52  int(SubsysDeviceID or 0)) )
53  searchDevices = 'NULLPAGE'
54  devices.append('System/%s/%s' % ( urllib.quote(profile.host.systemVendor), urllib.quote(profile.host.systemModel) ))
55  for dev in devices:
56  searchDevices = "%s|%s" % (searchDevices, dev)
57  scanURL='%s/smolt-w/api.php' % smoonURL
58  scanData = 'action=query&titles=%s&format=json' % searchDevices
59  try:
60  r = json.load(urllib.urlopen(scanURL, scanData))
61  except ValueError:
62  print "Could not wiki for errata!"
63  return
64  found = []
65 
66  for page in r['query']['pages']:
67  try:
68  if int(page) > 0:
69  found.append('\t%swiki/%s' % (smoonURL, r['query']['pages'][page]['title']))
70  except KeyError:
71  pass
72 
73  if found:
74  print _("\tErrata Found!")
75  for f in found: print "\t%s" % f
76  else:
77  print _("\tNo errata found, if this machine is having issues please go to")
78  print _("\tyour profile and create a wiki page for the device so others can")
79  print _("\tbenefit")
80 
81 if __name__ == "__main__":
82  from gate import create_passing_gate
84  smoonURL = get_config_attr("SMOON_URL", "http://smolts.org/")
85  profile = smolt.create_profile(gate, smolt.read_uuid())
86  scan(profile, smoonURL, gate)
87  rating(profile, smoonURL, gate)
def scan(profile, smoonURL, gate)
Definition: scan.py:43
def create_passing_gate()
Definition: gate.py:89
def rating(profile, smoonURL, gate)
Definition: scan.py:25
def get_config_attr(attr, default="")
Definition: smolt_config.py:22