def main(args):
    """
    """
    logger.info('lmdb test3.')
    logger.info('lmdb version %s', lmdb.version())

    if args.writer:
        the_writer()

    if args.reader:
        the_reader()
Exemple #2
0
 def __init__(self):
     '''
     LMDB creator can create a single LMDB for single label classification
     or two LMDBs where each element in the database_images has a corresponding
     counterpart in database_additional with the same key. This is useful for creating
     for example LMDBs for PHOCs, attributes or segmentation.
     '''
     self.logger = logging.getLogger('CaffeLMDBCreator')
     self.database_images = None
     self.database_additional = None
     self.txn_images = None
     self.txn_additional = None
     self.label_map = None
     self.internal_counter = 0
     
     self.logger.debug('Using LMDB version %d.%d.%d' % lmdb.version())
Exemple #3
0
    def __init__(self):
        '''
        LMDB creator can create a single LMDB for single label classification
        or two LMDBs where each element in the database_images has a corresponding
        counterpart in database_additional with the same key. This is useful for creating
        for example LMDBs for PHOCs, attributes or segmentation.
        '''
        self.logger = logging.getLogger('CaffeLMDBCreator')
        self.database_images = None
        self.database_additional = None
        self.txn_images = None
        self.txn_additional = None
        self.label_map = None
        self.internal_counter = 0

        self.logger.debug('Using LMDB version %d.%d.%d' % lmdb.version())
Exemple #4
0
 def test_version(self):
     ver = lmdb.version()
     assert len(ver) == 3
     assert all(isinstance(i, INT_TYPES) for i in ver)
     assert all(i >= 0 for i in ver)
Exemple #5
0
def run_command_version(options, reactor=None, **kwargs):
    """
    Subcommand "crossbar version".
    """
    log = make_logger()
    # verbose = True

    # Python
    py_ver = '.'.join([str(x) for x in list(sys.version_info[:3])])
    py_ver_string = "[%s]" % sys.version.replace('\n', ' ')

    if 'pypy_version_info' in sys.__dict__:
        py_ver_detail = "{}-{}".format(
            platform.python_implementation(),
            '.'.join(str(x) for x in sys.pypy_version_info[:3]))
    else:
        py_ver_detail = platform.python_implementation()

    # Twisted / Reactor
    tx_ver = "%s-%s" % (pkg_resources.require("Twisted")[0].version,
                        reactor.__class__.__name__)
    tx_loc = "[%s]" % qual(reactor.__class__)

    # txaio
    txaio_ver = 'txaio-%s' % pkg_resources.require("txaio")[0].version

    # Autobahn
    from autobahn.websocket.protocol import WebSocketProtocol
    ab_ver = pkg_resources.require("autobahn")[0].version
    ab_loc = "[%s]" % qual(WebSocketProtocol)

    # UTF8 Validator
    from autobahn.websocket.utf8validator import Utf8Validator
    s = qual(Utf8Validator)
    if 'wsaccel' in s:
        utf8_ver = 'wsaccel-%s' % pkg_resources.require('wsaccel')[0].version
    elif s.startswith('autobahn'):
        utf8_ver = 'autobahn'
    else:
        # could not detect UTF8 validator type/version
        utf8_ver = '?'
    utf8_loc = "[%s]" % qual(Utf8Validator)

    # XOR Masker
    from autobahn.websocket.xormasker import XorMaskerNull
    s = qual(XorMaskerNull)
    if 'wsaccel' in s:
        xor_ver = 'wsaccel-%s' % pkg_resources.require('wsaccel')[0].version
    elif s.startswith('autobahn'):
        xor_ver = 'autobahn'
    else:
        # could not detect XOR masker type/version
        xor_ver = '?'
    xor_loc = "[%s]" % qual(XorMaskerNull)

    # JSON Serializer
    supported_serializers = ['JSON']
    from autobahn.wamp.serializer import JsonObjectSerializer
    s = str(JsonObjectSerializer.JSON_MODULE)
    if 'ujson' in s:
        json_ver = 'ujson-%s' % pkg_resources.require('ujson')[0].version
    else:
        json_ver = 'stdlib'

    # MsgPack Serializer
    try:
        import msgpack  # noqa
        msgpack_ver = 'msgpack-python-%s' % pkg_resources.require(
            'msgpack-python')[0].version
        supported_serializers.append('MessagePack')
    except ImportError:
        msgpack_ver = '-'

    # CBOR Serializer
    try:
        import cbor  # noqa
        cbor_ver = 'cbor-%s' % pkg_resources.require('cbor')[0].version
        supported_serializers.append('CBOR')
    except ImportError:
        cbor_ver = '-'

    # LMDB
    try:
        import lmdb  # noqa
        lmdb_lib_ver = '.'.join([str(x) for x in lmdb.version()])
        lmdb_ver = '{}/lmdb-{}'.format(
            pkg_resources.require('lmdb')[0].version, lmdb_lib_ver)
    except ImportError:
        lmdb_ver = '-'

    def decorate(text):
        return click.style(text, fg='yellow', bold=True)

    for line in BANNER.splitlines():
        log.info(decorate("{:>40}".format(line)))

    pad = " " * 22

    log.info(" Crossbar.io        : {ver}", ver=decorate(crossbar.__version__))
    log.info("   Autobahn         : {ver} (with {serializers})",
             ver=decorate(ab_ver),
             serializers=', '.join(supported_serializers))
    log.trace("{pad}{debuginfo}", pad=pad, debuginfo=decorate(ab_loc))
    log.debug("     txaio          : {ver}", ver=decorate(txaio_ver))
    log.debug("     UTF8 Validator : {ver}", ver=decorate(utf8_ver))
    log.trace("{pad}{debuginfo}", pad=pad, debuginfo=decorate(utf8_loc))
    log.debug("     XOR Masker     : {ver}", ver=decorate(xor_ver))
    log.trace("{pad}{debuginfo}", pad=pad, debuginfo=decorate(xor_loc))
    log.debug("     JSON Codec     : {ver}", ver=decorate(json_ver))
    log.debug("     MsgPack Codec  : {ver}", ver=decorate(msgpack_ver))
    log.debug("     CBOR Codec     : {ver}", ver=decorate(cbor_ver))
    log.info("   Twisted          : {ver}", ver=decorate(tx_ver))
    log.trace("{pad}{debuginfo}", pad=pad, debuginfo=decorate(tx_loc))
    log.info("   LMDB             : {ver}", ver=decorate(lmdb_ver))
    log.info("   Python           : {ver}/{impl}",
             ver=decorate(py_ver),
             impl=decorate(py_ver_detail))
    log.trace("{pad}{debuginfo}", pad=pad, debuginfo=decorate(py_ver_string))
    log.info(" OS                 : {ver}", ver=decorate(platform.platform()))
    log.info(" Machine            : {ver}", ver=decorate(platform.machine()))
    log.info("")
