예제 #1
0
 def __init__(self, host, port):
   self.client = MozClient(host, port)
   self.root = None
   self.selected_tab = None
   self.selected_app = None
예제 #2
0
 def __init__(self, host, port):
     self.client = MozClient(host, port)
     self.root = None
     self.selected_tab = None
     self.selected_app = None
예제 #3
0
class Fireplay:
  '''
  The Fireplay main client
  '''
  # Make it on a different thread or with twisted since it is blocking at the moment
  def __init__(self, host, port):
    self.client = MozClient(host, port)
    self.root = None
    self.selected_tab = None
    self.selected_app = None

  def get_root(self, force=False):
    if not self.root or force:
      self.root = self.client.send({
        'to': 'root',
        'type': 'listTabs'
      })

    return self.root

  def get_tabs(self, force=False):
    self.get_root(force)
    return self.root['tabs']

  # TODO allow multiple tabs with multiple codebase
  def select_tab(self, tab):
    self.selected_tab = tab

  def reload_css(self):
    console = self.selected_tab['consoleActor']

    # TODO Avoid touching prototype, shrink in one call only
    self.client.send({
      'to': console,
      'type': 'evaluateJS',
      'text': FIREPLAY_CSS,
      'frameActor': None
    })

    return self.client.send({
      'to': console,
      'type': 'evaluateJS',
      'text': FIREPLAY_CSS_RELOAD,
      'frameActor': None
    })
  def get_apps(self):
    return self.client.send({
        'to': self.root["webappsActor"],
        'type':'getAll'
      })["apps"]

  def uninstall(self, manifestURL):
    self.client.send({
      'to': self.root["webappsActor"],
      'type': 'close',
      'manifestURL': manifestURL
    })
    self.client.send({
      'to': self.root["webappsActor"],
      'type': 'uninstall',
      'manifestURL': manifestURL
    })

  def launch(self, manifestURL):
    self.client.send({
      'to': self.root["webappsActor"],
      'type': 'launch',
      'manifestURL': manifestURL
    })


  def deploy(self, target_app_path, run=True, debug=False):

    webappsActor = self.root['webappsActor']
    app_manifest = get_manifest(target_app_path)[1]

    if run:
      for app in self.get_apps():
        if app['name'] == app_manifest['name']:
          self.uninstall(app['manifestURL'])

    app_id = self.install(target_app_path)

    for app in self.get_apps():
      if app['id'] == app_id:
        self.selected_app = app
        self.selected_app['local_path'] = target_app_path

    if run:
      self.launch(self.selected_app['manifestURL'])

  def install(self, target_app_path):
    webappsActor = self.root['webappsActor']

    zip_file = zip_path(target_app_path)
    app_file = open(zip_file, 'rb')
    data = app_file.read()
    file_size = len(data)

    upload_res = self.client.send({
      'to': webappsActor,
      'type': 'uploadPackage',
      'bulk': True
    })

    if 'actor' in upload_res and 'BulkActor' in upload_res['actor']:
      packageUploadActor = upload_res['actor']
      self.client.send_bulk(packageUploadActor, data)
    else: # Old B2G 1.4 and older, serialize binary data in JSON text strings (SLOW!)
      res = self.client.send({
        'to': webappsActor,
        'type':'uploadPackage'
      })
      packageUploadActor = upload_res['actor']
      chunk_size = 4*1024*1024
      bytes = 0
      while bytes < file_size:
        chunk = data[bytes:bytes+chunk_size]
        self.client.send_chunk(packageUploadActor, chunk)
        bytes += chunk_size

    app_local_id = str(uuid.uuid4())
    reply = self.client.send({
      'to': webappsActor,
      'type': 'install',
      'appId': app_local_id,
      'upload': packageUploadActor
    })
    return reply['appId']

  def inject_css(self):

    webappsActor = self.root['webappsActor']
    res = self.client.send({
      'to': webappsActor,
      'type': 'getAppActor',
      'manifestURL': self.selected_app['manifestURL']
    })

    styleSheetsActor = res['actor']['styleSheetsActor']
    res = self.client.send({
      'to': styleSheetsActor,
      'type': 'getStyleSheets'
    })

    # TODO upload all css always? this should be a setting
    for styleSheet in res['styleSheets']:
      css_file = self.selected_app['local_path'] + styleSheet['href'].replace(self.selected_app['origin'], '')
      f = open(css_file, 'r')

      self.client.send({
        'to':styleSheet['actor'],
        'type': 'update',
        'text': f.read(),
        'transition': True
      })

      # This clearly needs fixing, it is blocking. FXDEVTOOLS? new thread?
      res1 = self.client.receive()
      res2 = self.client.receive()
      res3 = self.client.receive()
