当前位置: 首页>>代码示例>>Python>>正文


Python Util.setupLogging方法代码示例

本文整理汇总了Python中Tardis.Util.setupLogging方法的典型用法代码示例。如果您正苦于以下问题:Python Util.setupLogging方法的具体用法?Python Util.setupLogging怎么用?Python Util.setupLogging使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Tardis.Util的用法示例。


在下文中一共展示了Util.setupLogging方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from Tardis import Util [as 别名]
# 或者: from Tardis.Util import setupLogging [as 别名]
def main():
    global logger
    args = processArgs()
    kwargs = processMountOpts(args.mountopts)
    logger = Util.setupLogging(args.verbose)

    try:
        argsDict = vars(args)
        def getarg(name):
            """ Extract a value from either the kwargs, or the regular args """
            return kwargs.get(name) or argsDict.get(name)

        # Extract the password file and program, if they exist.  Names differ, so getarg doesn't work.
        pwfile = kwargs.get('pwfile') or argsDict.get('passwordfile')
        pwprog = kwargs.get('pwprog') or argsDict.get('passwordprog')

        password = Util.getPassword(getarg('password'), pwfile, pwprog, prompt="Password for %s: " % (getarg('client')))
        args.password = None
        (tardis, cache, crypt) = Util.setupDataConnection(getarg('database'), getarg('client'), password, getarg('keys'), getarg('dbname'), getarg('dbdir'))
    except TardisDB.AuthenticationException as e:
        logger.error("Authentication failed.  Bad password")
        #if args.exceptions:
            #logger.exception(e)
        sys.exit(1)
    except Exception as e:
        logger.error("DB Connection failed: %s", e)
        sys.exit(1)

    delTardisKeys(kwargs)

    fs = TardisFS(tardis, cache, crypt, args)
    FUSE(fs, args.mountpoint[0], debug=args.debug, nothreads=True, foreground=args.foreground, **kwargs)
开发者ID:koldinger,项目名称:Tardis,代码行数:34,代码来源:TardisFS.py

示例2: main

# 需要导入模块: from Tardis import Util [as 别名]
# 或者: from Tardis.Util import setupLogging [as 别名]
def main():
    global logger
    try:
        parseArgs()
        logger = Util.setupLogging(args.verbose)

        if len(args.backup) > 2:
            logger.error(args.backup)
            logger.error("Too many backups (%d) specified.  Only one or two allowed", len(args.backup))
            sys.exit(1)

        password = Util.getPassword(
            args.password, args.passwordfile, args.passwordprog, prompt="Password for %s: " % (args.client)
        )
        args.password = None
        (tardis, cache, crypt) = Util.setupDataConnection(
            args.database, args.client, password, args.keys, args.dbname, args.dbdir
        )
        password = None

        bsets = []
        for i in args.backup:
            bset = getBackupSet(tardis, i)
            if bset:
                logger.debug("Got backupset %s", str(bset))
                logger.debug("backupset: %s", bset["backupset"])
                bsets.append(bset)
            else:
                sys.exit(1)

        if len(bsets) == 1:
            bsets.append(None)

        r = Regenerator.Regenerator(cache, tardis, crypt)
        then = time.asctime(time.localtime(float(bsets[0]["starttime"]))) + "  (" + bsets[0]["name"] + ")"
        if bsets[1]:
            now = time.asctime(time.localtime(float(bsets[1]["starttime"]))) + "  (" + bsets[1]["name"] + ")"
        else:
            now = time.asctime() + "  (filesystem)"

        for f in args.files:
            if bsets[1] is None and os.path.isdir(f):
                diffDir(os.path.abspath(f), r, bsets, tardis, crypt, args.reduce, now, then, recurse=args.recurse)
            else:
                (i0, _) = getFileInfo(os.path.abspath(f), bsets[0]["backupset"], tardis, crypt, args.reduce)
                if i0 and i0["dir"]:
                    (i1, _) = getFileInfo(os.path.abspath(f), bsets[1]["backupset"], tardis, crypt, args.reduce)
                    if i1 and i1["dir"]:
                        diffDir(
                            os.path.abspath(f), r, bsets, tardis, crypt, args.reduce, now, then, recurse=args.recurse
                        )
                        continue
                diffFile(f, r, bsets, tardis, crypt, args.reduce, args.recurse, now, then)
    except KeyboardInterrupt:
        pass
    except Exception as e:
        logger.error("Caught exception: %s", str(e))
        logger.exception(e)