Exemple #6
0
def run_command_version(options, reactor=None, **kwargs):
    """
    Subcommand "crossbar version".
    """
    log = make_logger()
    # verbose = True

    # Python
    py_ver = '.'.join([str(x) for x in list(sys.version_info[:3])])
    py_ver_string = "[%s]" % sys.version.replace('\n', ' ')

    if 'pypy_version_info' in sys.__dict__:
        py_ver_detail = "{}-{}".format(platform.python_implementation(), '.'.join(str(x) for x in sys.pypy_version_info[:3]))
    else:
        py_ver_detail = platform.python_implementation()

    # Twisted / Reactor
    tx_ver = "%s-%s" % (pkg_resources.require("Twisted")[0].version, reactor.__class__.__name__)
    tx_loc = "[%s]" % qual(reactor.__class__)

    # txaio
    txaio_ver = 'txaio-%s' % pkg_resources.require("txaio")[0].version

    # Autobahn
    from autobahn.websocket.protocol import WebSocketProtocol
    ab_ver = pkg_resources.require("autobahn")[0].version
    ab_loc = "[%s]" % qual(WebSocketProtocol)

    # UTF8 Validator
    from autobahn.websocket.utf8validator import Utf8Validator
    s = qual(Utf8Validator)
    if 'wsaccel' in s:
        utf8_ver = 'wsaccel-%s' % pkg_resources.require('wsaccel')[0].version
    elif s.startswith('autobahn'):
        utf8_ver = 'autobahn'
    else:
        # could not detect UTF8 validator type/version
        utf8_ver = '?'
    utf8_loc = "[%s]" % qual(Utf8Validator)

    # XOR Masker
    from autobahn.websocket.xormasker import XorMaskerNull
    s = qual(XorMaskerNull)
    if 'wsaccel' in s:
        xor_ver = 'wsaccel-%s' % pkg_resources.require('wsaccel')[0].version
    elif s.startswith('autobahn'):
        xor_ver = 'autobahn'
    else:
        # could not detect XOR masker type/version
        xor_ver = '?'
    xor_loc = "[%s]" % qual(XorMaskerNull)

    # JSON Serializer
    supported_serializers = ['JSON']
    from autobahn.wamp.serializer import JsonObjectSerializer
    s = str(JsonObjectSerializer.JSON_MODULE)
    if 'ujson' in s:
        json_ver = 'ujson-%s' % pkg_resources.require('ujson')[0].version
    else:
        json_ver = 'stdlib'

    # MsgPack Serializer
    try:
        import msgpack  # noqa
        msgpack_ver = 'msgpack-python-%s' % pkg_resources.require('msgpack-python')[0].version
        supported_serializers.append('MessagePack')
    except ImportError:
        msgpack_ver = '-'

    # CBOR Serializer
    try:
        import cbor  # noqa
        cbor_ver = 'cbor-%s' % pkg_resources.require('cbor')[0].version
        supported_serializers.append('CBOR')
    except ImportError:
        cbor_ver = '-'

    # UBJSON Serializer
    try:
        import ubjson  # noqa
        ubjson_ver = 'ubjson-%s' % pkg_resources.require('py-ubjson')[0].version
        supported_serializers.append('UBJSON')
    except ImportError:
        ubjson_ver = '-'

    # LMDB
    try:
        import lmdb  # noqa
        lmdb_lib_ver = '.'.join([str(x) for x in lmdb.version()])
        lmdb_ver = '{}/lmdb-{}'.format(pkg_resources.require('lmdb')[0].version, lmdb_lib_ver)
    except ImportError:
        lmdb_ver = '-'

    def decorate(text):
        return click.style(text, fg='yellow', bold=True)

    for line in BANNER.splitlines():
        log.info(decorate("{:>40}".format(line)))

    pad = " " * 22

    log.info(" Crossbar.io        : {ver}", ver=decorate(crossbar.__version__))
    log.info("   Autobahn         : {ver} (with {serializers})", ver=decorate(ab_ver), serializers=', '.join(supported_serializers))
    log.trace("{pad}{debuginfo}", pad=pad, debuginfo=decorate(ab_loc))
    log.debug("     txaio          : {ver}", ver=decorate(txaio_ver))
    log.debug("     UTF8 Validator : {ver}", ver=decorate(utf8_ver))
    log.trace("{pad}{debuginfo}", pad=pad, debuginfo=decorate(utf8_loc))
    log.debug("     XOR Masker     : {ver}", ver=decorate(xor_ver))
    log.trace("{pad}{debuginfo}", pad=pad, debuginfo=decorate(xor_loc))
    log.debug("     JSON Codec     : {ver}", ver=decorate(json_ver))
    log.debug("     MsgPack Codec  : {ver}", ver=decorate(msgpack_ver))
    log.debug("     CBOR Codec     : {ver}", ver=decorate(cbor_ver))
    log.debug("     UBJSON Codec   : {ver}", ver=decorate(ubjson_ver))
    log.info("   Twisted          : {ver}", ver=decorate(tx_ver))
    log.trace("{pad}{debuginfo}", pad=pad, debuginfo=decorate(tx_loc))
    log.info("   LMDB             : {ver}", ver=decorate(lmdb_ver))
    log.info("   Python           : {ver}/{impl}", ver=decorate(py_ver), impl=decorate(py_ver_detail))
    log.trace("{pad}{debuginfo}", pad=pad, debuginfo=decorate(py_ver_string))
    log.info(" OS                 : {ver}", ver=decorate(platform.platform()))
    log.info(" Machine            : {ver}", ver=decorate(platform.machine()))
    log.info("")