예제 #4
0
class Fireplay:
    '''
    The Fireplay main client
    '''

    # TODO Blocking at the moment
    def __init__(self, host, port):
        self.client = MozClient(host, port)
        self.root = None
        self.selected_tab = None
        self.selected_app = None

    def get_root(self, force=False):
        if not self.root or force:
            self.root = self.client.send({'to': 'root', 'type': 'listTabs'})

        return self.root

    def get_tabs(self, force=False):
        self.get_root(force)
        return self.root['tabs']

    # TODO allow multiple tabs with multiple codebase
    def select_tab(self, tab):
        self.selected_tab = tab

    def reload_tab(self):
        # TODO Avoid touching prototype, shrink in one call only
        console = self.selected_tab['consoleActor']
        self.client.send({
            'to': console,
            'type': 'evaluateJS',
            'text': FIREPLAY_RELOAD,
            'frameActor': None
        })

    def reload_css(self):
        console = self.selected_tab['consoleActor']

        # TODO Avoid touching prototype, shrink in one call only
        self.client.send({
            'to': console,
            'type': 'evaluateJS',
            'text': FIREPLAY_CSS,
            'frameActor': None
        })

        return self.client.send({
            'to': console,
            'type': 'evaluateJS',
            'text': FIREPLAY_CSS_RELOAD,
            'frameActor': None
        })

    def get_apps(self):
        return self.client.send({
            'to': self.root['webappsActor'],
            'type': 'getAll'
        })['apps']

    def uninstall(self, manifestURL):
        self.client.send({
            'to': self.root['webappsActor'],
            'type': 'close',
            'manifestURL': manifestURL
        })
        self.client.send({
            'to': self.root['webappsActor'],
            'type': 'uninstall',
            'manifestURL': manifestURL
        })

    def launch(self, manifestURL):
        self.client.send({
            'to': self.root['webappsActor'],
            'type': 'launch',
            'manifestURL': manifestURL
        })

    def deploy(self, target_app_path, run=True, debug=False):
        app_manifest = get_manifest(target_app_path)[1]

        if run:
            for app in self.get_apps():
                if app['name'] == app_manifest['name']:
                    self.uninstall(app['manifestURL'])

        app_id = self.install(target_app_path)

        for app in self.get_apps():
            if app['id'] == app_id:
                self.selected_app = app
                self.selected_app['local_path'] = target_app_path

        if run:
            self.launch(self.selected_app['manifestURL'])

    def install(self, target_app_path):
        webappsActor = self.root['webappsActor']

        zip_file = zip_path(target_app_path)
        app_file = open(zip_file, 'rb')
        data = app_file.read()
        file_size = len(data)

        upload_res = self.client.send({
            'to': webappsActor,
            'type': 'uploadPackage',
            'bulk': True
        })

        if 'actor' in upload_res and 'BulkActor' in upload_res['actor']:
            packageUploadActor = upload_res['actor']
            self.client.send_bulk(packageUploadActor, data)
        else:
            # Old B2G 1.4 and older
            self.client.send({'to': webappsActor, 'type': 'uploadPackage'})
            packageUploadActor = upload_res['actor']
            chunk_size = 4 * 1024 * 1024
            bytes = 0
            while bytes < file_size:
                chunk = data[bytes:bytes + chunk_size]
                self.client.send_chunk(packageUploadActor, chunk)
                bytes += chunk_size

        app_local_id = str(uuid.uuid4())
        reply = self.client.send({
            'to': webappsActor,
            'type': 'install',
            'appId': app_local_id,
            'upload': packageUploadActor
        })
        return reply['appId']

    def inject_css(self):

        webappsActor = self.root['webappsActor']
        res = self.client.send({
            'to': webappsActor,
            'type': 'getAppActor',
            'manifestURL': self.selected_app['manifestURL']
        })

        styleSheetsActor = res['actor']['styleSheetsActor']
        res = self.client.send({
            'to': styleSheetsActor,
            'type': 'getStyleSheets'
        })

        # TODO upload all css always? this should be a setting
        for styleSheet in res['styleSheets']:
            base_path = self.selected_app['local_path']
            manifest_path = self.selected_app['origin']
            css_path = styleSheet['href']
            css_file = base_path + css_path.replace(manifest_path, '')
            f = open(css_file, 'r')

            self.client.send({
                'to': styleSheet['actor'],
                'type': 'update',
                'text': f.read(),
                'transition': True
            })

            # TODO it is blocking. FXDEVTOOLS? new thread?
            self.client.receive()
            self.client.receive()
            self.client.receive()