开发者ID:koldinger,项目名称:Tardis,代码行数:60,代码来源:Diff.py

示例3: main

# 需要导入模块: from Tardis import Util [as 别名]
# 或者: from Tardis.Util import setupLogging [as 别名]
def main():
    global args, logger
    tardis = None
    try:
        args = processArgs()
        logger = Util.setupLogging(args.verbose)

        setColors(Defaults.getDefault('TARDIS_LS_COLORS'))

        # Load any password info
        password = Util.getPassword(args.password, args.passwordfile, args.passwordprog, prompt="Password for %s: " % (args.client))
        args.password = None

        (tardis, _, crypt) = Util.setupDataConnection(args.database, args.client, password, args.keys, args.dbname, args.dbdir)

        setupDisplay(tardis)

        if args.headers:
            doprint("Client: %s    DB: %s" %(args.client, args.database), color=colors['name'], eol=True)

        if args.glob:
            directories = []
            for d in args.directories:
                if not Util.isMagic(d):
                    directories.append(d)
                else:
                    directories += globPath(os.path.abspath(d), tardis, crypt)
        else:
            directories = args.directories

        for d in directories:
            d = os.path.abspath(d)
            if args.realpath:
                d = os.path.realpath(d)
            fInfos = collectFileInfo(d, tardis, crypt)
            recurse = args.maxdepth if args.recurse else 0
            processFile(d, fInfos, tardis, crypt, printContents=(not args.dirinfo), recurse=recurse)
    except KeyboardInterrupt:
        pass
    except TardisDB.AuthenticationException as e:
        logger.error("Authentication failed.  Bad password")
        if args.exceptions:
            logger.exception(e)
    except Exception as e:
        logger.error("Caught exception: %s", str(e))
        if args.exceptions:
            logger.exception(e)
    finally:
        if tardis:
            tardis.close()
开发者ID:koldinger,项目名称:Tardis,代码行数:52,代码来源:List.py

示例4: main

# 需要导入模块: from Tardis import Util [as 别名]
# 或者: from Tardis.Util import setupLogging [as 别名]
def main():
    global logger, crypt, tardis, args, owMode
    args = parseArgs()
    logger = Util.setupLogging(args.verbose, stream=sys.stderr)

    try:
        password = Util.getPassword(args.password, args.passwordfile, args.passwordprog, prompt="Password for %s: " % (args.client))
        args.password = None
        (tardis, cache, crypt) = Util.setupDataConnection(args.database, args.client, password, args.keys, args.dbname, args.dbdir)

        r = Regenerator.Regenerator(cache, tardis, crypt=crypt)
    except TardisDB.AuthenticationException as e:
        logger.error("Authentication failed.  Bad password")
        #if args.exceptions:
            #logger.exception(e)
        sys.exit(1)
    except Exception as e:
        logger.error("Regeneration failed: %s", e)
        sys.exit(1)

    try:
        bset = False

        if args.date:
            cal = parsedatetime.Calendar()
            (then, success) = cal.parse(args.date)
            if success:
                timestamp = time.mktime(then)
                logger.info("Using time: %s", time.asctime(then))
                bsetInfo = tardis.getBackupSetInfoForTime(timestamp)
                if bsetInfo and bsetInfo['backupset'] != 1:
                    bset = bsetInfo['backupset']
                    logger.debug("Using backupset: %s %d", bsetInfo['name'], bsetInfo['backupset'])
                else:
                    logger.critical("No backupset at date: %s (%s)", args.date, time.asctime(then))
                    sys.exit(1)
            else:
                logger.critical("Could not parse date string: %s", args.date)
                sys.exit(1)
        elif args.backup:
            #bsetInfo = tardis.getBackupSetInfo(args.backup)
            bsetInfo = Util.getBackupSet(tardis, args.backup)
            if bsetInfo:
                bset = bsetInfo['backupset']
            else:
                logger.critical("No backupset at for name: %s", args.backup)
                sys.exit(1)

        outputdir = None
        output    = sys.stdout.buffer
        outname   = None
        linkDB    = None

        owMode    = overwriteNames[args.overwrite]

        if args.output:
            if len(args.files) > 1:
                outputdir = mkOutputDir(args.output)
            elif os.path.isdir(args.output):
                outputdir = args.output
            else:
                outname = args.output
        logger.debug("Outputdir: %s  Outname: %s", outputdir, outname)

        if args.hardlinks:
            linkDB = {}

        #if args.cksum and (args.settime or args.setperm):
            #logger.warning("Unable to set time or permissions on files specified by checksum.")

        permChecker = setupPermissionChecks()

        retcode = 0
        hasher = None

        # do the work here
        if args.cksum:
            for i in args.files:
                try:
                    if args.auth:
                        hasher = Util.getHash(crypt)
                    ckname = i
                    if args.recovername:
                        ckname = recoverName(i)
                    f = r.recoverChecksum(i, args.auth)
                    if f:
                        logger.info("Recovering checksum %s", ckname)
                    # Generate an output name
                        if outname:
                            # Note, this should ONLY be true if only one file
                            output = open(outname,  "wb")
                        elif outputdir:
                            outname = os.path.join(outputdir, ckname)
                            if os.path.exists(outname) and owMode == OW_NEVER:
                                logger.warning("File %s exists.  Skipping", outname)
                                continue
                            logger.debug("Writing output to %s", outname)
                            output = open(outname,  "wb")
                        elif outname:
                            # Note, this should ONLY be true if only one file
