Skip to content

Commit

Permalink
Minor Smolt fixes.
Browse files Browse the repository at this point in the history
Replace external 'simplejson' with internal 'json' to remove external
dependency.

Fix detection of system memory for Linux 3.x.
  • Loading branch information
wagnerrp committed Feb 17, 2012
1 parent 8f9a9b1 commit bb154a8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
4 changes: 2 additions & 2 deletions mythtv/programs/scripts/hardwareprofile/getLink.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from optparse import OptionParser
from urlparse import urljoin
import urlgrabber.grabber
import simplejson
import json

sys.path.append('/usr/share/smolt/client')

Expand Down Expand Up @@ -76,7 +76,7 @@ def main():
pub_uuid_str = pub_uuid_fli.read()
try:
try:
pub_uuid_obj = simplejson.loads(pub_uuid_str)
pub_uuid_obj = json.loads(pub_uuid_str)
print _('To view your profile visit: %s') % smolt.get_profile_link(opts.smoonURL, pub_uuid_obj["pub_uuid"])
except ValueError, e:
error(_('Something went wrong fetching the public UUID'))
Expand Down
6 changes: 3 additions & 3 deletions mythtv/programs/scripts/hardwareprofile/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.

import smolt
import simplejson, urllib
import json, urllib
from i18n import _
from smolt_config import get_config_attr

Expand All @@ -27,7 +27,7 @@ def rating(profile, smoonURL, gate):
print _("Current rating for vendor/model.")
print ""
scanURL='%s/client/host_rating?vendor=%s&system=%s' % (smoonURL, urllib.quote(profile.host.systemVendor), urllib.quote(profile.host.systemModel))
r = simplejson.load(urllib.urlopen(scanURL))['ratings']
r = json.load(urllib.urlopen(scanURL))['ratings']
rating_system = { '0' : _('Unrated/Unknown'),
'1' : _('Non-working'),
'2' : _('Partially-working'),
Expand Down Expand Up @@ -57,7 +57,7 @@ def scan(profile, smoonURL, gate):
scanURL='%s/smolt-w/api.php' % smoonURL
scanData = 'action=query&titles=%s&format=json' % searchDevices
try:
r = simplejson.load(urllib.urlopen(scanURL, scanData))
r = json.load(urllib.urlopen(scanURL, scanData))
except ValueError:
print "Could not wiki for errata!"
return
Expand Down
16 changes: 9 additions & 7 deletions mythtv/programs/scripts/hardwareprofile/smolt.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
from urlparse import urlparse
from urllib import urlencode
import urllib
import simplejson
from simplejson import JSONEncoder, JSONDecodeError
import json
from json import JSONEncoder
import datetime
import logging

Expand Down Expand Up @@ -672,7 +672,7 @@ def serialize(object, human=False):
tok_str = token.read()
try:
try:
tok_obj = simplejson.loads(tok_str)
tok_obj = json.loads(tok_str)
if tok_obj['prefered_protocol'] in supported_protocols:
prefered_protocol = tok_obj['prefered_protocol']
else:
Expand Down Expand Up @@ -760,7 +760,7 @@ def serialize(object, human=False):
error(_('An error has occured while contacting the server: %s' % e))
sys.exit(1)
admin_str = admin_token.read()
admin_obj = simplejson.loads(admin_str)
admin_obj = json.loads(admin_str)
if admin_obj['prefered_protocol'] in supported_protocols:
prefered_protocol = admin_obj['prefered_protocol']
else:
Expand All @@ -781,8 +781,8 @@ def regenerate_pub_uuid(self, uuiddb, uuid, user_agent=user_agent, smoonURL=smoo

response = new_uuid.read() # Either JSON or an error page in (X)HTML
try:
response_dict = simplejson.loads(response)
except JSONDecodeError, e:
response_dict = json.loads(response)
except Exception, e:
serverMessage(response)
raise ServerError, _('Reply from server could not be interpreted')
else:
Expand Down Expand Up @@ -1176,6 +1176,8 @@ def get_entry(a, entry):
def read_memory():
un = os.uname()
kernel = un[2]
if kernel[:2] == "3.":
return read_memory_2_6()
if kernel[:3] == "2.6":
return read_memory_2_6()
if kernel[:3] == "2.4":
Expand Down Expand Up @@ -1281,7 +1283,7 @@ def read_pub_uuid(uuiddb, uuid, user_agent=user_agent, smoonURL=smoonURL, timeou
grabber = urlgrabber.grabber.URLGrabber(user_agent=user_agent, timeout=timeout, proxies=proxies)
try:
o = grabber.urlopen(urljoin(smoonURL + "/", '/client/pub_uuid/%s' % uuid))
pudict = simplejson.loads(o.read())
pudict = json.loads(o.read())
o.close()
uuiddb.set_pub_uuid(uuid, smoonURLparsed[1], pudict["pub_uuid"])
return pudict["pub_uuid"]
Expand Down

0 comments on commit bb154a8

Please sign in to comment.