Exemple #7
0
def run_command_version(options, reactor=None, **kwargs):
    """
    Subcommand "crossbar version".
    """
    log = make_logger()

    # Python
    py_ver = '.'.join([str(x) for x in list(sys.version_info[:3])])
    py_ver_string = "[%s]" % sys.version.replace('\n', ' ')

    if 'pypy_version_info' in sys.__dict__:
        py_ver_detail = "{}-{}".format(platform.python_implementation(), '.'.join(str(x) for x in sys.pypy_version_info[:3]))
    else:
        py_ver_detail = platform.python_implementation()

    # Twisted / Reactor
    tx_ver = "%s-%s" % (pkg_resources.require("Twisted")[0].version, reactor.__class__.__name__)
    tx_loc = "[%s]" % qual(reactor.__class__)

    # txaio
    txaio_ver = '%s' % pkg_resources.require("txaio")[0].version

    # Autobahn
    ab_ver = pkg_resources.require("autobahn")[0].version
    ab_loc = "[%s]" % qual(WebSocketProtocol)

    # UTF8 Validator
    s = qual(Utf8Validator)
    if 'wsaccel' in s:
        utf8_ver = 'wsaccel-%s' % pkg_resources.require('wsaccel')[0].version
    elif s.startswith('autobahn'):
        utf8_ver = 'autobahn'
    else:
        # could not detect UTF8 validator type/version
        utf8_ver = '?'
    utf8_loc = "[%s]" % qual(Utf8Validator)

    # XOR Masker
    s = qual(XorMaskerNull)
    if 'wsaccel' in s:
        xor_ver = 'wsaccel-%s' % pkg_resources.require('wsaccel')[0].version
    elif s.startswith('autobahn'):
        xor_ver = 'autobahn'
    else:
        # could not detect XOR masker type/version
        xor_ver = '?'
    xor_loc = "[%s]" % qual(XorMaskerNull)

    # JSON Serializer
    supported_serializers = ['JSON']
    from autobahn.wamp.serializer import JsonObjectSerializer
    json_ver = JsonObjectSerializer.JSON_MODULE.__name__

    # If it's just 'json' then it's the stdlib one...
    if json_ver == 'json':
        json_ver = 'stdlib'
    else:
        json_ver = (json_ver + "-%s") % pkg_resources.require(json_ver)[0].version

    # MsgPack Serializer
    try:
        import umsgpack  # noqa
        msgpack_ver = 'u-msgpack-python-%s' % pkg_resources.require('u-msgpack-python')[0].version
        supported_serializers.append('MessagePack')
    except ImportError:
        msgpack_ver = '-'

    # CBOR Serializer
    try:
        import cbor  # noqa
        cbor_ver = 'cbor-%s' % pkg_resources.require('cbor')[0].version
        supported_serializers.append('CBOR')
    except ImportError:
        cbor_ver = '-'

    # UBJSON Serializer
    try:
        import ubjson  # noqa
        ubjson_ver = 'ubjson-%s' % pkg_resources.require('py-ubjson')[0].version
        supported_serializers.append('UBJSON')
    except ImportError:
        ubjson_ver = '-'

    # LMDB
    try:
        import lmdb  # noqa
        lmdb_lib_ver = '.'.join([str(x) for x in lmdb.version()])
        lmdb_ver = '{}/lmdb-{}'.format(pkg_resources.require('lmdb')[0].version, lmdb_lib_ver)
    except ImportError:
        lmdb_ver = '-'

    # crossbarfabric (only Crossbar.io FABRIC)
    try:
        import crossbarfabric  # noqa
        crossbarfabric_ver = '%s' % pkg_resources.require('crossbarfabric')[0].version
    except ImportError:
        crossbarfabric_ver = '-'

    # crossbarfabriccenter (only Crossbar.io FABRIC CENTER)
    try:
        import crossbarfabriccenter  # noqa
        crossbarfabriccenter_ver = '%s' % pkg_resources.require('crossbarfabriccenter')[0].version
    except ImportError:
        crossbarfabriccenter_ver = '-'

    # txaio-etcd (only Crossbar.io FABRIC CENTER)
    try:
        import txaioetcd  # noqa
        txaioetcd_ver = '%s' % pkg_resources.require('txaioetcd')[0].version
    except ImportError:
        txaioetcd_ver = '-'

    # Release Public Key
    release_pubkey = _read_release_pubkey()

    def decorate(text):
        return click.style(text, fg='yellow', bold=True)

    Node = node_classes[options.personality][u'class']

    for line in Node.BANNER.splitlines():
        log.info(decorate("{:>40}".format(line)))

    pad = " " * 22

    log.info(" Crossbar.io        : {ver} ({personality})", ver=decorate(crossbar.__version__), personality=Node.PERSONALITY)
    log.info("   Autobahn         : {ver} (with {serializers})", ver=decorate(ab_ver), serializers=', '.join(supported_serializers))
    log.trace("{pad}{debuginfo}", pad=pad, debuginfo=decorate(ab_loc))
    log.debug("     txaio          : {ver}", ver=decorate(txaio_ver))
    log.debug("     UTF8 Validator : {ver}", ver=decorate(utf8_ver))
    log.trace("{pad}{debuginfo}", pad=pad, debuginfo=decorate(utf8_loc))
    log.debug("     XOR Masker     : {ver}", ver=decorate(xor_ver))
    log.trace("{pad}{debuginfo}", pad=pad, debuginfo=decorate(xor_loc))
    log.debug("     JSON Codec     : {ver}", ver=decorate(json_ver))
    log.debug("     MsgPack Codec  : {ver}", ver=decorate(msgpack_ver))
    log.debug("     CBOR Codec     : {ver}", ver=decorate(cbor_ver))
    log.debug("     UBJSON Codec   : {ver}", ver=decorate(ubjson_ver))
    log.info("   Twisted          : {ver}", ver=decorate(tx_ver))
    log.trace("{pad}{debuginfo}", pad=pad, debuginfo=decorate(tx_loc))
    log.info("   LMDB             : {ver}", ver=decorate(lmdb_ver))
    log.info("   Python           : {ver}/{impl}", ver=decorate(py_ver), impl=decorate(py_ver_detail))
    log.trace("{pad}{debuginfo}", pad=pad, debuginfo=decorate(py_ver_string))
    if options.personality in (u'fabric', u'fabriccenter'):
        log.info(" Crossbar.io Fabric : {ver}", ver=decorate(crossbarfabric_ver))
    if options.personality == u'fabriccenter':
        log.info(" Crossbar.io FC     : {ver}", ver=decorate(crossbarfabriccenter_ver))
        log.debug("   txaioetcd        : {ver}", ver=decorate(txaioetcd_ver))
    log.info(" OS                 : {ver}", ver=decorate(platform.platform()))
    log.info(" Machine            : {ver}", ver=decorate(platform.machine()))
    log.info(" Release key        : {release_pubkey}", release_pubkey=decorate(release_pubkey[u'base64']))
    log.info("")
Exemple #8
0
def _run_command_version(options, reactor, personality):
    """
    Subcommand "crossbar version".
    """
    log = make_logger()

    # Python
    py_ver = '.'.join([str(x) for x in list(sys.version_info[:3])])
    py_ver_string = "[%s]" % sys.version.replace('\n', ' ')

    if 'pypy_version_info' in sys.__dict__:
        py_ver_detail = "{}-{}".format(platform.python_implementation(), '.'.join(str(x) for x in sys.pypy_version_info[:3]))
    else:
        py_ver_detail = platform.python_implementation()

    # Pyinstaller (frozen EXE)
    py_is_frozen = getattr(sys, 'frozen', False)

    # Twisted / Reactor
    tx_ver = "%s-%s" % (_get_version('twisted'), reactor.__class__.__name__)
    tx_loc = "[%s]" % qual(reactor.__class__)

    # txaio
    txaio_ver = _get_version('txaio')

    # Autobahn
    ab_ver = _get_version('autobahn')
    ab_loc = "[%s]" % qual(WebSocketProtocol)

    # UTF8 Validator
    s = qual(Utf8Validator)
    if 'wsaccel' in s:
        utf8_ver = 'wsaccel-%s' % _get_version('wsaccel')
    elif s.startswith('autobahn'):
        utf8_ver = 'autobahn'
    else:
        # could not detect UTF8 validator type/version
        utf8_ver = '?'
    utf8_loc = "[%s]" % qual(Utf8Validator)

    # XOR Masker
    s = qual(XorMaskerNull)
    if 'wsaccel' in s:
        xor_ver = 'wsaccel-%s' % _get_version('wsaccel')
    elif s.startswith('autobahn'):
        xor_ver = 'autobahn'
    else:
        # could not detect XOR masker type/version
        xor_ver = '?'
    xor_loc = "[%s]" % qual(XorMaskerNull)

    # JSON Serializer
    supported_serializers = ['JSON']
    from autobahn.wamp.serializer import JsonObjectSerializer
    json_ver = JsonObjectSerializer.JSON_MODULE.__name__

    # If it's just 'json' then it's the stdlib one...
    if json_ver == 'json':
        json_ver = 'stdlib'
    else:
        json_ver = (json_ver + "-%s") % _get_version(json_ver)

    # MsgPack Serializer
    try:
        import umsgpack  # noqa
        msgpack_ver = 'u-msgpack-python-%s' % _get_version(umsgpack)
        supported_serializers.append('MessagePack')
    except ImportError:
        msgpack_ver = '-'

    # CBOR Serializer
    try:
        import cbor  # noqa
        cbor_ver = 'cbor-%s' % _get_version(cbor)
        supported_serializers.append('CBOR')
    except ImportError:
        cbor_ver = '-'

    # UBJSON Serializer
    try:
        import ubjson  # noqa
        ubjson_ver = 'ubjson-%s' % _get_version(ubjson)
        supported_serializers.append('UBJSON')
    except ImportError:
        ubjson_ver = '-'

    # LMDB
    try:
        import lmdb  # noqa
        lmdb_lib_ver = '.'.join([str(x) for x in lmdb.version()])
        lmdb_ver = '{}/lmdb-{}'.format(_get_version(lmdb), lmdb_lib_ver)
    except ImportError:
        lmdb_ver = '-'

    # crossbarfx
    try:
        from crossbarfx._version import __version__ as crossbarfx_ver  # noqa
    except ImportError:
        crossbarfx_ver = '-'

    # txaio-etcd
    try:
        import txaioetcd  # noqa
        txaioetcd_ver = _get_version(txaioetcd)
    except ImportError:
        txaioetcd_ver = '-'

    # Release Public Key
    from crossbar.common.key import _read_release_key
    release_pubkey = _read_release_key()

    def decorate(text, fg='white', bg=None, bold=True):
        return click.style(text, fg=fg, bg=bg, bold=bold)

    pad = " " * 22
    for line in personality.BANNER.splitlines():
        log.info(hl(line, color='yellow', bold=True))
    log.info("")
    log.info(" Crossbar.io        : {ver}", ver=decorate(crossbar.__version__))
    log.info("   Autobahn         : {ver}", ver=decorate(ab_ver))
    log.trace("{pad}{debuginfo}", pad=pad, debuginfo=decorate(ab_loc))
    log.debug("     txaio          : {ver}", ver=decorate(txaio_ver))
    log.debug("     UTF8 Validator : {ver}", ver=decorate(utf8_ver))
    log.trace("{pad}{debuginfo}", pad=pad, debuginfo=decorate(utf8_loc))
    log.debug("     XOR Masker     : {ver}", ver=decorate(xor_ver))
    log.trace("{pad}{debuginfo}", pad=pad, debuginfo=decorate(xor_loc))
    log.debug("     JSON Codec     : {ver}", ver=decorate(json_ver))
    log.debug("     MsgPack Codec  : {ver}", ver=decorate(msgpack_ver))
    log.debug("     CBOR Codec     : {ver}", ver=decorate(cbor_ver))
    log.debug("     UBJSON Codec   : {ver}", ver=decorate(ubjson_ver))
    log.info("   Twisted          : {ver}", ver=decorate(tx_ver))
    log.trace("{pad}{debuginfo}", pad=pad, debuginfo=decorate(tx_loc))
    log.info("   LMDB             : {ver}", ver=decorate(lmdb_ver))
    log.info("   Python           : {ver}/{impl}", ver=decorate(py_ver), impl=decorate(py_ver_detail))
    log.trace("{pad}{debuginfo}", pad=pad, debuginfo=decorate(py_ver_string))
    if personality.NAME in (u'edge', u'master'):
        log.info(" Crossbar.io FX     : {ver}", ver=decorate(crossbarfx_ver))
    if personality.NAME in (u'master'):
        log.info("   txaioetcd        : {ver}", ver=decorate(txaioetcd_ver))
    log.info(" Frozen executable  : {py_is_frozen}", py_is_frozen=decorate('yes' if py_is_frozen else 'no'))
    log.info(" Operating system   : {ver}", ver=decorate(platform.platform()))
    log.info(" Host machine       : {ver}", ver=decorate(platform.machine()))
    log.info(" Release key        : {release_pubkey}", release_pubkey=decorate(release_pubkey[u'base64']))
    log.info("")
