Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/controlpanel/aboutxo/model.py
blob: ebbcca73b8e250d73ed69bdaf313b95263a2b97e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# Copyright (C) 2008 One Laptop Per Child
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#

import os
import logging
import re
from gettext import gettext as _

_logger = logging.getLogger('ControlPanel - AboutXO')
_not_available = _('Not available')

def get_aboutxo():        
    msg = 'Serial Number: %s \nBuild Number: %s \nFirmware Number: %s \n' \
            % (get_serial_number(), get_build_number(), get_firmware_number())
    return msg

def print_aboutxo():
    print get_aboutxo()

def get_serial_number():
    serial_no = _read_file('/ofw/serial-number')
    if serial_no is None:
        serial_no = _not_available
    return serial_no
    
def print_serial_number():
    print get_serial_number()

def get_build_number():
    build_no = _read_file('/boot/olpc_build')
    if build_no is None:
        build_no = _not_available
    return build_no

def print_build_number():
    print get_build_number()

def get_firmware_number():    
    firmware_no = _read_file('/ofw/openprom/model')
    if firmware_no is None:
        firmware_no = _not_available
    else:
        firmware_no = re.split(" +", firmware_no)
        if len(firmware_no) == 3:
            firmware_no = firmware_no[1]
    return firmware_no        

def print_firmware_number():    
    print get_firmware_number()

def _read_file(path):
    if os.access(path, os.R_OK) == 0:
        return None

    fd = open(path, 'r')
    value = fd.read()
    fd.close()
    if value:
        value = value.strip('\n')
        return value
    else:
        _logger.debug('No information in file or directory: %s' % path)
        return None

def get_license():
    license_file = "/usr/share/licenses/common-licenses/GPLv2"
    lang = os.environ['LANG']
    if lang.endswith("UTF-8"):
        lang = lang[:-6]

    try_file = license_file + "." + lang
    if os.path.isfile(try_file):
        license_file = try_file
    else:
        try_file = license_file + "." + lang.split("_")[0]
        if os.path.isfile(try_file):
            license_file = try_file

    try:
        fd = open(license_file)
        # remove 0x0c page breaks which can't be rendered in text views
        license_text = fd.read().replace('\x0c', '')
        fd.close()
    except IOError:
        license_text = _not_available
    return license_text