Get a list of packed nodes from a ingest definition.
9677
def _getSynIngestNodes(self, item):
        '''
        
        '''
        pnodes = []
        seen = item.get('seen')
        # Track all the ndefs we make so we can make sources
        ndefs = []

        # Make the form nodes
        tags = item.get('tags', {})
        forms = item.get('forms', {})
        for form, valus in forms.items():
            for valu in valus:
                ndef = [form, valu]
                ndefs.append(ndef)
                obj = [ndef, {'tags': tags}]
                if seen:
                    obj[1]['props'] = {'.seen': seen}
                pnodes.append(obj)

        # Make the packed nodes
        nodes = item.get('nodes', ())
        for pnode in nodes:
            ndefs.append(pnode[0])
            pnode[1].setdefault('tags', {})
            for tag, valu in tags.items():
                # Tag in the packed node has a higher predecence
                # than the tag in the whole ingest set of data.
                pnode[1]['tags'].setdefault(tag, valu)
            if seen:
                pnode[1].setdefault('props', {})
                pnode[1]['props'].setdefault('.seen', seen)
            pnodes.append(pnode)

        # Make edges
        for srcdef, etyp, destndefs in item.get('edges', ()):
            for destndef in destndefs:
                ndef = [etyp, [srcdef, destndef]]
                ndefs.append(ndef)
                obj = [ndef, {}]
                if seen:
                    obj[1]['props'] = {'.seen': seen}
                if tags:
                    obj[1]['tags'] = tags.copy()
                pnodes.append(obj)

        # Make time based edges
        for srcdef, etyp, destndefs in item.get('time:edges', ()):
            for destndef, time in destndefs:
                ndef = [etyp, [srcdef, destndef, time]]
                ndefs.append(ndef)
                obj = [ndef, {}]
                if seen:
                    obj[1]['props'] = {'.seen': seen}
                if tags:
                    obj[1]['tags'] = tags.copy()
                pnodes.append(obj)

        # Make the source node and links
        source = item.get('source')
        if source:
            # Base object
            obj = [['meta:source', source], {}]
            pnodes.append(obj)

            # Subsequent links
            for ndef in ndefs:
                obj = [['meta:seen', (source, ndef)],
                       {'props': {'.seen': seen}}]
                pnodes.append(obj)
        return pnodes
175238
def ingest(cls, resource, element=None, xpath="ti:citation"):
        
        # Reuse of of find citation
        results = resource.xpath(xpath, namespaces=XPATH_NAMESPACES)
        if len(results) > 0:
            citation = cls(
                name=results[0].get("label"),
                xpath=results[0].get("xpath"),
                scope=results[0].get("scope")
            )

            if isinstance(element, cls):
                element.child = citation
                cls.ingest(
                    resource=results[0],
                    element=element.child
                )
            else:
                element = citation
                cls.ingest(
                    resource=results[0],
                    element=element
                )

            return citation

        return None
889363
def collect_by_type(self, typ):
        '''
        '''
        nodes = []
        if isinstance(self, typ):
            nodes.append(self)
        for c in self:
            nodes.extend(c.collect_by_type(typ))
        return nodes
554509
def visit_list(self, node):
        """"""
        return "[%s]" % ", ".join(child.accept(self) for child in node.elts)
357446
def _get_tables(self, ods):
        """"""

        childnodes = ods.spreadsheet.childNodes
        qname_childnodes = [(s.qname[1], s) for s in childnodes]
        return [node for name, node in qname_childnodes if name == u"table"]
1199304
def list_nodes(call=None):
    '''
    
    '''
    if call == 'action':
        raise SaltCloudSystemExit(
            'The list_nodes function must be called with -f or --function.'
        )

    ret = {}
    items = query(action='ve')

    for item in items:
        name = item.attrib['name']
        node = show_instance(name, call='action')

        ret[name] = {
            'id': node['id'],
            'image': node['platform']['template-info']['name'],
            'state': node['state'],
        }
        if 'private-ip' in node['network']:
            ret[name]['private_ips'] = [node['network']['private-ip']]
        if 'public-ip' in node['network']:
            ret[name]['public_ips'] = [node['network']['public-ip']]

    return ret
517558
def get_chunks(self, boundingbox=None):
        
        if self.chunks == None:
            self.chunks = list(self.iter_chunks())
        return self.chunks
659839
def getImportFromObjects(node):
    ''''''
    somenames = [x.asname for x in node.names if x.asname]
    othernames = [x.name for x in node.names if not x.asname]
    return somenames+othernames
219403
def get_nodes_by_source(self, graph, source_full_name):
        """"""
        parts = source_full_name.split('.')
        if len(parts) == 1:
            target_source, target_table = parts[0], None
        elif len(parts) == 2:
            target_source, target_table = parts
        else:  # len(parts) > 2 or len(parts) == 0
            msg = (
                'Invalid source selector value "{}". Sources must be of the '
                'form `${{source_name}}` or '
                '`${{source_name}}.${{target_name}}`'
            ).format(source_full_name)
            raise dbt.exceptions.RuntimeException(msg)

        for node, real_node in self.source_nodes(graph):
            if target_source not in (real_node.source_name, SELECTOR_GLOB):
                continue
            if target_table in (None, real_node.name, SELECTOR_GLOB):
                yield node