Exemple #9
0
# Flatbuffers Serializer
try:
    from autobahn.wamp.serializer import FlatBuffersObjectSerializer
    flatbuffers = FlatBuffersObjectSerializer.FLATBUFFERS_MODULE
    res['flatbuffers_ver'] = '{}-{}'.format(flatbuffers.__name__,
                                            _get_version(flatbuffers))
    supported_serializers.append('Flatbuffers')
except ImportError:
    res['flatbuffers_ver'] = None

res['supported_serializers'] = supported_serializers

try:
    import lmdb  # noqa
    lmdb_lib_ver = '.'.join([str(x) for x in lmdb.version()])
    res['lmdb_ver'] = '{}/lmdb-{}'.format(_get_version(lmdb), lmdb_lib_ver)
except ImportError:
    res['lmdb_ver'] = None

try:
    import zlmdb  # noqa
    res['zlmdb_ver'] = _get_version(zlmdb)
except ImportError:
    res['zlmdb_ver'] = None

try:
    import numpy  # noqa
    res['numpy_ver'] = _get_version(numpy)
except ImportError:
    res['numpy_ver'] = None
Exemple #10
0
 def test_version(self):
     ver = lmdb.version()
     assert len(ver) == 3
     assert all(isinstance(i, INT_TYPES) for i in ver)
     assert all(i >= 0 for i in ver)
Exemple #11
0
import subprocess
import platform
import sys
sys.path.append("/home/npellejero/digits/nvidia-caffe/python/")
import caffe
caffe.set_mode_gpu()
import lmdb

import pandas as pd
import numpy as np

import matplotlib.pyplot as plt

print "OS:     ", platform.platform()
print "Python: ", sys.version.split("\n")[0]
print "CUDA:   ", subprocess.Popen(["nvcc","--version"], stdout=subprocess.PIPE).communicate()[0].split("\n")[3]
print "LMDB:   ", ".".join([str(i) for i in lmdb.version()])
Exemple #12
0
def main():
    #Spit out system information
    print "OS:     ", platform.platform()
    print "Python: ", sys.version.split("\n")[0]
    print "CUDA:   ", subprocess.Popen(
        ["nvcc", "--version"],
        stdout=subprocess.PIPE).communicate()[0].split("\n")[3]
    print "LMDB:   ", ".".join([str(i) for i in lmdb.version()])
    print ""

    no_cards = 0

    while True:
        try:
            no_cards = int(
                raw_input("No of cards for system? [3/4/5/0] (0 for all):\t"))
            if no_cards == 3 or no_cards == 4 or no_cards == 5:
                break
            else:
                raise ValueError
        except ValueError:
            print "Incorrect input, try again!"

    lmdb_train_path = "../dataset/lmdb/cards_" + str(
        no_cards) + "_train_data_lmdb"
    lmdb_test_path = "../dataset/lmdb/cards_" + str(
        no_cards) + "_test_data_lmdb"
    train_data_set = "../dataset/poker-hand-training-true.data"
    test_data_set = "../dataset/poker-hand-testing.data"
    caffe_path = "../../caffe-master/build/tools/caffe"
    config_path = "../nn_config/cards_" + str(no_cards) + "_config/"
    config_filename = "config.prototxt"
    model_test_filaname = "model_test.prototxt"
    caffe_nets = "../caffe_nets/cards_" + str(no_cards) + "_net/"

    max_iters_3_cards = 100000
    max_iters_4_cards = 100000
    max_iters_5_cards = 100000

    caffemodel_filename = "_iter_"
    solverstate_filaname = "_iter_"

    if no_cards == 3:
        caffemodel_filename += str(max_iters_3_cards)
        solverstate_filaname += str(max_iters_3_cards)
    elif no_cards == 4:
        caffemodel_filename += str(max_iters_4_cards)
        solverstate_filaname += str(max_iters_4_cards)
    elif no_cards == 5:
        caffemodel_filename += str(max_iters_5_cards)
        solverstate_filaname += str(max_iters_5_cards)

    caffemodel_filename += ".caffemodel"
    solverstate_filaname += ".solverstate"

    while True:
        load_data = raw_input(
            "Load data into LMDB? Deletes old data if found. [y/n]:\t")
        if load_data == "y" or load_data == "Y":
            print "Loading data into LMDB..."

            if os.path.isdir(lmdb_train_path):
                shutil.rmtree(lmdb_train_path)
            if os.path.isdir(lmdb_test_path):
                shutil.rmtree(lmdb_test_path)

            df = pd.read_csv(train_data_set, sep=",")
            testing_data = pd.read_csv(test_data_set, sep=",")

            training_features = df.ix[:, :(no_cards * 2)].as_matrix()
            training_labels = df.ix[:, -1].as_matrix()

            testing_features = testing_data.ix[:, :(no_cards * 2)].as_matrix()
            testing_labels = testing_data.ix[:, -1].as_matrix()

            dataload_lmdb.load_data_into_lmdb(lmdb_train_path,
                                              training_features,
                                              training_labels)
            dataload_lmdb.load_data_into_lmdb(lmdb_test_path, testing_features,
                                              testing_labels)

            break
        elif load_data == "N" or load_data == "n":
            break
        else:
            print "Incorrect input, try again!"

    while True:
        train_net = raw_input("Train the network? [y/n]:\t")
        if train_net == "y" or train_net == "Y":
            #dataload_lmdb.get_data_for_case_from_lmdb(lmdb_train_path, "00012345")
            print "Training..."

            proc = subprocess.Popen([
                caffe_path, "train",
                "--solver=" + config_path + config_filename
            ],
                                    stderr=subprocess.PIPE)
            res = proc.communicate()[1]

            if proc.returncode != 0:
                print "Error in Caffe training!"
                print res
                sys.exit()

            shutil.move(caffemodel_filename, caffe_nets + caffemodel_filename)
            shutil.move(solverstate_filaname,
                        caffe_nets + solverstate_filaname)

            break
        elif train_net == "n" or train_net == "N":
            break
        else:
            print "Incorrect input, try again!"

    while True:
        test_net = raw_input("Test the caffe net? [y/n]:\t")
        if test_net == "y" or test_net == "Y":

            if not os.path.exists(config_path + model_test_filaname):
                print "Model_test.prototxt for cards_" + str(
                    no_cards) + "_config not found!"
                break
            if not os.path.exists(caffe_nets + caffemodel_filename):
                print "Caffemodel for cards_" + str(no_cards) + "_net not found, first train the network for cards_"\
                     + str(no_cards) + " first!"
                break

            print "Testing..."
            net = caffe.Net(config_path + model_test_filaname,
                            caffe_nets + caffemodel_filename, caffe.TEST)
            labels, features = dataload_lmdb.get_data_for_case_from_lmdb(
                lmdb_test_path, "00001230")

            out = net.forward(**{net.inputs[0]: np.asarray([features])})
            print np.argmax(out["prob"][0]) == labels, "\n", out
            plt.bar(range(10), out["prob"][0])
            pylab.show()
            break
        elif test_net == "n" or test_net == "N":
            break
        else:
            print "Incorrect input, try again!"

    print "\n..........End of script.........."
