Ticket #3337: get_xo_serial.patch

File get_xo_serial.patch, 1.6 KB (added by earias, 12 years ago)
  • src/jarabe/journal/misc.py

    diff -u -r -N sugar-0.94.1.orig/src/jarabe/journal/misc.py sugar-0.94.1/src/jarabe/journal/misc.py
    old new  
    11# Copyright (C) 2007, One Laptop Per Child
    22# Copyright (C) 2010, Paraguay Educa <tecnologia@paraguayeduca.org>
     3# Copyright (C) 2012, Plan Ceibal <comunidad@plan.ceibal.edu.uy>
    34#
    45# This program is free software; you can redistribute it and/or modify
    56# it under the terms of the GNU General Public License as published by
     
    323324    return serial_number
    324325
    325326def get_xo_serial():
    326     path = '/ofw/serial-number'
     327    _ofw_serial = '/ofw/serial-number'
     328    _proc_serial = '/proc/device-tree/serial-number'
    327329
     330    serial = None
     331    if os.path.exists(_ofw_serial):
     332        serial = read_file(_ofw_serial)
     333    elif os.path.exists(_proc_serial):
     334        serial = read_file(_proc_serial)
     335    return serial
     336       
     337def read_file(path):
    328338    if os.access(path, os.R_OK) == 0:
    329339        return None
    330340
    331     file_descriptor = open(path, 'r')
    332     content = file_descriptor.read()
    333     file_descriptor.close()
    334 
    335     if content:
    336         return content.strip()
     341    fd = open(path, 'r')
     342    value = fd.read()
     343    fd.close()
     344    if value:
     345        value = value.strip('\n')
     346        return value
    337347    else:
    338         logging.error('No serial number at %s', path)
    339348        return None
    340349
     350
    341351def get_nick():
    342352    client = gconf.client_get_default()
    343353    return client.get_string("/desktop/sugar/user/nick")