Rtos API example

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers module_copy_firefox.py Source File

module_copy_firefox.py

00001 """
00002 mbed SDK
00003 Copyright (c) 2011-2013 ARM Limited
00004 
00005 Licensed under the Apache License, Version 2.0 (the "License");
00006 you may not use this file except in compliance with the License.
00007 You may obtain a copy of the License at
00008 
00009     http://www.apache.org/licenses/LICENSE-2.0
00010 
00011 Unless required by applicable law or agreed to in writing, software
00012 distributed under the License is distributed on an "AS IS" BASIS,
00013 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014 See the License for the specific language governing permissions and
00015 limitations under the License.
00016 """
00017 
00018 from os.path import join, basename
00019 from host_test_plugins import HostTestPluginBase
00020 
00021 
00022 class HostTestPluginCopyMethod_Firefox(HostTestPluginBase):
00023 
00024     def file_store_firefox(self, file_path, dest_disk):
00025         try:
00026             from selenium import webdriver
00027             profile = webdriver.FirefoxProfile()
00028             profile.set_preference('browser.download.folderList', 2) # custom location
00029             profile.set_preference('browser.download.manager.showWhenStarting', False)
00030             profile.set_preference('browser.download.dir', dest_disk)
00031             profile.set_preference('browser.helperApps.neverAsk.saveToDisk', 'application/octet-stream')
00032             # Launch browser with profile and get file
00033             browser = webdriver.Firefox(profile)
00034             browser.get(file_path)
00035             browser.close()
00036         except:
00037             return False
00038         return True
00039 
00040     # Plugin interface
00041     name = 'HostTestPluginCopyMethod_Firefox'
00042     type = 'CopyMethod'
00043     capabilities = ['firefox']
00044     required_parameters = ['image_path', 'destination_disk']
00045 
00046     def setup(self, *args, **kwargs):
00047         """ Configure plugin, this function should be called before plugin execute() method is used.
00048         """
00049         try:
00050             from selenium import webdriver
00051         except ImportError, e:
00052             self.print_plugin_error("Error: firefox copy method requires selenium library. %s"% e)
00053             return False
00054         return True
00055 
00056     def execute(self, capabilitity, *args, **kwargs):
00057         """ Executes capability by name.
00058             Each capability may directly just call some command line
00059             program or execute building pythonic function
00060         """
00061         result = False
00062         if self.check_parameters(capabilitity, *args, **kwargs) is True:
00063             image_path = kwargs['image_path']
00064             destination_disk = kwargs['destination_disk']
00065             # Prepare correct command line parameter values
00066             image_base_name = basename(image_path)
00067             destination_path = join(destination_disk, image_base_name)
00068             if capabilitity == 'firefox':
00069                 self.file_store_firefox(image_path, destination_path)
00070         return result
00071 
00072 
00073 def load_plugin ():
00074     """ Returns plugin available in this module
00075     """
00076     return HostTestPluginCopyMethod_Firefox()