Exemple #13
0
def main():
    #Spit out system information
    print "OS:     ", platform.platform()
    print "Python: ", sys.version.split("\n")[0]
    print "CUDA:   ", subprocess.Popen(["nvcc","--version"], stdout=subprocess.PIPE).communicate()[0].split("\n")[3]
    print "LMDB:   ", ".".join([str(i) for i in lmdb.version()])
    print ""

    no_cards = 0

    while True:
        try:
            no_cards = int(raw_input("No of cards for system? [3/4/5/0] (0 for all):\t"))
            if no_cards == 3 or no_cards == 4 or no_cards == 5:
                break
            else:
                raise ValueError
        except ValueError:
            print "Incorrect input, try again!"

    lmdb_train_path = "../dataset/lmdb/cards_" + str(no_cards) +"_train_data_lmdb"
    lmdb_test_path = "../dataset/lmdb/cards_" + str(no_cards) +"_test_data_lmdb"
    train_data_set = "../dataset/poker-hand-training-true.data"
    test_data_set = "../dataset/poker-hand-testing.data"
    caffe_path = "../../caffe-master/build/tools/caffe"
    config_path = "../nn_config/cards_" + str(no_cards) + "_config/"
    config_filename = "config.prototxt"
    model_test_filaname = "model_test.prototxt"
    caffe_nets = "../caffe_nets/cards_" + str(no_cards) + "_net/"

    max_iters_3_cards = 100000
    max_iters_4_cards = 100000
    max_iters_5_cards = 100000

    caffemodel_filename = "_iter_"
    solverstate_filaname = "_iter_"

    if no_cards == 3:
        caffemodel_filename += str(max_iters_3_cards)
        solverstate_filaname += str(max_iters_3_cards)
    elif no_cards == 4:
        caffemodel_filename += str(max_iters_4_cards)
        solverstate_filaname += str(max_iters_4_cards)
    elif no_cards == 5:
        caffemodel_filename += str(max_iters_5_cards)
        solverstate_filaname += str(max_iters_5_cards)

    caffemodel_filename += ".caffemodel"
    solverstate_filaname += ".solverstate"

    while True:
        load_data = raw_input("Load data into LMDB? Deletes old data if found. [y/n]:\t")
        if load_data == "y" or load_data == "Y":
            print "Loading data into LMDB..."

            if os.path.isdir(lmdb_train_path):
                shutil.rmtree(lmdb_train_path)
            if os.path.isdir(lmdb_test_path):
                shutil.rmtree(lmdb_test_path)

            df = pd.read_csv(train_data_set, sep=",")
            testing_data = pd.read_csv(test_data_set, sep=",")

            training_features = df.ix[:,:(no_cards * 2)].as_matrix()
            training_labels = df.ix[:,-1].as_matrix()

            testing_features = testing_data.ix[:,:(no_cards * 2)].as_matrix()
            testing_labels = testing_data.ix[:,-1].as_matrix()

            dataload_lmdb.load_data_into_lmdb(lmdb_train_path, training_features, training_labels)
            dataload_lmdb.load_data_into_lmdb(lmdb_test_path, testing_features, testing_labels)

            break
        elif load_data == "N" or load_data == "n":
            break
        else:
            print "Incorrect input, try again!"


    while True:
        train_net = raw_input("Train the network? [y/n]:\t")
        if train_net == "y" or train_net == "Y":
            #dataload_lmdb.get_data_for_case_from_lmdb(lmdb_train_path, "00012345")
            print "Training..."

            proc = subprocess.Popen(
                [caffe_path, "train", "--solver=" + config_path + config_filename], 
                stderr=subprocess.PIPE)
            res = proc.communicate()[1]
            
            if proc.returncode != 0:
                print "Error in Caffe training!"
                print res
                sys.exit()

            shutil.move(caffemodel_filename, caffe_nets + caffemodel_filename)
            shutil.move(solverstate_filaname, caffe_nets + solverstate_filaname)

            break
        elif train_net == "n" or train_net == "N":
            break
        else:
            print "Incorrect input, try again!"

    while True:
        test_net = raw_input("Test the caffe net? [y/n]:\t")
        if test_net == "y" or test_net == "Y":

            if not os.path.exists(config_path + model_test_filaname):
                print "Model_test.prototxt for cards_" + str(no_cards) + "_config not found!"
                break
            if not os.path.exists(caffe_nets + caffemodel_filename):
                print "Caffemodel for cards_" + str(no_cards) + "_net not found, first train the network for cards_"\
                     + str(no_cards) + " first!"
                break

            print "Testing..."
            net = caffe.Net(config_path + model_test_filaname, caffe_nets + caffemodel_filename, caffe.TEST)
            labels, features = dataload_lmdb.get_data_for_case_from_lmdb(lmdb_test_path, "00001230")
            
            out = net.forward(**{net.inputs[0]: np.asarray([features])})
            print np.argmax(out["prob"][0]) == labels, "\n", out
            plt.bar(range(10),out["prob"][0])
            pylab.show()
            break
        elif test_net == "n" or test_net == "N":
            break
        else:
            print "Incorrect input, try again!"

    print "\n..........End of script.........."
