def main(argv: List[str]) -> None: args = parse_args(argv[1:]) if args.debug: logging.basicConfig(level=logging.DEBUG) else: logging.basicConfig(level=logging.WARNING) if args.profile: activate_profiler(True) app = FileViewApplication() if args.FILE == []: app.show_location(Location.from_path(os.getcwd())) elif args.FILE == ["-"]: if args.null: app.show_location(Location.from_url("stream0:///stdin")) else: app.show_location(Location.from_url("stream:///stdin")) elif len(args.FILE) == 1 and os.path.isdir(args.FILE[0]): app.show_location(Location.from_human(args.FILE[0])) elif args.recursive: files = expand_directories(args.FILE, args.recursive) app.show_files([Location.from_path(f) for f in files]) else: app.show_files([Location.from_human(f) for f in args.FILE]) sys.exit(app.run())
def main(argv: List[str]) -> None: args = parse_args(argv[1:]) if args.debug: logging.basicConfig(level=logging.DEBUG) else: logging.basicConfig(level=logging.WARNING) if args.profile: activate_profiler(True) app = FileViewApplication() if args.FILE == []: app.show_location(Location.from_path(os.getcwd())) elif args.FILE == ["-"]: if args.null: app.show_location(Location.from_url("stream0:///stdin")) else: app.show_location(Location.from_url("stream:///stdin")) elif len(args.FILE) == 1 and os.path.isdir(args.FILE[0]): app.show_location(Location.from_human(args.FILE[0])) elif args.recursive: files = expand_directories(args.FILE, args.recursive) app.show_files([Location.from_path(f) for f in files]) else: app.show_files([Location.from_human(f) for f in args.FILE]) sys.exit(app.run())
def test_from_human_path(self): result = Location.from_human(".") expected = Location.from_path(os.getcwd()) self.assertEqual(result, expected) result = Location.from_human("") expected = Location.from_path(os.getcwd()) self.assertEqual(result, expected)
def test_from_human_path(self): result = Location.from_human(".") expected = Location.from_path(os.getcwd()) self.assertEqual(result, expected) result = Location.from_human("") expected = Location.from_path(os.getcwd()) self.assertEqual(result, expected)
def from_path(path: str) -> 'FileInfo': logger.debug("FileInfo.from_path: %s", path) fi = FileInfo() fi._abspath = os.path.abspath(path) fi._location = Location.from_path(fi._abspath) fi._dirname = os.path.dirname(fi._abspath) fi._basename = os.path.basename(fi._abspath) fi._ext = os.path.splitext(fi._abspath)[1] try: fi._stat = os.lstat(fi._abspath) fi._have_access = os.access(fi._abspath, os.R_OK) fi._error = FileInfoError.NO_ERROR except (FileNotFoundError, NotADirectoryError): fi._error = FileInfoError.FILENOTFOUND except PermissionError: fi._error = FileInfoError.PERMISSIONDENIED except OSError as err: if err.errno == errno.EIO: fi._error = FileInfoError.IO else: fi._error = FileInfoError.UNKNOWN except Exception as err: fi._error = FileInfoError.UNKNOWN else: fi._isdir = os.path.isdir(fi._abspath) fi._isfile = stat.S_ISREG(fi._stat.st_mode) fi._issymlink = stat.S_ISLNK(fi._stat.st_mode) return fi
def test_collector(self): app = QApplication([]) try: vfs = StdioFilesystem("/tmp") metadata_collector = MetaDataCollector(vfs) def on_metadata(filename, metadata): print(filename) print(metadata) print() metadata_collector.sig_metadata_ready.connect(on_metadata) metadata_collector.request_metadata(Location.from_path("dirtools/fileview/icons/noun_409399_cc.png")) QTimer.singleShot(500, metadata_collector.close) QTimer.singleShot(1500, app.quit) app.exec() except Exception as err: print(err) finally: metadata_collector.close() vfs.close()
def from_path(path: str) -> 'FileInfo': logger.debug("FileInfo.from_path: %s", path) fi = FileInfo() fi._abspath = os.path.abspath(path) fi._location = Location.from_path(fi._abspath) fi._dirname = os.path.dirname(fi._abspath) fi._basename = os.path.basename(fi._abspath) fi._ext = os.path.splitext(fi._abspath)[1] try: fi._stat = os.lstat(fi._abspath) fi._have_access = os.access(fi._abspath, os.R_OK) fi._error = FileInfoError.NO_ERROR except (FileNotFoundError, NotADirectoryError): fi._error = FileInfoError.FILENOTFOUND except PermissionError: fi._error = FileInfoError.PERMISSIONDENIED except OSError as err: if err.errno == errno.EIO: fi._error = FileInfoError.IO else: fi._error = FileInfoError.UNKNOWN except Exception as err: fi._error = FileInfoError.UNKNOWN else: fi._isdir = os.path.isdir(fi._abspath) fi._isfile = stat.S_ISREG(fi._stat.st_mode) fi._issymlink = stat.S_ISLNK(fi._stat.st_mode) return fi
def test_collector(self): app = QApplication([]) try: vfs = StdioFilesystem("/tmp") metadata_collector = MetaDataCollector(vfs) def on_metadata(filename, metadata): print(filename) print(metadata) print() metadata_collector.sig_metadata_ready.connect(on_metadata) metadata_collector.request_metadata( Location.from_path( "dirtools/fileview/icons/noun_409399_cc.png")) QTimer.singleShot(500, metadata_collector.close) QTimer.singleShot(1500, app.quit) app.exec() except Exception as err: print(err) finally: metadata_collector.close() vfs.close()
def on_return_pressed(self) -> None: try: completition = self._popup.get_current_completion() self._popup.hide() if completition is not None: location = Location.from_path(completition) else: location = Location.from_human(self.text()) except Exception: logger.warning("unparsable location entered: %s", self.text()) else: self._controller.set_location(location) self._popup.hide()
def _on_activated(self, fd: int) -> None: while True: try: filename: str = next(self.readliner) except StopIteration: self.socket_notifier.setEnabled(False) self.socket_notifier = None self.sig_end_of_stream.emit() return else: if filename is not None: location = Location.from_path(filename) self.sig_file_added.emit(self.vfs.get_fileinfo(location)) else: return
def _set_directory_location(self, location: Location) -> None: self.file_collection.clear() if self._directory_watcher is not None: self._directory_watcher.close() self._directory_watcher = self.app.vfs.opendir(location) if hasattr(self._directory_watcher, 'sig_file_added'): self._directory_watcher.sig_file_added.connect( self.file_collection.add_fileinfo) if hasattr(self._directory_watcher, 'sig_file_removed'): self._directory_watcher.sig_file_removed.connect( self.file_collection.remove_file) if hasattr(self._directory_watcher, 'sig_file_modified'): self._directory_watcher.sig_file_modified.connect( self.file_collection.modify_file) if hasattr(self._directory_watcher, 'sig_file_closed'): self._directory_watcher.sig_file_closed.connect( self.file_collection.close_file) if hasattr(self._directory_watcher, 'sig_finished'): self._directory_watcher.sig_finished.connect(self._on_finished) if hasattr(self._directory_watcher, 'sig_scandir_finished'): self._directory_watcher.sig_scandir_finished.connect( self._on_scandir_finished) if hasattr(self._directory_watcher, 'sig_message'): self._directory_watcher.sig_message.connect( self._on_directory_watcher_message) self._directory_watcher.start() if location.protocol() == "search": abspath, query = location.search_query() search_location = Location.from_path(abspath) self.location = search_location self._gui._window.set_location(search_location) self._gui._window.search_lineedit.setText(query) self._gui._window.search_toolbar.show() else: self.location = location self._gui._window.set_location(self.location)
def go_home(self) -> None: home = os.path.expanduser("~") self.set_location(Location.from_path(home))
def request(filename: str) -> None: nonlocal num_requests metadata_collector.request_metadata(Location.from_path(filename)) num_requests += 1
def location(self) -> Location: if self._location is None: self._location = Location.from_path(self._abspath) return self._location
def request(filename: str) -> None: nonlocal num_requests metadata_collector.request_metadata(Location.from_path(filename)) num_requests += 1
def location(self) -> Location: if self._location is None: self._location = Location.from_path(self._abspath) return self._location