def install_pygtk(): """A temporary dirty hack of installing pygtk related packages.""" pygtk_dict = {'x86_64': ['pygtk_x86_64.tbz2', 'lib64'], 'i686': ['pygtk_x86_32.tbz2', 'lib'], 'armv7l': ['pygtk_armv7l.tbz2', 'lib'], } pygtk_info = pygtk_dict.get(get_cpu().lower()) if get_board() is None: print 'This does not look like a chromebook.' elif pygtk_info: cmd_remount = 'mount -o remount,rw /' if common_util.simple_system(cmd_remount) == 0: pygtk_tarball, lib_path = pygtk_info cmd_untar = 'tar -jxf pygtk/%s -C /' % pygtk_tarball if common_util.simple_system(cmd_untar) == 0: # Need to add the gtk path manually. Otherwise, the path # may not be in the sys.path for the first time when the # tarball is extracted. gtk_path = ('/usr/local/%s/python2.7/site-packages/gtk-2.0' % lib_path) sys.path.append(gtk_path) print 'Successful installation of pygtk.' return True else: print 'Error: Failed to install pygtk.' else: print 'Failed to remount. Have you removed the write protect?' else: print 'The pygtk is only supported for %s so far.' % pygtk_dict.keys() print 'The other cpus will be supported on demand.' print 'The plan is to remove gtk totally and upgrade to Chrome browser.' return False
def dump_window(self, filename): """Dump the screenshot of a window to the specified file name.""" win_id = self._get_win_id() if win_id: dump_cmd = self.dump_window_format % (win_id, filename) common_util.simple_system(dump_cmd) else: print 'Warning: cannot get the window id.'
def upload(self, data, bucket_dir=''): """Upload the data to the chosen bucket.""" if not bucket_dir: bucket_dir = self.default_bucket_dir cp_flag = '-R' if os.path.isdir(data) else '' simple_system(self.upload_cmd % (cp_flag, data, bucket_dir)) msg = '\nGesture event files have been uploaded to "%s"\n' data_dir = os.path.basename(data) print msg % os.path.join(self.bucket, bucket_dir, data_dir)
def stop(self): """Close the file.""" with open(self.html_filename, 'w') as report_file: report_file.write(self.doc.get_doc(self.test_version)) # Make a copy to /tmp so that it could be viewed in Chrome. tmp_copy = os.path.join(conf.docroot, os.path.basename(self.html_filename)) copy_cmd = 'cp %s %s' % (self.html_filename, tmp_copy) common_util.simple_system(copy_cmd) # Dump the logs to a byte stream file log_file_root = os.path.splitext(self.html_filename)[0] log_filename = os.extsep.join([log_file_root, 'log']) self.rlog.dump(log_filename)
def start_power_management(): """Start the power daemon management.""" ret_d = common_util.simple_system('start -q powerd') if ret_d: print 'Error in starting powerd.' print 'The screen may not go into suspend mode.' print 'If this is a problem, you could reboot the machine.'
def _execute_control_command(self, control_cmd): """Execute a control command.""" print 'Executing: "%s"' % control_cmd if self.is_robot_action_mode(): # Pausing to give everything time to settle time.sleep(0.5) return common_util.simple_system(control_cmd) return 0
def generate_mtplot_image_from_log(device_node, mtplot_file): """Convert the mtplot file to evemu format, and play it with evemu-play. @param device_node: the touch device node on which to play the mtplot_file @param mtplot_file: a device file in mtplot format """ # Convert the mtplot file to evemu file. evemu_file = mtb.convert_mtplot_file_to_evemu_file(mtplot_file, evemu_dir='/tmp', force=True) if not evemu_file: msg = 'Error to convert data from mtplot format to evemu format: %s' print msg % mtplot_file return # Launch mtplot in order to capture the image. mtplot_cmd = 'mtplot -d :0 %s' % device_node devnull = open(os.devnull, 'w') proc = subprocess.Popen(mtplot_cmd.split(), stdout=devnull) play_cmd = 'evemu-play --insert-slot0 %s < %s' % (device_node, evemu_file) print 'Executing: %s\n' % play_cmd simple_system(play_cmd) # evemu_file looks like drumroll.fast-link-fw_1.0-robot-20130829.evemu.dat # image_file looks like drumroll.fast-link-fw_1.0-robot-20130829 image_file = evemu_file.rsplit('.', 2)[0] # Dump the screen shot to the image file. width, height = SimpleX('aura').get_screen_size() geometry_str = '%dx%d+%d+%d' % (width, height, 0, 0) ScreenShot(geometry_str).dump_root(image_file) # Terminate mtplot. proc.poll() if proc.returncode is None: proc.terminate() proc.wait() devnull.close() print 'Files saved:' print 'The evemu file: %s' % evemu_file print 'The mtplot image file: %s\n' % image_file
def download_and_install_gsutil(): """Download and install gsutil package.""" if not os.path.isdir(GSUTIL_PATH): print 'Installing %s ...' % GSUTIL # Download the gsutil tarball to a temporary directory temp_dir = tempfile.mkdtemp() gsutil_temp_file = os.path.join(temp_dir, GSUTIL_TAR_NAME) print ' Downloading gsutil tarball: "%s".' % GSUTIL_URI file_utils.download_file(GSUTIL_URI, gsutil_temp_file) # Untar the gsutil tarball untar_cmd_str = 'tar xf %s -C %s' untar_cmd = untar_cmd_str % (gsutil_temp_file, GSUTIL_INSTALL_DIR) print ' Untarring the gsutil tarball.' simple_system(untar_cmd) # Remove the tarball and the temp directory shutil.rmtree(temp_dir) # Set the PATH environment variable for gsutil PATH = os.environ['PATH'] os.environ['PATH'] = ':'.join([GSUTIL_PATH, PATH])
def rmdir(self, data_dir): """Remove all files in the data directory.""" simple_system(self.rm_cmd % os.path.join(data_dir, '*'))
def rm(self, single_file): """Remove single_file.""" simple_system(self.rm_cmd % single_file)
def ls(self, files=''): """ls the files in the selected bucket.""" simple_system(self.ls_cmd % files)
def dump_root(self, filename): """Dump the screenshot of root to the specified file name.""" dump_cmd = self.dump_root_format % (self.geometry_str, filename) common_util.simple_system(dump_cmd)
def stop_power_management(): """Stop the power daemon management.""" ret_d = common_util.simple_system('stop -q powerd') if ret_d: print 'Error in stopping powerd.' print 'The screen may dim during the test.'
def _execute_noise_command(self, noise_cmd): if self.is_robot_action_mode() or self.is_manual_noise_test_mode(): return common_util.simple_system(noise_cmd)
def turn_off_noise(self): off_cmd = 'python %s OFF' % self._noise_script_dir common_util.simple_system(off_cmd)