Exemple #14
0
def run_command_version(options, reactor=None, **kwargs):
    """
    Subcommand "crossbar version".
    """
    log = make_logger()

    # Python
    py_ver = '.'.join([str(x) for x in list(sys.version_info[:3])])
    py_ver_string = "[%s]" % sys.version.replace('\n', ' ')

    if 'pypy_version_info' in sys.__dict__:
        py_ver_detail = "{}-{}".format(
            platform.python_implementation(),
            '.'.join(str(x) for x in sys.pypy_version_info[:3]))
    else:
        py_ver_detail = platform.python_implementation()

    # Twisted / Reactor
    tx_ver = "%s-%s" % (pkg_resources.require("Twisted")[0].version,
                        reactor.__class__.__name__)
    tx_loc = "[%s]" % qual(reactor.__class__)

    # txaio
    txaio_ver = '%s' % pkg_resources.require("txaio")[0].version

    # Autobahn
    ab_ver = pkg_resources.require("autobahn")[0].version
    ab_loc = "[%s]" % qual(WebSocketProtocol)

    # UTF8 Validator
    s = qual(Utf8Validator)
    if 'wsaccel' in s:
        utf8_ver = 'wsaccel-%s' % pkg_resources.require('wsaccel')[0].version
    elif s.startswith('autobahn'):
        utf8_ver = 'autobahn'
    else:
        # could not detect UTF8 validator type/version
        utf8_ver = '?'
    utf8_loc = "[%s]" % qual(Utf8Validator)

    # XOR Masker
    s = qual(XorMaskerNull)
    if 'wsaccel' in s:
        xor_ver = 'wsaccel-%s' % pkg_resources.require('wsaccel')[0].version
    elif s.startswith('autobahn'):
        xor_ver = 'autobahn'
    else:
        # could not detect XOR masker type/version
        xor_ver = '?'
    xor_loc = "[%s]" % qual(XorMaskerNull)

    # JSON Serializer
    supported_serializers = ['JSON']
    from autobahn.wamp.serializer import JsonObjectSerializer
    json_ver = JsonObjectSerializer.JSON_MODULE.__name__

    # If it's just 'json' then it's the stdlib one...
    if json_ver == 'json':
        json_ver = 'stdlib'
    else:
        json_ver = (json_ver +
                    "-%s") % pkg_resources.require(json_ver)[0].version

    # MsgPack Serializer
    try:
        import umsgpack  # noqa
        msgpack_ver = 'u-msgpack-python-%s' % pkg_resources.require(
            'u-msgpack-python')[0].version
        supported_serializers.append('MessagePack')
    except ImportError:
        msgpack_ver = '-'

    # CBOR Serializer
    try:
        import cbor  # noqa
        cbor_ver = 'cbor-%s' % pkg_resources.require('cbor')[0].version
        supported_serializers.append('CBOR')
    except ImportError:
        cbor_ver = '-'

    # UBJSON Serializer
    try:
        import ubjson  # noqa
        ubjson_ver = 'ubjson-%s' % pkg_resources.require(
            'py-ubjson')[0].version
        supported_serializers.append('UBJSON')
    except ImportError:
        ubjson_ver = '-'

    # LMDB
    try:
        import lmdb  # noqa
        lmdb_lib_ver = '.'.join([str(x) for x in lmdb.version()])
        lmdb_ver = '{}/lmdb-{}'.format(
            pkg_resources.require('lmdb')[0].version, lmdb_lib_ver)
    except ImportError:
        lmdb_ver = '-'

    # Release Public Key
    release_pubkey = _read_release_pubkey()

    def decorate(text):
        return click.style(text, fg='yellow', bold=True)

    Node = node_classes[options.personality][u'class']

    for line in Node.BANNER.splitlines():
        log.info(decorate("{:>40}".format(line)))

    pad = " " * 22

    log.info(" Crossbar.io        : {ver} ({personality})",
             ver=decorate(crossbar.__version__),
             personality=Node.PERSONALITY)
    log.info("   Autobahn         : {ver} (with {serializers})",
             ver=decorate(ab_ver),
             serializers=', '.join(supported_serializers))
    log.trace("{pad}{debuginfo}", pad=pad, debuginfo=decorate(ab_loc))
    log.debug("     txaio             : {ver}", ver=decorate(txaio_ver))
    log.debug("     UTF8 Validator    : {ver}", ver=decorate(utf8_ver))
    log.trace("{pad}{debuginfo}", pad=pad, debuginfo=decorate(utf8_loc))
    log.debug("     XOR Masker        : {ver}", ver=decorate(xor_ver))
    log.trace("{pad}{debuginfo}", pad=pad, debuginfo=decorate(xor_loc))
    log.debug("     JSON Codec        : {ver}", ver=decorate(json_ver))
    log.debug("     MessagePack Codec : {ver}", ver=decorate(msgpack_ver))
    log.debug("     CBOR Codec        : {ver}", ver=decorate(cbor_ver))
    log.debug("     UBJSON Codec      : {ver}", ver=decorate(ubjson_ver))
    log.info("   Twisted          : {ver}", ver=decorate(tx_ver))
    log.trace("{pad}{debuginfo}", pad=pad, debuginfo=decorate(tx_loc))
    log.info("   LMDB             : {ver}", ver=decorate(lmdb_ver))
    log.info("   Python           : {ver}/{impl}",
             ver=decorate(py_ver),
             impl=decorate(py_ver_detail))
    log.trace("{pad}{debuginfo}", pad=pad, debuginfo=decorate(py_ver_string))
    log.info(" OS                 : {ver}", ver=decorate(platform.platform()))
    log.info(" Machine            : {ver}", ver=decorate(platform.machine()))
    log.info(" Release key        : {release_pubkey}",
             release_pubkey=decorate(release_pubkey[u'base64']))
    log.info("")
Exemple #15
0
def _get_versions(reactor):
    v = Versions()

    v.executable = os.path.realpath(sys.executable)

    v.platform = platform.platform()
    v.machine = platform.machine()

    # Python
    v.py_ver = '.'.join([str(x) for x in list(sys.version_info[:3])])
    v.py_ver_string = "%s" % sys.version.replace('\n', ' ')

    if 'pypy_version_info' in sys.__dict__:
        v.py_ver_detail = "{}-{}".format(
            platform.python_implementation(),
            '.'.join(str(x) for x in sys.pypy_version_info[:3]))
    else:
        v.py_ver_detail = platform.python_implementation()

    # Pyinstaller (frozen EXE)
    v.py_is_frozen = getattr(sys, 'frozen', False)

    # Twisted / Reactor
    v.tx_ver = "%s-%s" % (_get_version('twisted'), reactor.__class__.__name__)
    v.tx_loc = "%s" % qual(reactor.__class__)

    # txaio
    v.txaio_ver = _get_version('txaio')

    # Autobahn
    v.ab_ver = _get_version('autobahn')
    v.ab_loc = "%s" % qual(WebSocketProtocol)

    # UTF8 Validator
    s = qual(Utf8Validator)
    if 'wsaccel' in s:
        v.utf8_ver = 'wsaccel-%s' % _get_version('wsaccel')
    elif s.startswith('autobahn'):
        v.utf8_ver = 'autobahn'
    else:
        # could not detect UTF8 validator type/version
        v.utf8_ver = '?'
    v.utf8_loc = "%s" % qual(Utf8Validator)

    # XOR Masker
    s = qual(XorMaskerNull)
    if 'wsaccel' in s:
        v.xor_ver = 'wsaccel-%s' % _get_version('wsaccel')
    elif s.startswith('autobahn'):
        v.xor_ver = 'autobahn'
    else:
        # could not detect XOR masker type/version
        v.xor_ver = '?'
    v.xor_loc = "%s" % qual(XorMaskerNull)

    # JSON Serializer
    supported_serializers = ['JSON']
    from autobahn.wamp.serializer import JsonObjectSerializer
    json_ver = JsonObjectSerializer.JSON_MODULE.__name__

    # If it's just 'json' then it's the stdlib one...
    if json_ver == 'json':
        v.json_ver = 'stdlib'
    else:
        v.json_ver = (json_ver + "-%s") % _get_version(json_ver)

    # MsgPack Serializer
    try:
        from autobahn.wamp.serializer import MsgPackObjectSerializer
        msgpack = MsgPackObjectSerializer.MSGPACK_MODULE
        v.msgpack_ver = '{}-{}'.format(msgpack.__name__, _get_version(msgpack))
        supported_serializers.append('MessagePack')
    except ImportError:
        pass

    # CBOR Serializer
    try:
        from autobahn.wamp.serializer import CBORObjectSerializer
        cbor = CBORObjectSerializer.CBOR_MODULE
        v.cbor_ver = '{}-{}'.format(cbor.__name__, _get_version(cbor))
        supported_serializers.append('CBOR')
    except ImportError:
        pass

    # UBJSON Serializer
    try:
        from autobahn.wamp.serializer import UBJSONObjectSerializer
        ubjson = UBJSONObjectSerializer.UBJSON_MODULE
        v.ubjson_ver = '{}-{}'.format(ubjson.__name__, _get_version(ubjson))
        supported_serializers.append('UBJSON')
    except ImportError:
        pass

    # Flatbuffers Serializer
    try:
        from autobahn.wamp.serializer import FlatBuffersObjectSerializer
        flatbuffers = FlatBuffersObjectSerializer.FLATBUFFERS_MODULE
        v.flatbuffers_ver = '{}-{}'.format(flatbuffers.__name__,
                                           _get_version(flatbuffers))
        supported_serializers.append('Flatbuffers')
    except ImportError:
        pass

    v.supported_serializers = supported_serializers

    # LMDB
    try:
        import lmdb  # noqa
        lmdb_lib_ver = '.'.join([str(x) for x in lmdb.version()])
        v.lmdb_ver = '{}/lmdb-{}'.format(_get_version(lmdb), lmdb_lib_ver)
    except ImportError:
        pass

    # crossbar
    v.crossbar_ver = crossbar.__version__

    # crossbarfx
    try:
        import crossbarfx  # noqa
        v.crossbarfx_ver = _get_version(crossbarfx)
    except ImportError:
        pass

    # zlmdb
    try:
        import zlmdb  # noqa
        v.zlmdb_ver = _get_version(zlmdb)
    except ImportError:
        pass

    # numpy
    try:
        import numpy  # noqa
        v.numpy_ver = _get_version(numpy)
    except ImportError:
        pass

    # Release Public Key
    from crossbar.common.key import _read_release_key
    release_pubkey = _read_release_key()
    v.release_pubkey = release_pubkey['base64']

    return v
