mirror of
https://github.com/alexgo-io/stacks-puppet-node.git
synced 2026-04-09 08:41:15 +08:00
83 lines
2.2 KiB
Python
83 lines
2.2 KiB
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
Blockstack-client
|
|
~~~~~
|
|
copyright: (c) 2014-2015 by Halfmoon Labs, Inc.
|
|
copyright: (c) 2016 by Blockstack.org
|
|
|
|
This file is part of Blockstack-client.
|
|
|
|
Blockstack-client is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
Blockstack-client is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
You should have received a copy of the GNU General Public License
|
|
along with Blockstack-client. If not, see <http://www.gnu.org/licenses/>.
|
|
"""
|
|
|
|
import logging
|
|
import os
|
|
import zlib
|
|
|
|
if os.environ.get("BLOCKSTACK_DEBUG", None) is not None:
|
|
DEBUG = True
|
|
else:
|
|
DEBUG = False
|
|
|
|
def get_logger(name=None):
|
|
"""
|
|
Get logger
|
|
"""
|
|
|
|
level = logging.CRITICAL
|
|
if DEBUG:
|
|
logging.disable(logging.NOTSET)
|
|
level = logging.DEBUG
|
|
|
|
if name is None:
|
|
name = "<unknown>"
|
|
level = logging.CRITICAL
|
|
|
|
log = logging.getLogger(name=name)
|
|
log.setLevel( level )
|
|
console = logging.StreamHandler()
|
|
console.setLevel( level )
|
|
log_format = ('[%(asctime)s] [%(levelname)s] [%(module)s:%(lineno)d] (' + str(os.getpid()) + ') %(message)s' if DEBUG else '%(message)s')
|
|
formatter = logging.Formatter( log_format )
|
|
console.setFormatter(formatter)
|
|
log.propagate = False
|
|
|
|
if len(log.handlers) > 0:
|
|
for i in xrange(0, len(log.handlers)):
|
|
log.handlers.pop(0)
|
|
|
|
log.addHandler(console)
|
|
return log
|
|
|
|
|
|
def compress_chunk( chunk_buf ):
|
|
"""
|
|
compress a chunk of data
|
|
"""
|
|
data = zlib.compress(chunk_buf, 9)
|
|
return data
|
|
|
|
def decompress_chunk( chunk_buf ):
|
|
"""
|
|
decompress a chunk of data
|
|
"""
|
|
data = zlib.decompress(chunk_buf)
|
|
return data
|
|
|
|
def get_driver_settings_dir(config_path, driver_name):
|
|
"""
|
|
driver-specific state
|
|
"""
|
|
return os.path.join( os.path.dirname(config_path), "drivers/{}".format(driver_name))
|