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