本文整理汇总了Python中Tardis.Util.getHash方法的典型用法代码示例。如果您正苦于以下问题:Python Util.getHash方法的具体用法?Python Util.getHash怎么用?Python Util.getHash使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tardis.Util
的用法示例。
在下文中一共展示了Util.getHash方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from Tardis import Util [as 别名]
# 或者: from Tardis.Util import getHash [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
#.........这里部分代码省略.........
示例2: recoverObject
# 需要导入模块: from Tardis import Util [as 别名]
# 或者: from Tardis.Util import getHash [as 别名]
def recoverObject(regenerator, info, bset, outputdir, path, linkDB, name=None, authenticate=True):
"""
Main recovery routine. Recover an object, based on the info object, and put it in outputdir.
"""
retCode = 0
outname = None
skip = False
hasher = None
try:
if info:
realname = info['name']
if args.crypt and crypt:
realname = crypt.decryptFilename(realname)
if name:
# This should only happen only one file specified.
outname = name
elif outputdir:
outname = os.path.abspath(os.path.join(outputdir, realname))
if outname and not checkOverwrite(outname, info):
skip = True
try:
logger.warning("Skipping existing file: %s %s", Util.shortPath(path), notSame(path, outname, '(' + Util.shortPath(outname) + ')'))
except Exception:
pass
# First, determine if we're in a linking situation
if linkDB is not None and info['nlinks'] > 1 and not info['dir']:
key = (info['inode'], info['device'])
if key in linkDB:
logger.info("Linking %s to %s", outname, linkDB[key])
os.link(linkDB[key], outname)
skip = True
else:
linkDB[key] = outname
# If it's a directory, create the directory, and recursively process it
if info['dir']:
if not outname:
#logger.error("Cannot regenerate directory %s without outputdir specified", path)
raise Exception("Cannot regenerate directory %s without outputdir specified" % (path))
try:
logger.info("Processing directory %s", Util.shortPath(path))
except Exception:
pass
contents = list(tardis.readDirectory((info['inode'], info['device']), bset))
# Make sure an output directory is specified (really only useful at the top level)
if not os.path.exists(outname):
os.mkdir(outname)
dirInode = (info['inode'], info['device'])
# For each file in the directory, regenerate it.
for i in contents:
name = i['name']
# Get the Info
childInfo = tardis.getFileInfoByName(name, dirInode, bset)
# Decrypt filename, and make it UTF-8.
if args.crypt and crypt:
name = crypt.decryptFilename(name)
else:
name = name
# Recurse into the child, if it exists.
if childInfo:
try:
if args.recurse or not childInfo['dir']:
recoverObject(regenerator, childInfo, bset, outname, os.path.join(path, name), linkDB, authenticate=authenticate)
except Exception as e:
logger.error("Could not recover %s in %s", name, path)
if args.exceptions:
logger.exception(e)
else:
retCode += 1
elif not skip:
myname = outname if outname else "stdout"
logger.info("Recovering file %s %s", Util.shortPath(path), notSame(path, myname, " => " + Util.shortPath(myname)))
checksum = info['checksum']
i = regenerator.recoverChecksum(checksum, authenticate)
if i:
if authenticate:
hasher = Util.getHash(crypt)
if info['link']:
# read and make a link
i.seek(0)
x = i.read(16 * 1024)
if outname:
os.symlink(x, outname)
else:
logger.warning("No name specified for link: %s", x)
if hasher:
hasher.update(x)
else:
#.........这里部分代码省略.........