#.........这里部分代码省略.........
开发者ID:koldinger,项目名称:Tardis,代码行数:103,代码来源:Regenerate.py

示例5: main

# 需要导入模块: from Tardis import Util [as 别名]
# 或者: from Tardis.Util import setupLogging [as 别名]
def main():
    global logger
    parseArgs()
    logger = Util.setupLogging(args.verbose)

    # Commands which cannot be executed on remote databases
    allowRemote = args.command not in ['create', 'upgrade']

    db      = None
    crypt   = None
    cache   = None
    try:
        confirm = args.command in ['setpass', 'create']
        allowNone = args.command not in ['setpass', 'chpass']
        try:
            password = Util.getPassword(args.password, args.passwordfile, args.passwordprog, prompt="Password for %s: " % (args.client), allowNone=allowNone, confirm=confirm)
        except Exception as e:
            logger.critical(str(e))
            if args.exceptions:
                logger.exception(e)
            return -1
            
        if password:
            crypt = TardisCrypto.TardisCrypto(password, args.client)
            args.password = None

        if args.command == 'create':
            return createClient(crypt, password)

        if args.command == 'setpass':
            if not Util.checkPasswordStrength(password):
                return -1

            if not crypt:
                logger.error("No password specified")
                return -1
            return setPassword(crypt, password)

        if args.command == 'chpass':
            return changePassword(crypt, password)

        upgrade = (args.command == 'upgrade')

        try:
            (db, cache, crypt) = getDB(crypt, password, allowRemote=allowRemote, allowUpgrade=upgrade)

            if crypt and args.command != 'keys':
                if args.keys:
                    (f, c) = Util.loadKeys(args.keys, db.getConfigValue('ClientID'))
                else:
                    (f, c) = db.getKeys()
                crypt.setKeys(f, c)
        except TardisDB.AuthenticationException as e:
            logger.error("Authentication failed.  Bad password")
            if args.exceptions:
                logger.exception(e)
            sys.exit(1)
        except Exception as e:
            logger.critical("Unable to connect to database: %s", e)
            if args.exceptions:
                logger.exception(e)
            sys.exit(1)

        if args.command == 'keys':
            return moveKeys(db, crypt)
        elif args.command == 'list':
            return listBSets(db, crypt, cache)
        elif args.command == 'files':
            return listFiles(db, crypt)
        elif args.command == 'info':
            return bsetInfo(db)
        elif args.command == 'purge':
            return purge(db, cache)
        elif args.command == 'delete':
            return deleteBsets(db, cache)
        elif args.command == 'priority':
            return setPriority(db)
        elif args.command == 'rename':
            return renameSet(db)
        elif args.command == 'getconfig':
            return getConfig(db)
        elif args.command == 'setconfig':
            return setConfig(db)
        elif args.command == 'orphans':
            return removeOrphans(db, cache)
        elif args.command == 'upgrade':
            return
    except KeyboardInterrupt:
        pass
    except TardisDB.AuthenticationException as e:
        logger.error("Authentication failed.  Bad password")
        sys.exit(1)
    except Exception as e:
        logger.error("Caught exception: %s", str(e))
        if args.exceptions:
            logger.exception(e)
    finally:
        if db:
            db.close()
开发者ID:koldinger,项目名称:Tardis,代码行数:101,代码来源:Sonic.py


注:本文中的Tardis.Util.setupLogging方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。