def filename(config, like, ilike, notlike, notilike, run): with self_contained_session(config.database, echo=config.database_echo) as session: query = session.query(Filename) for name in like: query = like_filter(query, name) for name in ilike: query = ilike_filter_escape(query, name) for name in notlike: query = like_filter(query, name, exclude=True) for name in notilike: query = ilike_filter_escape(query, name, exclude=True) #elif regex: # broken for bytes # query = session.query(Filename).filter(text('filename ~ :reg')).params(reg=name) #else: # assert len(names) == 1 # query = session.query(Filename).filter(Filename.filename == names[0]) for filename in query: #print(filename) for item in filename.filenames: print(item.file) if run: command = run + b' -- ' + b'"' + item.file + b'"' eprint(command)
def filerecord(config, path): with self_contained_session(config.database) as session: BASE.metadata.create_all(session.bind) path, filename = os.path.split(path) #session. filerecord = FileRecord.construct(session=session, inpath=path) filerecord = FileRecord.construct(session=session, inpath=path) #session.commit() print(bytes(filerecord))
def _index(config, paths, verbose): #with PyCallGraph(output=GraphvizOutput()): for path in paths: assert path_is_dir(path) with self_contained_session(config.database) as session: BASE.metadata.create_all(session.bind) pathlib_object = pathlib.Path(os.fsdecode(path)) for index, path in enumerate(all_files_iter(pathlib_object)): if verbose: ceprint(path) filerecord = FileRecord.construct(session=session, path=bytes(path), verbose=verbose) session.add(filerecord) if index % 100: session.flush() session.commit()
def path(config, path, like, regex): with self_contained_session(config.database, echo=config.database_echo) as session: if like and regex: eprint("--like and --regex are mutually exclusive.") quit(1) if like: path_generator = session.query(Path).filter( Path.path.like(b'%' + path + b'%')) elif regex: path_generator = session.query(Path).filter( text('path ~ :reg')).params(reg=path) else: path_generator = session.query(Path).filter(Path.path == path) for path in path_generator: #print(path) for item in path.filerecords: print(item)
def path(config): with self_contained_session(config.database) as session: path_generator = session.query(Path) for path in path_generator: print(path)
def filerecord(config): with self_contained_session(config.database) as session: filerecord_generator = session.query(FileRecord) for filerecord in filerecord_generator: print(filerecord)
def filename(config): with self_contained_session(config.database) as session: filename_generator = session.query(Filename) for filename in filename_generator: print(filename)
def _record(config, path): with self_contained_session(config.database) as session: BASE.metadata.create_all(session.bind) filerecord = FileRecord.construct(session=session, path=path) session.commit() print(bytes(filerecord))