本文整理汇总了Python中Tardis.Util.isMagic方法的典型用法代码示例。如果您正苦于以下问题:Python Util.isMagic方法的具体用法?Python Util.isMagic怎么用?Python Util.isMagic使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tardis.Util
的用法示例。
在下文中一共展示了Util.isMagic方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from Tardis import Util [as 别名]
# 或者: from Tardis.Util import isMagic [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()
示例2: globPath
# 需要导入模块: from Tardis import Util [as 别名]
# 或者: from Tardis.Util import isMagic [as 别名]
def globPath(path, tardis, crypt, first=0):
"""
Glob a path. Only globbs the first
"""
logger.debug("Globbing %s", path)
if not Util.isMagic(path):
return [path]
comps = path.split(os.sep)
results = []
for i in range(first, len(comps)):
if Util.isMagic(comps[i]):
currentPath = os.path.join('/', *comps[:i])
pattern = comps[i]
logger.debug("Globbing in component %d of %s: %s %s", i, path, currentPath, pattern)
# Collect info about the current path (without the globb pattern)
fInfos = collectFileInfo(currentPath, tardis, crypt)
# Collect any directories in that poth
dirs = [(x, fInfos[x['backupset']]) for x in backupSets if fInfos[x['backupset']] and fInfos[x['backupset']]['dir'] == 1]
# And cons up the names which are in those directories
(_, names) = collectDirContents2(tardis, dirs, crypt)
# Filter down any that match
matches = fnmatch.filter(names, pattern)
# Put the paths back together
globbed = sorted([os.path.join('/', currentPath, match, *comps[i+1:]) for match in matches])
logger.debug("Globbed %s: %s", path, globbed)
# And repeat.
for j in globbed:
results += globPath(j, tardis, crypt, i + 1)
break
return results
示例3: main
# 需要导入模块: from Tardis import Util [as 别名]
# 或者: from Tardis.Util import isMagic [as 别名]
def main():
global args, logger
try:
FORMAT = "%(levelname)s : %(message)s"
logging.basicConfig(stream=sys.stderr, format=FORMAT, level=logging.INFO)
logger = logging.getLogger("")
args = processArgs()
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 Exception as e:
logger.error("Caught exception: %s", str(e))
logger.exception(e)