add new output for a specific MAVLink sysID
166164
def cmd_output_sysid(self, args):
        ''''''
        sysid = int(args[0])
        device = args[1]
        print("Adding output %s for sysid %u" % (device, sysid))
        try:
            conn = mavutil.mavlink_connection(device, input=False, source_system=self.settings.source_system)
            conn.mav.srcComponent = self.settings.source_component
        except Exception:
            print("Failed to connect to %s" % device)
            return
        try:
            mp_util.child_fd_list_add(conn.port.fileno())
        except Exception:
            pass
        if sysid in self.mpstate.sysid_outputs:
            self.mpstate.sysid_outputs[sysid].close()
        self.mpstate.sysid_outputs[sysid] = conn
701673
def capture_output(self, with_hook=True):
        """"""
        self.hooked = ''

        def display_hook(obj):
            # That's some dirty hack
            self.hooked += self.safe_better_repr(obj)
            self.last_obj = obj

        stdout, stderr = sys.stdout, sys.stderr
        if with_hook:
            d_hook = sys.displayhook
            sys.displayhook = display_hook

        sys.stdout, sys.stderr = StringIO(), StringIO()
        out, err = [], []
        try:
            yield out, err
        finally:
            out.extend(sys.stdout.getvalue().splitlines())
            err.extend(sys.stderr.getvalue().splitlines())
            if with_hook:
                sys.displayhook = d_hook

            sys.stdout, sys.stderr = stdout, stderr
1140103
def update(driver_name, outputdir, version=None):
    
    platform = helpers.get_platform()
    driver_name = helpers.normalize_driver_name(driver_name)
    driver_class = helpers.get_driver_class(driver_name)
    driver = driver_class(outputdir, platform['os_name'], platform['os_bits'])
    if version:
        driver.download_driver_executable(version=version)
    elif driver.is_remote_higher_than_local():
        latest_remote_version = driver.get_latest_remote_version()
        driver.download_driver_executable(version=latest_remote_version)
    else:
        logger.info('{} is up to date'.format(driver_name))
300141
def write(self, outfilename=None):
        """"""
        outfilename = outfilename or self.filename
        if not outfilename:
            raise ValueError('Unable to write MAK file without a filename')
        with codecs.open(outfilename, 'wb', 'windows-1252') as outf:
            outf.write('\r\n'.join(self._serialize()))
463877
def mavlink_packet(self, m):
        ''''''
        if m.get_type() == 'PPP' and self.ppp_fd != -1:
            print("got ppp mavlink pkt len=%u" % m.length)
            os.write(self.ppp_fd, m.data[:m.length])
294571
def mavparms(logfile):
    ''''''
    mlog = mavutil.mavlink_connection(filename)

    while True:
        try:
            m = mlog.recv_match(type=['PARAM_VALUE', 'PARM'])
            if m is None:
                return
        except Exception:
            return
        if m.get_type() == 'PARAM_VALUE':
            pname = str(m.param_id).strip()
            value = m.param_value
        else:
            pname = m.Name
            value = m.Value
        if len(pname) > 0:
            if args.changesOnly is True and pname in parms and parms[pname] != value:
                print("%s %-15s %.6f -> %.6f" % (time.asctime(time.localtime(m._timestamp)), pname, parms[pname], value))

            parms[pname] = value
798055
def symlink(source, destination):
    """"""
    log("Symlinking {} as {}".format(source, destination))
    cmd = [
        'ln',
        '-sf',
        source,
        destination,
    ]
    subprocess.check_call(cmd)
1153001
def create_symlinks(d):
    """"""
    data = loadJson(d)
    outDir = prepare_output(d)

    unseen = data["pages"].keys()
    while len(unseen) > 0:
        latest = work = unseen[0]
        while work in unseen:
            unseen.remove(work)
            if "prev" in data["pages"][work]:
                work = data["pages"][work]["prev"]
    print("Latest page: %s" % (latest))

    order = []
    work = latest
    while work in data["pages"]:
        order.extend(data["pages"][work]["images"].values())
        if "prev" in data["pages"][work]:
            work = data["pages"][work]["prev"]
        else:
            work = None
    order.reverse()

    for i, img in enumerate(order):
        os.symlink(os.path.join('..', img), os.path.join(outDir, '%05i_%s' % (i, img)))
194582
def add_new_data_port(self):
        """"""
        try:
            new_data_port_ids = gui_helper_state_machine.add_data_port_to_selected_states('OUTPUT', int, [self.model])
            if new_data_port_ids:
                self.select_entry(new_data_port_ids[self.model.state])
        except ValueError:
            pass
46332
def mavlink_packet(self, m):
        ''''''
        if m.get_type() == 'SERIAL_CONTROL':
            data = m.data[:m.count]
            if m.count > 0:
                s = ''.join(str(chr(x)) for x in data)
                if self.mpstate.system == 'Windows':
                    # strip nsh ansi codes
                    s = s.replace("\033[K","")
                sys.stdout.write(s)
                self.last_packet = time.time()
37182
def add_output(self, line):
        
        Deployment.objects.filter(pk=self.id).update(output=CF('output')+line)
433564
def _add_output(self, out):
        
        self._outputs += [out]
        out.node = self
        out._set_as_output_of(self)
