本文整理汇总了Python中config.Configuration.get方法的典型用法代码示例。如果您正苦于以下问题:Python Configuration.get方法的具体用法?Python Configuration.get怎么用?Python Configuration.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类config.Configuration
的用法示例。
在下文中一共展示了Configuration.get方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from config import Configuration [as 别名]
# 或者: from config.Configuration import get [as 别名]
def run(self):
config = Configuration()
jid = config.get('connection', 'jid')
password = config.get('connection', 'password')
resource = config.get('connection', 'resource')
debug = config.getboolean('connection', 'debug')
bot = UpwalkJabberBot(jid, password, resource, debug)
bot.serve_forever()
示例2: __init__
# 需要导入模块: from config import Configuration [as 别名]
# 或者: from config.Configuration import get [as 别名]
def __init__(self, mq_server=None, mq_name=None, logger=None):
"""__init__
:param mq_server:
:param mq_name:
"""
self.mq_server = mq_server if mq_server else Configuration.get("mq_server")
self.mq_name = mq_name if mq_name else Configuration.get("mq_name")
connection = pika.BlockingConnection(
pika.ConnectionParameters(host=self.mq_server))
self.mq_channel = connection.channel()
self.mq_channel.queue_declare(self.mq_name, durable=True)
self.logger = logger if logger else Logger.get(self.__class__.__name__)
示例3: __init__
# 需要导入模块: from config import Configuration [as 别名]
# 或者: from config.Configuration import get [as 别名]
def __init__(self, mq_server=None, mq_name=None, logger=None):
"""__init__
:param mq_server:
:param mq_name:
:param logger:
"""
self.mq_server = mq_server if mq_server else Configuration.get("mq_server")
self.mq_name = mq_name if mq_name else Configuration.get("mq_name")
self.mq_connection = pika.BlockingConnection(
pika.ConnectionParameters(host=self.mq_server))
self.mq_channel = self.mq_connection.channel()
tmp_queue = self.mq_channel.queue_declare(exclusive=True)
self.callback_queue = tmp_queue.method.queue
self.mq_channel.basic_consume(self.on_resonse, no_ack=True, queue=self.callback_queue)
self.logger = logger if logger else Logger.get(self.__class__.__name__)
示例4: setup_logging
# 需要导入模块: from config import Configuration [as 别名]
# 或者: from config.Configuration import get [as 别名]
def setup_logging():
"""
Set up logging module according to options in application's configuration
file.
"""
import logging
import os.path
from twisted.python import log
from config import Configuration
config = Configuration()
levels_map = {'CRITICAL': logging.CRITICAL, 'ERROR': logging.ERROR,
'WARNING': logging.WARNING, 'INFO': logging.INFO,
'DEBUG': logging.DEBUG}
level_str = config.get('logging', 'level')
filename = config.get('logging', 'filename')
try:
level = levels_map[level_str]
except KeyError:
default = logging.INFO
print ('Unknown logging level %s, using default %s'
% (level_str, logging.getLevelName(default)))
level = default
if filename is None or filename == '':
filename = 'stdout'
if filename == 'stdout':
filepath = None
else:
filepath = os.path.join(get_app_dir(), filename)
# http://twistedmatrix.com/documents/current/core/howto/logging.html#auto3
observer = log.PythonLoggingObserver()
observer.start()
print ("Openning log '%s' with level %s"
% (filepath if filepath else filename, logging.getLevelName(level)))
logging.basicConfig(level=level, filename=filepath)
示例5: setup
# 需要导入模块: from config import Configuration [as 别名]
# 或者: from config.Configuration import get [as 别名]
def setup(self, log_folder=None, file_name="stock_tracer_{0}.log"):
"""setup
:param log_folder:
:param file_name:
"""
log_config = Configuration.get("logging")
logger = logging.getLogger('stock_tracer')
logger.setLevel(logging.DEBUG)
formatter = logging.Formatter('[%(asctime)s] - [%(name)s] - [%(levelname)s] - %(message)s')
# create file log
if log_config["file"]:
log_folder = log_folder if log_folder else DEFAULT_LOGFOLDER
if not path.exists(log_folder):
makedirs(log_folder)
log_file_name = file_name.format(datetime.now().strftime("%Y-%m-%d"))
fh = logging.FileHandler(path.join(log_folder, log_file_name))
fh.setLevel(logging.DEBUG)
fh.setFormatter(formatter)
logger.addHandler(fh)
# create console log
if log_config["console"]:
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
ch.setFormatter(formatter)
logger.addHandler(ch)
# create es log
if log_config["es"]:
es_logging_handler = ESLoggingHandler([{'host': Configuration.get('es_host'), 'port': 9200}],
es_index_name="stock_log")
es_logging_handler.setLevel(logging.DEBUG)
es_logging_handler.setFormatter(formatter)
logger.addHandler(es_logging_handler)
self.is_initialized = True
示例6: get
# 需要导入模块: from config import Configuration [as 别名]
# 或者: from config.Configuration import get [as 别名]
def get(self):
self.response.headers['Content-Type'] = 'application/pdf'
config = Configuration()
address = 'Ola Nordmann\nNorskeveien 1\n9876 Olabyen'
member_no = '9876'
access_code = 'BBQLOL'
fee = 400
profile_url = constants.PROFILE_URL
account_no = config.get('GIRO_ACCOUNT_NO')
body_template = Template(config.get('GIRO_TEXT'))
message_template = Template(config.get('GIRO_MESSAGE'))
data = { 'member_no': member_no, 'account_no': account_no, 'access_code': access_code, 'profile_url': profile_url }
pdf = PdfGenerator(member_address=address, club_address=config.get('GIRO_ADDRESS'), account_no=account_no,
member_no=member_no, access_code=access_code, profile_url=profile_url,
heading=config.get('GIRO_SUBJECT'), body=body_template.render(data), fee=fee, due_date='12.12.2012', payment_message=message_template.render(data))
pdf.generate_pdf(self.response.out)
示例7: get
# 需要导入模块: from config import Configuration [as 别名]
# 或者: from config.Configuration import get [as 别名]
def get(self, logger_name):
"""get logging instance
:param logger_name:
"""
if not self.is_initialized:
self.setup(Configuration.get("log_folder"))
if "stock_tracer" not in logger_name:
logger_name = "stock_tracer." + logger_name
logger = logging.getLogger(logger_name)
logger.disabled = False
return logger
示例8: send_welcome_mail
# 需要导入模块: from config import Configuration [as 别名]
# 或者: from config.Configuration import get [as 别名]
def send_welcome_mail(self, member):
"""Send welcom email with attachments"""
config = Configuration()
sender_address = config.get('WELCOME_MAIL_SENDER')
subject = config.get('WELCOME_MAIL_SUBJECT')
account_no = config.get('GIRO_ACCOUNT_NO')
mail_template = Template(config.get('WELCOME_MAIL_TEXT'))
data = {
'member': member,
'year': datetime.date.today().year,
'accountno': account_no,
'profile_url': constants.PROFILE_URL
}
body = mail_template.render(data)
buf = cStringIO.StringIO()
address = member.name + '\n' + member.address + \
'\n' + member.zipcode + ' ' + member.city
if member.country.name != 'Norge':
address = address + '\n' + member.country.name
body_template = Template(config.get('GIRO_TEXT'))
message_template = Template(config.get('GIRO_MESSAGE'))
data = {'member_no': member.number, 'account_no': account_no,
'access_code': member.edit_access_code, 'profile_url': constants.PROFILE_URL}
due_date = datetime.datetime.now() + datetime.timedelta(days=14)
due_date_str = due_date.strftime('%d.%m.%Y')
current_date = datetime.datetime.now()
if current_date.month >= 7:
fee = member.member_type.fee / 2
else:
fee = member.member_type.fee
pdf = PdfGenerator(member_address=address, club_address=config.get('GIRO_ADDRESS'), account_no=account_no,
member_no=member.number, access_code=member.edit_access_code, profile_url=constants.PROFILE_URL,
heading=config.get('GIRO_SUBJECT'), body=body_template.render(data), fee=fee,
due_date=due_date_str, payment_message=message_template.render(data))
pdf.generate_pdf(buf)
mail.send_mail(sender_address, member.email, subject,
body, attachments=[('kontingent.pdf', buf.getvalue())])
示例9: import
# 需要导入模块: from config import Configuration [as 别名]
# 或者: from config.Configuration import get [as 别名]
import os
from api.app import app
from config import Configuration
from core.util.problem_detail import ProblemDetail
from core.app_server import returns_problem_detail
from controller import setup_admin_controllers
from templates import (
admin as admin_template,
admin_sign_in_again as sign_in_again_template,
)
# The secret key is used for signing cookies for admin login
app.secret_key = Configuration.get(Configuration.SECRET_KEY)
@app.before_first_request
def setup_admin():
if getattr(app, 'manager', None) is not None:
setup_admin_controllers(app.manager)
def requires_admin(f):
@wraps(f)
def decorated(*args, **kwargs):
admin = app.manager.admin_sign_in_controller.authenticated_admin_from_request()
if isinstance(admin, ProblemDetail):
return app.manager.admin_sign_in_controller.error_response(admin)
elif isinstance(admin, Response):
return admin
return f(*args, **kwargs)
示例10: __init__
# 需要导入模块: from config import Configuration [as 别名]
# 或者: from config.Configuration import get [as 别名]
def __init__(self, basic_auth_provider=None, oauth_providers=None):
self.basic_auth_provider = basic_auth_provider
self.oauth_providers = oauth_providers or []
self.secret_key = Configuration.get(Configuration.SECRET_KEY)
示例11: instance
# 需要导入模块: from config import Configuration [as 别名]
# 或者: from config.Configuration import get [as 别名]
def instance():
return Configuration.get()
示例12: Flask
# 需要导入模块: from config import Configuration [as 别名]
# 或者: from config.Configuration import get [as 别名]
app = Flask(__name__)
testing = 'TESTING' in os.environ
db_url = Configuration.database_url(testing)
SessionManager.initialize(db_url)
session_factory = SessionManager.sessionmaker(db_url)
_db = flask_scoped_session(session_factory, app)
SessionManager.initialize_data(_db)
app.config['BABEL_DEFAULT_LOCALE'] = LanguageCodes.three_to_two[Configuration.localization_languages()[0]]
app.config['BABEL_TRANSLATION_DIRECTORIES'] = "../translations"
babel = Babel(app)
import routes
if Configuration.get(Configuration.INCLUDE_ADMIN_INTERFACE):
import admin.routes
debug = Configuration.logging_policy().get("level") == 'DEBUG'
logging.getLogger().info("Application debug mode==%r" % debug)
app.config['DEBUG'] = debug
app.debug = debug
def run():
debug = True
url = Configuration.integration_url(
Configuration.CIRCULATION_MANAGER_INTEGRATION, required=True)
scheme, netloc, path, parameters, query, fragment = urlparse.urlparse(url)
if ':' in netloc:
host, port = netloc.split(':')
port = int(port)
示例13: get
# 需要导入模块: from config import Configuration [as 别名]
# 或者: from config.Configuration import get [as 别名]
log_file_name = file_name.format(datetime.now().strftime("%Y-%m-%d"))
fh = logging.FileHandler(path.join(log_folder, log_file_name))
fh.setLevel(logging.DEBUG)
# create console log
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
# create formatter and add it to the handlers
formatter = logging.Formatter('[%(asctime)s] - [%(name)s] - [%(levelname)s] - %(message)s')
fh.setFormatter(formatter)
ch.setFormatter(formatter)
# add the handlers to the logger
logger.addHandler(fh)
logger.addHandler(ch)
def get(self, logger_name):
"""get logging instance
:param logger_name:
"""
if "stock_tracer" not in logger_name:
logger_name = "stock_tracer." + logger_name
logger = logging.getLogger(logger_name)
logger.disabled = False
return logger
Logger = Logger.getInstance(Configuration.get("log_folder"))
示例14: ConversionProcess
# 需要导入模块: from config import Configuration [as 别名]
# 或者: from config.Configuration import get [as 别名]
class ConversionProcess():
"""
Class impolementing conversion process. Run command defined in application's
configuration file and control it. When process is finished unexpectedly,
log its returncode and stderr and stdout.
State of process coluld be checked by this properties: started, finished,
paused, cancelled, pid. When process is finished its status is in additional
properties: returncode, stderr, stdout.
Process support this operations: run, terminate, pause, resume.
"""
def __init__(self, input_file, sub_file, output_file, log_stdout=False):
"""
Store information about input and output files and subtitles. Store if
log stdout and set object's attributes.
@param input_file str, Path to input file
@param sub_file str, Path to subtitles file
@param output_file str, Path to output file
@param log_stdout bool, Store stdout after process finish
"""
self.input_file = input_file
self.sub_file = sub_file
self.output_file = output_file
self.log_stdout = log_stdout
self.config = Configuration()
self.logger = logging.getLogger(self.__class__.__name__)
self.process_transport = None
self.process_protocol = None
self.started = False
self.finished = False
self.paused = False
self.cancelled = False
self.deferred = defer.Deferred()
self.deferred.addErrback(self.process_exited)
self.pid = None
self.returncode = None
self.stderr = None
self.stdout = None
def run(self):
"""
Star conversion process.
@return t.i.d.Deferred
"""
assert not self.started
conversion_command = self.get_conversion_command()
conversion_command = encode(conversion_command)
args = shlex.split(conversion_command)
executable = args[0]
self.open_stdout_log()
self.open_stderr_log()
proto = WatchingProcessProtocol(self.deferred)
proto.outReceived = lambda data: self.stdout_log.write(data)
proto.errReceived = lambda data: self.stderr_log.write(data)
self.logger.info('Starting conversion process of %s', self.input_file)
kwargs = {}
if sys.platform == 'win32':
import win32process
kwargs['win32flags'] = win32process.CREATE_NO_WINDOW
self.process_transport = reactor.spawnProcess(proto, executable, args, **kwargs)
self.process_protocol = proto
self.pid = self.process_transport.pid
self.started = True
return self.deferred
def terminate(self):
"""
Terminate running process. It means terminate OS's process and cancel
deferred.
"""
if self.finished:
return
self.logger.info('Terminating conversion process of %s', self.input_file)
try:
self.process_transport.signalProcess('TERM')
except error.ProcessExitedAlready:
return # process already exited, so it was callbacked
self.deferred.cancel()
def pause(self):
"""
#.........这里部分代码省略.........