<commit_before>#!/ms/dist/python/PROJ/core/2.5.0/bin/python
# ex: set expandtab softtabstop=4 shiftwidth=4: -*- cpy-indent-level: 4; indent-tabs-mode: nil -*-
# $Header$
# $Change$
# $DateTime$
# $Author$
# Copyright (C) 2008 <NAME>
#
# This module is part of Aquilon
"""Contains the logic for `aq show network`."""


from aquilon.server.broker import (format_results, add_transaction, az_check,
                                   BrokerCommand)
from aquilon.aqdb.net.network import Network
from aquilon.aqdb.hw.interface import Interface
from aquilon.server.dbwrappers.location import get_location
from aquilon.server.dbwrappers.network import get_network_byname, get_network_byip
from aquilon.server.formats.network import SimpleNetworkList
from aquilon.server.formats.network import NetworkHostList

class CommandShowNetwork(BrokerCommand):

    required_parameters = []

    @add_transaction
    @az_check
    @format_results
    def render(self, session, network, ip, all, type=False, hosts=False, **arguments):
        dbnetwork = network and get_network_byname(session, network) or None
        dbnetwork = ip and get_network_byip(session, ip) or None
        ints = []
        q = session.query(Network)
        if dbnetwork:
            if hosts:
                return NetworkHostList([dbnetwork])
            else:
                return dbnetwork
        if type:
            q = q.filter_by(network_type = type)
#            q = q.join('network_type').filter_by(network_type=type)
#            q = q.reset_joinpoint()
        dblocation = get_location(session, **arguments)
        if dblocation:
            q = q.filter_by(location=dblocation)
        if hosts:
            return NetworkHostList(q.all())
        else:
            return SimpleNetworkList(q.all())


#if __name__=='__main__':
<commit_msg>Removed old join on now defunct network_type table<commit_after>#!/ms/dist/python/PROJ/core/2.5.0/bin/python
# ex: set expandtab softtabstop=4 shiftwidth=4: -*- cpy-indent-level: 4; indent-tabs-mode: nil -*-
# $Header$
# $Change$
# $DateTime$
# $Author$
# Copyright (C) 2008 <NAME>
#
# This module is part of Aquilon
"""Contains the logic for `aq show network`."""


from aquilon.server.broker import (format_results, add_transaction, az_check,
                                   BrokerCommand)
from aquilon.aqdb.net.network import Network
from aquilon.aqdb.hw.interface import Interface
from aquilon.server.dbwrappers.location import get_location
from aquilon.server.dbwrappers.network import get_network_byname, get_network_byip
from aquilon.server.formats.network import SimpleNetworkList
from aquilon.server.formats.network import NetworkHostList

class CommandShowNetwork(BrokerCommand):

    required_parameters = []

    @add_transaction
    @az_check
    @format_results
    def render(self, session, network, ip, all, type=False, hosts=False, **arguments):
        dbnetwork = network and get_network_byname(session, network) or None
        dbnetwork = ip and get_network_byip(session, ip) or None
        ints = []
        q = session.query(Network)
        if dbnetwork:
            if hosts:
                return NetworkHostList([dbnetwork])
            else:
                return dbnetwork
        if type:
            q = q.filter_by(network_type = type)
        dblocation = get_location(session, **arguments)
        if dblocation:
            q = q.filter_by(location=dblocation)
        if hosts:
            return NetworkHostList(q.all())
        else:
            return SimpleNetworkList(q.all())


#if __name__=='__main__':

{'fraction_non_alphanumeric': 0.09851665267282396, 'fraction_numerical': 0.00559753708368318, 'mean_word_length': 2.914567360350493, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4665209', 'n_tokens_mistral': 1079, 'n_tokens_neox': 1048, 'n_words': 261}