2 # Authors: Nicholas Alexander && Otacilio Lacerda
7 BATTERY = os.environ['BATTERY_PATH'] + 'battery.py'
11 def queryProductInformation(deviceIp):
12 """ Update device name by getting device product name and os version
15 Use osso-product-info command to get the device and device OS short
16 names and set each to it correspondent attribute.
20 info = commands.getoutput("ssh -l %s %s osso-product-info" %
21 (USER_HOST, deviceIp))
23 deviceName = _extractOssoInfo(info, "shortName")
24 deviceOs = _extractOssoInfo(info, "shortOS")
25 ossoVersion = _extractOssoInfo(info, "ossoVersion")
26 if deviceName != -1 and deviceOs != -1:
27 deviceName = deviceName.strip("'")
28 deviceOs = deviceOs.strip("'")
30 deviceName = "NO INFORMATION"
31 deviceOs = "NO INFORMATION"
33 return (deviceName, deviceOs, ossoVersion)
35 def queryDeviceStorage(deviceIp):
36 """Returns a list of tuples, each tuple representing a memory status.
38 Tuples are in this format: (total, used)
41 mem_infos -- List with all tuples holding memory info
44 info = commands.getoutput("ssh -l root %s df" %
45 deviceIp).splitlines()
46 mem_infos = [-1, -1, -1]
48 if line.find("/dev/mtdblock4") != -1:
50 total_used = _get_memory(line, "/dev/mtdblock4")
52 mem_infos.insert(0, total_used)
54 elif line.find("/media/mmc1") != -1:
55 total_used = _get_memory(line, "/dev/mmcblk0p1")
57 mem_infos.insert(1, total_used)
59 elif line.find("/media/mmc2") != -1:
60 total_used = _get_memory(line, "/dev/mmcblk1p1")
62 mem_infos.insert(2, total_used)
66 def queryDeviceBattery(deviceIp):
67 """Return device current battery status in a string.
69 This method runs a python script in the device that returns the battery
70 status, this status is represented by one string with the percentage of
71 battery current charge or the number -1 case battery is charging.
74 text -- Text with the battery status
78 # Calls script that returns device battery status
79 os.system("scp %s %s@%s:/tmp" % (BATTERY, USER_HOST, deviceIp))
80 battery_status = commands.getoutput("ssh -l %s %s /usr/bin/python \
81 /tmp/battery.py" % (USER_HOST,
85 def _get_memory(line, path):
86 """Retrieve and return total and used memory information from the given
87 line using the memory path to retrieve the right information.
89 This function is to be used with a line of the return of a df command.
92 line -- The line where the memory information is
93 path -- The path in the begining of the line
97 used -- Amount of used memory
102 while number_of_infos < 2:
106 end = line.find(" ", start + 1)
107 if number_of_infos == 0:
108 total = line[start: end]
109 elif number_of_infos == 1:
110 used = line[start: end]
116 def _extractOssoInfo(osso_string, info_type="name"):
117 """Read the osso-product-info command return string and extract the
118 needed info depeding on info_type argument.
121 osso_string -- The string returned by osso-product-info command
122 info_type -- the kind of information to b extracted, can be:
123 name - returns device full name (default)
124 OS - returns device OS full name
125 shortName - returns device short name
126 shortOS - returns device short OS name
129 info -- String with the needed information
130 -1 -- Case the information couldn't be found in the given string
134 if info_type == "shortName":
135 detailed_type = "OSSO_PRODUCT_NAME"
136 elif info_type == "shortOS":
137 detailed_type = "OSSO_PRODUCT_RELEASE_NAME"
138 elif info_type == "name":
139 detailed_type = "OSSO_PRODUCT_FULL_NAME"
140 elif info_type == "OS":
141 detailed_type = "OSSO_PRODUCT_RELEASE_FULL_NAME"
142 elif info_type == "ossoVersion":
143 detailed_type = "OSSO_VERSION"
145 detailed_type = "OSSO_PRODUCT_FULL_NAME"
147 types_list = osso_string.splitlines()
149 for type_line in types_list:
150 if type_line.startswith(detailed_type):
151 # The second argument is the information itself since informations
152 # are displayed like: OSSO_PRODUCT_RELEASE_NAME='OS 2008'
153 info = type_line.split("=")[1]