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 = unicode(os.path.abspath(d).decode(fsEncoding)) 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)) if args.exceptions: logger.exception(e) finally: if tardis: tardis.close()
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
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()
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
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)