From fe6b35111c325fe95bff48b95bee3a5d2f31b4c3 Mon Sep 17 00:00:00 2001 From: Arash Ghoreyshi Date: Wed, 5 Jun 2013 13:42:32 -0500 Subject: [PATCH] Add a test file, a configuration file, and various generated files --- barbicanclient/common/config.py | 92 +++ barbicanclient/openstack/.DS_Store | Bin 0 -> 6148 bytes .../openstack/common/gettextutils.py | 50 ++ .../openstack/common/importutils.py | 67 +++ barbicanclient/openstack/common/local.py | 48 ++ barbicanclient/openstack/common/log.py | 558 ++++++++++++++++++ barbicanclient/version.py | 21 + etc/barbicanclient.conf | 10 + tests/client_test.py | 76 +++ 9 files changed, 922 insertions(+) create mode 100644 barbicanclient/common/config.py create mode 100644 barbicanclient/openstack/.DS_Store create mode 100644 barbicanclient/openstack/common/gettextutils.py create mode 100644 barbicanclient/openstack/common/importutils.py create mode 100644 barbicanclient/openstack/common/local.py create mode 100644 barbicanclient/openstack/common/log.py create mode 100644 barbicanclient/version.py create mode 100644 etc/barbicanclient.conf create mode 100644 tests/client_test.py diff --git a/barbicanclient/common/config.py b/barbicanclient/common/config.py new file mode 100644 index 00000000..e5d9d004 --- /dev/null +++ b/barbicanclient/common/config.py @@ -0,0 +1,92 @@ +# Copyright (c) 2013 Rackspace, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +""" +Configuration setup for Barbican Client. +""" + +import logging +import logging.config +import logging.handlers +import os +import sys + +from barbicanclient.version import __version__ +from oslo.config import cfg + +CONF = cfg.CONF +CONF.import_opt('verbose', 'barbicanclient.openstack.common.log') +CONF.import_opt('debug', 'barbicanclient.openstack.common.log') +CONF.import_opt('log_dir', 'barbicanclient.openstack.common.log') +CONF.import_opt('log_file', 'barbicanclient.openstack.common.log') +CONF.import_opt('log_config', 'barbicanclient.openstack.common.log') +CONF.import_opt('log_format', 'barbicanclient.openstack.common.log') +CONF.import_opt('log_date_format', 'barbicanclient.openstack.common.log') +CONF.import_opt('use_syslog', 'barbicanclient.openstack.common.log') +CONF.import_opt('syslog_log_facility', 'barbicanclient.openstack.common.log') + + +def parse_args(args=None, usage=None, default_config_files=None): + CONF(args=args, + project='barbicanclient', + prog='barbicanclient', + version=__version__, + usage=usage, + default_config_files=default_config_files) + + +def setup_logging(): + """ + Sets up the logging options + """ + + if CONF.log_config: + # Use a logging configuration file for all settings... + if os.path.exists(CONF.log_config): + logging.config.fileConfig(CONF.log_config) + return + else: + raise RuntimeError("Unable to locate specified logging " + "config file: %s" % CONF.log_config) + + root_logger = logging.root + if CONF.debug: + root_logger.setLevel(logging.DEBUG) + elif CONF.verbose: + root_logger.setLevel(logging.INFO) + else: + root_logger.setLevel(logging.WARNING) + + formatter = logging.Formatter(CONF.log_format, CONF.log_date_format) + + if CONF.use_syslog: + try: + facility = getattr(logging.handlers.SysLogHandler, + CONF.syslog_log_facility) + except AttributeError: + raise ValueError(_("Invalid syslog facility")) + + handler = logging.handlers.SysLogHandler(address='/dev/log', + facility=facility) + elif CONF.log_file: + logfile = CONF.log_file + if CONF.log_dir: + logfile = os.path.join(CONF.log_dir, logfile) + handler = logging.handlers.WatchedFileHandler(logfile) + else: + handler = logging.StreamHandler(sys.stdout) + + handler.setFormatter(formatter) + root_logger.addHandler(handler) diff --git a/barbicanclient/openstack/.DS_Store b/barbicanclient/openstack/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..94e8390ae962e15cb3acaeb6fc15ce9a113b765a GIT binary patch literal 6148 zcmeHKOH0E*5Z-NTji}Iz(BtB{NNSaO@DM@;k3tGPSkc6Y4a96|QhTV;AozRyH~t=H zb~lG$&LVau?0&QJ*vALi2V;!8%dpQ_hcRYBLFA~^2%2kM4HJyWRUeWi!77~xu?%WD z`imx zdgf=#)b$t2bLD3<@F;yOWeob%L{FkHo85N0>-F*JpeOo6JMW40aA^0$$>1!{cR)HH z*1_S?`Q_Mu$zR_J%^wG}5_FOGpe51H=F^u)z$NL&4hJ zU=C>M!~ii+&j9WZ0t%vIu+XTs4yf?@jQ$oP3h4NjKokZYgM~)$fN-4(s8hLlVsM=f zc46WigM~(&&bS&G`Y|Jyj~A{+2fI+=j5`{sCI*OsDg#a3?BMx-0l!S`BfpwLEn