757070
def get_list_w_id2nts(ids, id2nts, flds, dflt_null=""):
    """"""
    combined_nt_list = []
    # 1. Instantiate namedtuple object
    ntobj = cx.namedtuple("Nt", " ".join(flds))
    # 2. Fill dict with namedtuple objects for desired ids
    for item_id in ids:
        # 2a. Combine various namedtuples into a single namedtuple
        nts = [id2nt.get(item_id) for id2nt in id2nts]
        vals = _combine_nt_vals(nts, flds, dflt_null)
        combined_nt_list.append(ntobj._make(vals))
    return combined_nt_list
84966
def _nodes_to_values(self):
        
        def is_none(slice):
            return slice[0] == -1 and slice[1] == -1

        def get(slice):
            return self.string[slice[0]:slice[1]]

        return [(varname, get(slice), slice) for varname, slice in self._nodes_to_regs() if not is_none(slice)]
143171
def traverse_imports(names):
    
    pending = [names]
    while pending:
        node = pending.pop()
        if node.type == token.NAME:
            yield node.value
        elif node.type == syms.dotted_name:
            yield "".join([ch.value for ch in node.children])
        elif node.type == syms.dotted_as_name:
            pending.append(node.children[0])
        elif node.type == syms.dotted_as_names:
            pending.extend(node.children[::-2])
        else:
            raise AssertionError("unkown node type")
352478
def node(*nodes):
    """"""
    chef.build_node_data_bag()
    if not len(nodes) or nodes[0] == '':
        abort('No node was given')
    elif nodes[0] == 'all':
        # Fetch all nodes and add them to env.hosts
        for node in lib.get_nodes(env.chef_environment):
            env.hosts.append(node['name'])
        if not len(env.hosts):
            abort('No nodes found in /nodes/')
        message = "Are you sure you want to configure all nodes ({0})".format(
            len(env.hosts))
        if env.chef_environment:
            message += " in the {0} environment".format(env.chef_environment)
        message += "?"
        if not __testing__:
            if not lib.global_confirm(message):
                abort('Aborted by user')
    else:
        # A list of nodes was given
        env.hosts = list(nodes)
    env.all_hosts = list(env.hosts)  # Shouldn't be needed

    # Check whether another command was given in addition to "node:"
    if not(littlechef.__cooking__ and
            'node:' not in sys.argv[-1] and
            'nodes_with_role:' not in sys.argv[-1] and
            'nodes_with_recipe:' not in sys.argv[-1] and
            'nodes_with_tag:' not in sys.argv[-1]):
        # If user didn't type recipe:X, role:Y or deploy_chef,
        # configure the nodes
        with settings():
            execute(_node_runner)
        chef.remove_local_node_data_bag()
935633
def list_nodes_full(call=None):
    '''
    
    '''
    response = _query('grid', 'server/list')

    ret = {}
    for item in response['list']:
        name = item['name']
        ret[name] = item

        ret[name]['image_info'] = item['image']
        ret[name]['image'] = item['image']['friendlyName']
        ret[name]['size'] = item['ram']['name']
        ret[name]['public_ips'] = [item['ip']['ip']]
        ret[name]['private_ips'] = []
        ret[name]['state_info'] = item['state']
        if 'active' in item['state']['description']:
            ret[name]['state'] = 'RUNNING'

    return ret
665782
def get_nodes(self):
        
        return self.fold_up(lambda n, fl, fg: [n] + fl + fg, lambda leaf: [leaf])
226933
def _ingest_sources(self, sources, stage, force=False):
        """"""
        from concurrent import ingest_mp

        self.state = self.STATES.INGESTING

        downloadable_sources = [s for s in sources if force or
                                (s.is_processable and not s.is_ingested and not s.is_built)]

        errors = 0

        with self.progress.start('ingest', stage,
                                 message='Ingesting ' + ('MP' if self.multi else 'SP'),
                                 item_total=len(sources), item_type='source',
                                 item_count=len(downloadable_sources)
                                 ) as ps:

            # Create all of the source tables first, so we can't get contention for creating them
            # in MP.

            for source in sources:
                _ = source.source_table

            if self.multi:
                args = [(self.identity.vid, stage, source.vid, force) for source in downloadable_sources]

                pool = self.library.process_pool(limited_run=self.limited_run)

                try:
                    # The '1' for chunksize ensures that the subprocess only gets one
                    # source to build. Combined with maxchildspertask = 1 in the pool,
                    # each process will only handle one source before exiting.
                    result = pool.map_async(ingest_mp, args, 1)

                    pool.close()
                    pool.join()

                except KeyboardInterrupt:
                    self.log('Got keyboard interrrupt; terminating workers')
                    pool.terminate()
                    raise
            else:
                for i, source in enumerate(downloadable_sources, 1):
                    ps.add(
                        message='Ingesting source #{}, {}'.format(i, source.name),
                        source=source, state='running')
                    r = self._ingest_source(source, ps, force)
                    if not r:
                        errors += 1

            if errors > 0:
                from ambry.dbexceptions import IngestionError
                raise IngestionError('Failed to ingest {} sources'.format(errors))

        return errors
77730
def _nodes(output, parent=None):
    """"""
    # NOTE refactor so all outputs behave the same
    entity = getattr(output, 'entity', output)

    if isinstance(entity, Collection):
        for member in entity.members:
            if parent is not None:
                member = attr.evolve(member, parent=parent)
            yield from _nodes(member)
        yield output
    else:
        yield output