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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
# 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
import subprocess
from gettext import gettext as _
import errno
from jarabe import config
_logger = logging.getLogger('ControlPanel - AboutComputer')
_not_available = _('Not available')
def get_aboutcomputer():
msg = 'Serial Number: %s \nBuild Number: %s \nFirmware Number: %s \n' \
% (get_serial_number(), get_build_number(), get_firmware_number())
return msg
def print_aboutcomputer():
print get_aboutcomputer()
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():
serial_no = get_serial_number()
if serial_no is None:
serial_no = _not_available
print serial_no
def get_build_number():
build_no = _read_file('/boot/olpc_build')
if build_no is None:
build_no = _read_file('/etc/redhat-release')
if build_no is None:
try:
popen = subprocess.Popen(['lsb_release', '-ds'],
stdout=subprocess.PIPE)
except OSError, e:
if e.errno != errno.ENOENT:
raise
else:
build_no, stderr_ = popen.communicate()
if build_no is None or not build_no:
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 get_wireless_firmware():
try:
info = subprocess.Popen(["/usr/sbin/ethtool", "-i", "eth0"],
stdout=subprocess.PIPE).stdout.readlines()
except OSError:
return _not_available
try:
wireless_firmware = [line for line in info
if line.startswith('firmware')][0].split()[1]
except IndexError:
wireless_firmware = _not_available
return wireless_firmware
def print_wireless_firmware():
print get_wireless_firmware()
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 = os.path.join(config.data_path, '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
|