本文整理匯總了Python中Tardis.Util.reducePath方法的典型用法代碼示例。如果您正苦於以下問題:Python Util.reducePath方法的具體用法?Python Util.reducePath怎麽用?Python Util.reducePath使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Tardis.Util
的用法示例。
在下文中一共展示了Util.reducePath方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: collectFileInfo
# 需要導入模塊: from Tardis import Util [as 別名]
# 或者: from Tardis.Util import reducePath [as 別名]
def collectFileInfo(filename, tardis, crypt):
"""
Collect information about a file in all the backupsets
Note that we sometimes need to reduce the pathlength. It's done here, on a directory
by directory basis.
"""
lookup = crypt.encryptPath(filename) if crypt else filename
fInfos = {}
lInfo = {}
if filename == '/':
fInfos = makeFakeRootInfo()
elif args.reduce:
for bset in backupSets:
temp = lookup
temp = Util.reducePath(tardis, bset['backupset'], temp, args.reduce) # No crypt, as we've already run that to get to lookup
if lInfo and lInfo['firstset'] <= bset['backupset'] <= lInfo['lastset']:
fInfos[bset['backupset']] = lInfo
else:
lInfo = tardis.getFileInfoByPath(temp, bset['backupset'])
fInfos[bset['backupset']] = lInfo
else:
fSet = backupSets[0]['backupset']
lSet = backupSets[-1]['backupset']
for (bset, info) in tardis.getFileInfoByPathForRange(lookup, fSet, lSet):
logger.debug("Bset: %s, info: %s", bset, info)
fInfos[bset] = info
return fInfos
示例2: findLastPath
# 需要導入模塊: from Tardis import Util [as 別名]
# 或者: from Tardis.Util import reducePath [as 別名]
def findLastPath(path, reduce):
logger.debug("findLastPath: %s", path)
# Search all the sets in backwards order
bsets = list(tardis.listBackupSets())
for bset in reversed(bsets):
logger.debug("Checking for path %s in %s (%d)", path, bset['name'], bset['backupset'])
tmp = Util.reducePath(tardis, bset['backupset'], os.path.abspath(path), reduce, crypt)
tmp2 = tmp
if args.crypt and crypt:
tmp2 = crypt.encryptPath(tmp)
info = tardis.getFileInfoByPath(tmp2, bset['backupset'])
if info:
logger.debug("Found %s in backupset %s: %s", path, bset['name'], tmp)
return bset['backupset'], tmp, bset['name']
return (None, None, None)
示例3: getFileInfo
# 需要導入模塊: from Tardis import Util [as 別名]
# 或者: from Tardis.Util import reducePath [as 別名]
def getFileInfo(path, bset, tardis, crypt, reducePath):
p = Util.reducePath(tardis, bset, path, reducePath, crypt)
e = crypt.encryptPath(p) if crypt else p
info = tardis.getFileInfoByPath(e, bset)
return info, p
示例4: main
# 需要導入模塊: from Tardis import Util [as 別名]
# 或者: from Tardis.Util import reducePath [as 別名]
#.........這裏部分代碼省略.........
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
if os.path.exists(outname) and owMode == OW_NEVER:
logger.warning("File %s exists. Skipping", outname)
continue
output = file(outname, "wb")
try:
x = f.read(64 * 1024)
while x:
output.write(x)
if hasher:
hasher.update(x)
x = f.read(64 * 1024)
except Exception as e:
logger.error("Unable to read file: {}: {}".format(i, repr(e)))
raise
finally:
f.close()
if output is not sys.stdout.buffer:
output.close()
if args.auth:
logger.debug("Checking authentication")
outname = doAuthenticate(outname, i, hasher.hexdigest())
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("Could not recover: %s: %s", i, e)
if args.exceptions:
logger.exception(e)
retcode += 1
else: # Not checksum, but acutal pathnames
for i in args.files:
try:
i = os.path.abspath(i)
logger.info("Processing %s", Util.shortPath(i))
path = None
f = None
if args.last:
(bset, path, name) = findLastPath(i, args.reduce)
if bset is None:
logger.error("Unable to find a latest version of %s", i)
raise Exception("Unable to find a latest version of " + i)
logger.info("Found %s in backup set %s", i, name)
elif args.reduce:
path = Util.reducePath(tardis, bset, i, args.reduce, crypt)
logger.debug("Reduced path %s to %s", path, i)
if not path:
logger.error("Unable to find a compute path for %s", i)
raise Exception("Unable to compute path for " + i)
else:
path = i
if args.crypt and crypt:
actualPath = crypt.encryptPath(path)
else:
actualPath = path
logger.debug("Actual path is %s -- %s", actualPath, bset)
info = tardis.getFileInfoByPath(actualPath, bset)
if info:
retcode += recoverObject(r, info, bset, outputdir, path, linkDB, name=outname, authenticate=args.auth)
else:
logger.error("Could not recover info for %s (File not found)", i)
retcode += 1
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("Could not recover: %s: %s", i, e)
if args.exceptions:
logger.exception(e)
except KeyboardInterrupt:
logger.error("Recovery interupted")
except TardisDB.AuthenticationException as e:
logger.error("Authentication failed. Bad password")
if args.exceptions:
logger.exception(e)
except Exception as e:
logger.error("Regeneration failed: %s", e)
if args.exceptions:
logger.exception(e)
if errors:
logger.warning("%d files could not be recovered.")
return retcode