本文整理汇总了Python中Tardis.Util.setupDataConnection方法的典型用法代码示例。如果您正苦于以下问题:Python Util.setupDataConnection方法的具体用法?Python Util.setupDataConnection怎么用?Python Util.setupDataConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tardis.Util
的用法示例。
在下文中一共展示了Util.setupDataConnection方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from Tardis import Util [as 别名]
# 或者: from Tardis.Util import setupDataConnection [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)
示例2: main
# 需要导入模块: from Tardis import Util [as 别名]
# 或者: from Tardis.Util import setupDataConnection [as 别名]
def main():
global logger
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger('')
args = processArgs()
password = Util.getPassword(args.password, args.passwordfile, args.passwordprog)
(_, _, crypto) = Util.setupDataConnection(args.database, args.client, password, args.keys, args.dbname, args.dbdir)
data = args.names
if not data:
tty = os.isatty(0)
if not tty:
data = list(map(str.strip, sys.stdin.readlines()))
else:
data = reader(args.quiet)
for i in data:
if i:
if not args.quiet:
print(i, " \t => \t", end=' ')
try:
if (args.encrypt):
print(crypto.encryptPath(i))
else:
print(crypto.decryptPath(i))
except Exception as e:
print("Caught exception: " + str(e))
示例3: main
# 需要导入模块: from Tardis import Util [as 别名]
# 或者: from Tardis.Util import setupDataConnection [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)
示例4: main
# 需要导入模块: from Tardis import Util [as 别名]
# 或者: from Tardis.Util import setupDataConnection [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()
示例5: main
# 需要导入模块: from Tardis import Util [as 别名]
# 或者: from Tardis.Util import setupDataConnection [as 别名]
def main():
global args
args = processArgs()
password = Util.getPassword(args.password, args.passwordfile, args.passwordprog, prompt="Password for %s: " % (args.client))
(tardis, _, crypt) = Util.setupDataConnection(args.database, args.client, password, args.keys, args.dbname, args.dbdir)
(f, c) = crypt.getKeys()
client = tardis.getConfigValue('ClientID')
data = Util.mkKeyString(client, f, c)
qrfile = mkQrFile(data)
makePdf(args.output, qrfile.name, data, args.client)
return 0
示例6: main
# 需要导入模块: from Tardis import Util [as 别名]
# 或者: from Tardis.Util import setupDataConnection [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)
示例7: __init__
# 需要导入模块: from Tardis import Util [as 别名]
# 或者: from Tardis.Util import setupDataConnection [as 别名]
def __init__(self, *args, **kw):
super(TardisFS, self).__init__(*args, **kw)
try:
client = Defaults.getDefault('TARDIS_CLIENT')
database = Defaults.getDefault('TARDIS_DB')
dbdir = Defaults.getDefault('TARDIS_DBDIR') % { 'TARDIS_DB': database } # HACK
dbname = Defaults.getDefault('TARDIS_DBNAME')
current = Defaults.getDefault('TARDIS_RECENT_SET')
# Parameters
self.database = database
self.client = client
self.repoint = False
self.password = None
self.pwfile = None
self.pwprog = None
self.keys = None
self.dbname = dbname
self.dbdir = dbdir
self.cachetime = 60
self.nocrypt = False
self.noauth = False
self.current = current
self.authenticate = True
self.crypt = None
logging.basicConfig(level=logging.WARNING)
self.log = logging.getLogger("TardisFS")
self.parser.add_option("--database", '-D', help="Path to the Tardis database directory")
self.parser.add_option("--client", '-C', help="Client to load database for")
self.parser.add_option("--password", '-P', help="Password for this archive (use '-o password=' to prompt for password)")
self.parser.add_option("--keys", help="Load keys from the specified file")
self.parser.add_option(mountopt="database", help="Path to the Tardis database directory")
self.parser.add_option(mountopt="client", help="Client to load database for")
self.parser.add_option(mountopt="password", help="Password for this archive (use '-o password=' to prompt for password)")
self.parser.add_option(mountopt="pwfile", help="Read password for this archive from the file. Can be a URL (HTTP/HTTPS or FTP)")
self.parser.add_option(mountopt="pwprog", help="Use the specified program to generate the password on stdout")
self.parser.add_option(mountopt="keys", help="Load keys from the specified file")
self.parser.add_option(mountopt="repoint", help="Make absolute links relative to backupset")
self.parser.add_option(mountopt="dbname", help="Database Name")
self.parser.add_option(mountopt="dbdir", help="Database Directory (if different from data directory")
self.parser.add_option(mountopt="cachetime", help="Lifetime of cached elements in seconds")
self.parser.add_option(mountopt='nocrypt', help="Disable encryption")
self.parser.add_option(mountopt='noauth', help="Disable authentication")
self.parser.add_option(mountopt='current', help="Name to use for most recent complete backup")
res = self.parse(values=self, errex=1)
self.mountpoint = res.mountpoint
self.name = "TardisFS:<{}/{}>".format(self.database, self.client)
password = Util.getPassword(self.password, self.pwfile, self.pwprog, prompt="Password for %s: " % (self.client))
self.password = None
self.cache = Cache.Cache(0, float(self.cachetime))
self.fileCache = Cache.Cache(0, float(self.cachetime), 'FileCache')
#if password:
# self.crypt = TardisCrypto.TardisCrypto(password, self.client)
(self.tardis, self.cacheDir, self.crypt) = Util.setupDataConnection(self.database, self.client, password, self.keys, self.dbname, self.dbdir)
password = None
# Remove the crypto object if not encyrpting files.
if self.nocrypt or self.nocrypt is None:
self.crypt = None
if self.noauth or self.noauth is None:
self.authenticate = False
# Create a regenerator.
self.regenerator = Regenerator.Regenerator(self.cacheDir, self.tardis, crypt=self.crypt)
self.files = {}
# Fuse variables
self.flags = 0
self.multithreaded = 0
except Exception as e:
self.log.exception(e)
sys.exit(2)
示例8: main
# 需要导入模块: from Tardis import Util [as 别名]
# 或者: from Tardis.Util import setupDataConnection [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
#.........这里部分代码省略.........