Exemple #16
0
from __future__ import with_statement
import os
import sys
import unittest
import weakref

import testlib
from testlib import B
from testlib import OCT
from testlib import INT_TYPES
from testlib import UnicodeType

import lmdb

# Whether we have the patch that allows env.copy* to take a txn
have_txn_patch = lmdb.version(subpatch=True)[3]

NO_READERS = UnicodeType('(no active readers)\n')

try:
    PAGE_SIZE = os.sysconf(os.sysconf_names['SC_PAGE_SIZE'])
except (AttributeError, KeyError, OSError):
    PAGE_SIZE = 4096


class VersionTest(unittest.TestCase):
    def tearDown(self):
        testlib.cleanup()

    def test_version(self):
        ver = lmdb.version()
Exemple #17
0
def version():
    return lmdb.version()
Exemple #18
0
 def test_version_subpatch(self):
     ver = lmdb.version(subpatch=True)
     assert len(ver) == 4
     assert all(isinstance(i, INT_TYPES) for i in ver)
     assert all(i >= 0 for i in ver)
Exemple #19
0
import caffe
caffe.set_mode_gpu()
import lmdb

from sklearn.cross_validation import StratifiedShuffleSplit
import pandas as pd
import numpy as np

import matplotlib.pyplot as plt

print "OS:     ", platform.platform()
print "Python: ", sys.version.split("\n")[0]
print "CUDA:   ", subprocess.Popen(
    ["nvcc", "--version"],
    stdout=subprocess.PIPE).communicate()[0].split("\n")[3]
print "LMDB:   ", ".".join([str(i) for i in lmdb.version()])

df = pd.read_csv("train.csv", sep=",")
features = df.ix[:, 1:-1].as_matrix()
labels = df.ix[:, -1].as_matrix()

vec_log = np.vectorize(lambda x: np.log(x + 1))
vec_int = np.vectorize(lambda str: int(str[-1]) - 1)

features = vec_log(features)
labels = vec_int(labels)

sss = StratifiedShuffleSplit(labels, 1, test_size=0.02, random_state=0)
sss = list(sss)[0]

features_training = features[sss[0], ]
Exemple #20
0
def run_command_version(options, reactor=None, **kwargs):
    """
    Subcommand "crossbar version".
    """
    log = make_logger()

    # Python
    py_ver = '.'.join([str(x) for x in list(sys.version_info[:3])])
    py_ver_string = "[%s]" % sys.version.replace('\n', ' ')

    if 'pypy_version_info' in sys.__dict__:
        py_ver_detail = "{}-{}".format(platform.python_implementation(), '.'.join(str(x) for x in sys.pypy_version_info[:3]))
    else:
        py_ver_detail = platform.python_implementation()

    # Pyinstaller (frozen EXE)
    py_is_frozen = getattr(sys, 'frozen', False)

    # Twisted / Reactor
    tx_ver = "%s-%s" % (get_version('twisted'), reactor.__class__.__name__)
    tx_loc = "[%s]" % qual(reactor.__class__)

    # txaio
    txaio_ver = get_version('txaio')

    # Autobahn
    ab_ver = get_version('autobahn')
    ab_loc = "[%s]" % qual(WebSocketProtocol)

    # UTF8 Validator
    s = qual(Utf8Validator)
    if 'wsaccel' in s:
        utf8_ver = 'wsaccel-%s' % get_version('wsaccel')
    elif s.startswith('autobahn'):
        utf8_ver = 'autobahn'
    else:
        # could not detect UTF8 validator type/version
        utf8_ver = '?'
    utf8_loc = "[%s]" % qual(Utf8Validator)

    # XOR Masker
    s = qual(XorMaskerNull)
    if 'wsaccel' in s:
        xor_ver = 'wsaccel-%s' % get_version('wsaccel')
    elif s.startswith('autobahn'):
        xor_ver = 'autobahn'
    else:
        # could not detect XOR masker type/version
        xor_ver = '?'
    xor_loc = "[%s]" % qual(XorMaskerNull)

    # JSON Serializer
    supported_serializers = ['JSON']
    from autobahn.wamp.serializer import JsonObjectSerializer
    json_ver = JsonObjectSerializer.JSON_MODULE.__name__

    # If it's just 'json' then it's the stdlib one...
    if json_ver == 'json':
        json_ver = 'stdlib'
    else:
        json_ver = (json_ver + "-%s") % get_version(json_ver)

    # MsgPack Serializer
    try:
        import umsgpack  # noqa
        msgpack_ver = 'u-msgpack-python-%s' % get_version(umsgpack)
        supported_serializers.append('MessagePack')
    except ImportError:
        msgpack_ver = '-'

    # CBOR Serializer
    try:
        import cbor  # noqa
        cbor_ver = 'cbor-%s' % get_version(cbor)
        supported_serializers.append('CBOR')
    except ImportError:
        cbor_ver = '-'

    # UBJSON Serializer
    try:
        import ubjson  # noqa
        ubjson_ver = 'ubjson-%s' % get_version(ubjson)
        supported_serializers.append('UBJSON')
    except ImportError:
        ubjson_ver = '-'

    # LMDB
    try:
        import lmdb  # noqa
        lmdb_lib_ver = '.'.join([str(x) for x in lmdb.version()])
        lmdb_ver = '{}/lmdb-{}'.format(get_version(lmdb), lmdb_lib_ver)
    except ImportError:
        lmdb_ver = '-'

    # crossbarfabric (only Crossbar.io FABRIC)
    try:
        from crossbarfabric._version import __version__ as crossbarfabric_ver  # noqa
    except ImportError:
        crossbarfabric_ver = '-'

    # crossbarfabriccenter (only Crossbar.io FABRIC CENTER)
    try:
        from crossbarfabriccenter._version import __version__ as crossbarfabriccenter_ver  # noqa
    except ImportError:
        crossbarfabriccenter_ver = '-'

    # txaio-etcd (only Crossbar.io FABRIC CENTER)
    try:
        import txaioetcd  # noqa
        txaioetcd_ver = get_version(txaioetcd)
    except ImportError:
        txaioetcd_ver = '-'

    # Release Public Key
    from crossbar.controller.node import _read_release_pubkey
    release_pubkey = _read_release_pubkey()

    def decorate(text):
        return click.style(text, fg='yellow', bold=True)

    Node = get_installed_personalities()[options.personality].NodeKlass

    for line in Node.BANNER.splitlines():
        log.info(decorate("{:>40}".format(line)))

    pad = " " * 22

    log.info(" Crossbar.io        : {ver} ({personality})", ver=decorate(crossbar.__version__), personality=Node.PERSONALITY)
    log.info("   Autobahn         : {ver} (with {serializers})", ver=decorate(ab_ver), serializers=', '.join(supported_serializers))
    log.trace("{pad}{debuginfo}", pad=pad, debuginfo=decorate(ab_loc))
    log.debug("     txaio          : {ver}", ver=decorate(txaio_ver))
    log.debug("     UTF8 Validator : {ver}", ver=decorate(utf8_ver))
    log.trace("{pad}{debuginfo}", pad=pad, debuginfo=decorate(utf8_loc))
    log.debug("     XOR Masker     : {ver}", ver=decorate(xor_ver))
    log.trace("{pad}{debuginfo}", pad=pad, debuginfo=decorate(xor_loc))
    log.debug("     JSON Codec     : {ver}", ver=decorate(json_ver))
    log.debug("     MsgPack Codec  : {ver}", ver=decorate(msgpack_ver))
    log.debug("     CBOR Codec     : {ver}", ver=decorate(cbor_ver))
    log.debug("     UBJSON Codec   : {ver}", ver=decorate(ubjson_ver))
    log.info("   Twisted          : {ver}", ver=decorate(tx_ver))
    log.trace("{pad}{debuginfo}", pad=pad, debuginfo=decorate(tx_loc))
    log.info("   LMDB             : {ver}", ver=decorate(lmdb_ver))
    log.info("   Python           : {ver}/{impl}", ver=decorate(py_ver), impl=decorate(py_ver_detail))
    log.trace("{pad}{debuginfo}", pad=pad, debuginfo=decorate(py_ver_string))
    if options.personality in (u'fabric', u'fabriccenter'):
        log.info(" Crossbar.io Fabric : {ver}", ver=decorate(crossbarfabric_ver))
    if options.personality == u'fabriccenter':
        log.info(" Crossbar.io FC     : {ver}", ver=decorate(crossbarfabriccenter_ver))
        log.debug("   txaioetcd        : {ver}", ver=decorate(txaioetcd_ver))
    log.info(" Frozen executable  : {py_is_frozen}", py_is_frozen=decorate('yes' if py_is_frozen else 'no'))
    log.info(" Operating system   : {ver}", ver=decorate(platform.platform()))
    log.info(" Host machine       : {ver}", ver=decorate(platform.machine()))
    log.info(" Release key        : {release_pubkey}", release_pubkey=decorate(release_pubkey[u'base64']))
    log.info("")