696690
def _add_interface(self, interface_id, mgt=None, **kw):
        
        _kw = copy.deepcopy(kw) # Preserve original kw, especially lists
        mgt = mgt if mgt else {}
        
        if 'cvi_mode' in _kw:
            self.data.update(cvi_mode=_kw.pop('cvi_mode'))
        
        if 'macaddress' in _kw:
            self.data.update(
                macaddress=_kw.pop('macaddress'))
            if 'cvi_mode' not in self.data:
                self.data.update(cvi_mode='packetdispatch')
        
        if 'zone_ref' in _kw:
            zone_ref = _kw.pop('zone_ref')
            self.data.update(zone_ref=zone_helper(zone_ref) if zone_ref else None)
        
        if 'comment' in _kw:
            self.data.update(comment=_kw.pop('comment'))

        interfaces = _kw.pop('interfaces', [])
        for interface in interfaces:
            vlan_id = interface.pop('vlan_id', None)
            if vlan_id:
                _interface_id = '{}.{}'.format(interface_id, vlan_id)
            else:
                _interface_id = interface_id
    
            _interface = []
            if_mgt = {k: str(v) == str(_interface_id) for k, v in mgt.items()}
            
            if 'cluster_virtual' in interface and 'network_value' in interface:
                cluster_virtual = interface.pop('cluster_virtual')
                network_value = interface.pop('network_value')
                if cluster_virtual and network_value:
                    cvi = ClusterVirtualInterface.create(
                        _interface_id, cluster_virtual, network_value,
                        auth_request=True if if_mgt.get('primary_mgt') else False)
                      
                    _interface.append({cvi.typeof: cvi.data})
    
            for node in interface.pop('nodes', []):
                _node = if_mgt.copy()
                _node.update(outgoing=True if if_mgt.get('primary_mgt') else False)
                # Add node specific key/value pairs set on the node. This can
                # also be used to override management settings
                _node.update(node)
                ndi = NodeInterface.create(
                    interface_id=_interface_id, **_node)
                _interface.append({ndi.typeof: ndi.data})

            if vlan_id:
                vlan_interface = {
                    'interface_id': _interface_id,
                    'zone_ref': zone_helper(interface.pop('zone_ref', None)),
                    'comment': interface.pop('comment', None),
                    'interfaces': _interface}
                # Add remaining kwargs on vlan level to VLAN physical interface
                for name, value in interface.items():
                    vlan_interface[name] = value
                self.data.setdefault('vlanInterfaces', []).append(
                    vlan_interface)
            else:
                self.data.setdefault('interfaces', []).extend(
                    _interface)

        # Remaining kw go to base level interface
        for name, value in _kw.items():
            self.data[name] = value
1331285
def auto_mavlink_version(self, buf):
        ''''''
        global mavlink
        if len(buf) == 0:
            return
        try:
            magic = ord(buf[0])
        except:
            magic = buf[0]
        if not magic in [ 85, 254, 253 ]:
            return
        self.first_byte = False
        if self.WIRE_PROTOCOL_VERSION == "0.9" and magic == 254:
            self.WIRE_PROTOCOL_VERSION = "1.0"
            set_dialect(current_dialect)
        elif self.WIRE_PROTOCOL_VERSION == "1.0" and magic == 85:
            self.WIRE_PROTOCOL_VERSION = "0.9"
            os.environ['MAVLINK09'] = '1'
            set_dialect(current_dialect)
        elif self.WIRE_PROTOCOL_VERSION != "2.0" and magic == 253:
            self.WIRE_PROTOCOL_VERSION = "2.0"
            os.environ['MAVLINK20'] = '1'
            set_dialect(current_dialect)
        else:
            return
        # switch protocol 
        (callback, callback_args, callback_kwargs) = (self.mav.callback,
                                                      self.mav.callback_args,
                                                      self.mav.callback_kwargs)
        self.mav = mavlink.MAVLink(self, srcSystem=self.source_system)
        self.mav.robust_parsing = self.robust_parsing
        self.WIRE_PROTOCOL_VERSION = mavlink.WIRE_PROTOCOL_VERSION
        (self.mav.callback, self.mav.callback_args, self.mav.callback_kwargs) = (callback,
                                                                                 callback_args,
                                                                                 callback_kwargs)
191130
def mavlink_packet(self, m):
        ''''''
        if m.get_type() == 'SERIAL_CONTROL':
            data = m.data[:m.count]
            s = ''.join(str(chr(x)) for x in data)
            sys.stdout.write(s)
1233175
def _add_seg_to_output(out, data, enumerate_chroms=False):
    
    out_file = "%s.seg" % os.path.splitext(out["cns"])[0]
    if not utils.file_exists(out_file):
        with file_transaction(data, out_file) as tx_out_file:
            cmd = [os.path.join(os.path.dirname(sys.executable), "cnvkit.py"), "export",
                   "seg"]
            if enumerate_chroms:
                cmd += ["--enumerate-chroms"]
            cmd += ["-o", tx_out_file, out["cns"]]
            do.run(cmd, "CNVkit export seg")
    out["seg"] = out_file
    return out
785156
def add_mavlink_packet(self, msg):
        ''''''
        mtype = msg.get_type()
        if mtype not in self.msg_types:
            return
        for i in range(len(self.fields)):
            if mtype not in self.field_types[i]:
                continue
            f = self.fields[i]
            self.values[i] = mavutil.evaluate_expression(f, self.state.master.messages)
        if self.livegraph is not None:
            self.livegraph.add_values(self.values)