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