Exemple #21
0
def _get_versions(reactor):
    v = Versions()

    v.executable = os.path.realpath(sys.executable)

    v.platform = platform.platform()
    v.machine = platform.machine()

    # Python
    v.py_ver = '.'.join([str(x) for x in list(sys.version_info[:3])])
    v.py_ver_string = "%s" % sys.version.replace('\n', ' ')

    if 'pypy_version_info' in sys.__dict__:
        v.py_ver_detail = "{}-{}".format(platform.python_implementation(), '.'.join(str(x) for x in sys.pypy_version_info[:3]))
    else:
        v.py_ver_detail = platform.python_implementation()

    # Pyinstaller (frozen EXE)
    v.py_is_frozen = getattr(sys, 'frozen', False)

    # Twisted / Reactor
    v.tx_ver = "%s-%s" % (_get_version('twisted'), reactor.__class__.__name__)
    v.tx_loc = "%s" % qual(reactor.__class__)

    # txaio
    v.txaio_ver = _get_version('txaio')

    # Autobahn
    v.ab_ver = _get_version('autobahn')
    v.ab_loc = "%s" % qual(WebSocketProtocol)

    # UTF8 Validator
    s = qual(Utf8Validator)
    if 'wsaccel' in s:
        v.utf8_ver = 'wsaccel-%s' % _get_version('wsaccel')
    elif s.startswith('autobahn'):
        v.utf8_ver = 'autobahn'
    else:
        # could not detect UTF8 validator type/version
        v.utf8_ver = '?'
    v.utf8_loc = "%s" % qual(Utf8Validator)

    # XOR Masker
    s = qual(XorMaskerNull)
    if 'wsaccel' in s:
        v.xor_ver = 'wsaccel-%s' % _get_version('wsaccel')
    elif s.startswith('autobahn'):
        v.xor_ver = 'autobahn'
    else:
        # could not detect XOR masker type/version
        v.xor_ver = '?'
    v.xor_loc = "%s" % qual(XorMaskerNull)

    # JSON Serializer
    supported_serializers = ['JSON']
    from autobahn.wamp.serializer import JsonObjectSerializer
    json_ver = JsonObjectSerializer.JSON_MODULE.__name__

    # If it's just 'json' then it's the stdlib one...
    if json_ver == 'json':
        v.json_ver = 'stdlib'
    else:
        v.json_ver = (json_ver + "-%s") % _get_version(json_ver)

    # MsgPack Serializer
    try:
        from autobahn.wamp.serializer import MsgPackObjectSerializer
        msgpack = MsgPackObjectSerializer.MSGPACK_MODULE
        v.msgpack_ver = '{}-{}'.format(msgpack.__name__, _get_version(msgpack))
        supported_serializers.append('MessagePack')
    except ImportError:
        pass

    # CBOR Serializer
    try:
        from autobahn.wamp.serializer import CBORObjectSerializer
        cbor = CBORObjectSerializer.CBOR_MODULE
        v.cbor_ver = '{}-{}'.format(cbor.__name__, _get_version(cbor))
        supported_serializers.append('CBOR')
    except ImportError:
        pass

    # UBJSON Serializer
    try:
        from autobahn.wamp.serializer import UBJSONObjectSerializer
        ubjson = UBJSONObjectSerializer.UBJSON_MODULE
        v.ubjson_ver = '{}-{}'.format(ubjson.__name__, _get_version(ubjson))
        supported_serializers.append('UBJSON')
    except ImportError:
        pass

    # Flatbuffers Serializer
    try:
        from autobahn.wamp.serializer import FlatBuffersObjectSerializer
        flatbuffers = FlatBuffersObjectSerializer.FLATBUFFERS_MODULE
        v.flatbuffers_ver = '{}-{}'.format(flatbuffers.__name__, _get_version(flatbuffers))
        supported_serializers.append('Flatbuffers')
    except ImportError:
        pass

    v.supported_serializers = supported_serializers

    # LMDB
    try:
        import lmdb  # noqa
        lmdb_lib_ver = '.'.join([str(x) for x in lmdb.version()])
        v.lmdb_ver = '{}/lmdb-{}'.format(_get_version(lmdb), lmdb_lib_ver)
    except ImportError:
        pass

    # crossbar
    v.crossbar_ver = crossbar.__version__

    # crossbarfx
    try:
        import crossbarfx  # noqa
        v.crossbarfx_ver = _get_version(crossbarfx)
    except ImportError:
        pass

    # xbr
    try:
        import xbr  # noqa
        v.xbr_ver = _get_version(xbr)
    except ImportError:
        pass

    # zlmdb
    try:
        import zlmdb  # noqa
        v.zlmdb_ver = _get_version(zlmdb)
    except ImportError:
        pass

    # numpy
    try:
        import numpy  # noqa
        v.numpy_ver = _get_version(numpy)
    except ImportError:
        pass

    # Release Public Key
    from crossbar.common.key import _read_release_key
    release_pubkey = _read_release_key()
    v.release_pubkey = release_pubkey[u'base64']

    return v