當前位置: 首頁>>代碼示例>>Python>>正文


Python Glusto.create_log方法代碼示例

本文整理匯總了Python中glusto.core.Glusto.create_log方法的典型用法代碼示例。如果您正苦於以下問題:Python Glusto.create_log方法的具體用法?Python Glusto.create_log怎麽用?Python Glusto.create_log使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在glusto.core.Glusto的用法示例。


在下文中一共展示了Glusto.create_log方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: main

# 需要導入模塊: from glusto.core import Glusto [as 別名]
# 或者: from glusto.core.Glusto import create_log [as 別名]
def main():
    """Entry point console script for setuptools.

    Provides a command-line interface to Glusto.

    Currently does nothing useful, but plan to wrap Glusto functionality in a
    CLI interface that can be injected into shell scripts, etc.

    Example:
        # glusto run hostname.example.com "uname -a"
    """
    epilog = ('NOTE: If encountering an "unknown option" issue '
              'with the -t and -n options, use param=\'args\' syntax.'
              '(e.g., -t="-v -x tests")')
    parser = argparse.ArgumentParser(description="Glusto CLI wrapper",
                                     epilog=epilog)
    parser.add_argument("-c", "--config",
                        help="Config file(s) to read.",
                        action="store", dest="config_list",
                        default=None)
    parser.add_argument("--ssh-keyfile",
                        help="SSH keyfile for connections.",
                        action="store", dest="ssh_keyfile")
    parser.add_argument("-l", "--log",
                        help="Default logfile location.",
                        action="store", dest="log_filename",
                        default=None)
    parser.add_argument("--log-level",
                        help="Default log level.",
                        action="store", dest="log_level",
                        default=None)
    parser.add_argument("--pytest",
                        help="Run tests using the pytest framework.",
                        action="store", dest="run_pytest")
    parser.add_argument("--nosetests",
                        help="Run tests using the nose framework.",
                        action="store", dest="run_nosetests")
    parser.add_argument("--unittest",
                        help="Run tests using the unittest framework.",
                        action="store", dest="run_unittest")
    parser.add_argument("-u",
                        help="Run unittests per provided config file.",
                        action="store_true", dest="run_unittest_config")
    parser.add_argument("-d", "--discover",
                        help="Discover unittests from directory.",
                        action="store", dest="discover_dir")
    args = parser.parse_args()

    # read config files and update g.config attributes
    handle_configs(args.config_list)

    # TODO: break everything into separate methods

    # handle actionable config items
    # logging
    # set defaults
    log_name = "glustomain"
    log_filename = "/tmp/glustomain.log"
    log_level = "INFO"
    # override with config
    log_filename = g.config.get('log_filename', log_filename)
    log_level = g.config.get('log_level', log_level)
    # override with CLI options
    if args.log_filename:
        log_filename = args.log_filename
    if args.log_level:
        log_level = args.log_level

    g.log = g.create_log(name=log_name, filename=log_filename,
                         level=log_level)
    print("Log %s created as %s with log level %s" % (log_name, log_filename,
                                                      log_level))

    g.log.info("Starting glusto via main()")
    print "Starting glusto via main()"

    # override ssh_keyfile @ CLI
    if args.ssh_keyfile:
        g.ssh_set_keyfile(args.ssh_keyfile)

    g.show_config(g.config)

    # unittest
    # TODO: functionalize this so it can be used for standalone test scripts
    if args.run_unittest_config or args.discover_dir:
        tsuite = unittest.TestSuite()
        if args.discover_dir:
            unittest_config = {'cli_discover': 'true'}
        else:
            unittest_config = g.config.get('unittest', False)

        if not unittest_config:
            print ("ERROR: Unittest option requires a unittest configuration.")
            return False

        output_junit = unittest_config.get('output_junit', False)
        if output_junit:
            trunner = xmlrunner.XMLTestRunner(output='/tmp/glustoreports')
        else:
            trunner = unittest.TextTestRunner(verbosity=2)
#.........這裏部分代碼省略.........
開發者ID:loadtheaccumulator,項目名稱:glusto,代碼行數:103,代碼來源:main.py


注:本文中的glusto.core.Glusto.create_log方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。