Example #1
0
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())
Example #2
0
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())
Example #3
0
    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)
Example #4
0
    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)
Example #5
0
 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()
Example #6
0
    def test_from_human(self):
        humans = [
            ("/", "file:///"),
            ("/tmp/file.rar://rar", "file:///tmp/file.rar%3A//rar"),
            ("/tmp/file", "file:///tmp/file"),
            ("file:///tmp/file2", "file:///tmp/file2"),
            ("file:///tmp/file.rar//rar:foo.bar",
             "file:///tmp/file.rar//rar:foo.bar"),
            ("file:///tmp/file spacetest", "file:///tmp/file%20spacetest"),
        ]

        for human, expected in humans:
            location = Location.from_human(human)
            self.assertEqual(location.as_url(), expected)
Example #7
0
    def on_text_edited(self, text) -> None:
        p = self.palette()

        try:
            location = Location.from_human(text)
            if location.exists():
                p.setColor(QPalette.Text, Qt.black)
            else:
                p.setColor(QPalette.Text, Qt.red)
        except Exception:
            p.setColor(QPalette.Text, Qt.red)

        self.setPalette(p)

        self._controller._path_completion.request_completions(text)
Example #8
0
    def test_from_human(self):
        humans = [
            ("/",
             "file:///"),

            ("/tmp/file.rar://rar",
             "file:///tmp/file.rar%3A//rar"),

            ("/tmp/file",
             "file:///tmp/file"),

            ("file:///tmp/file2",
             "file:///tmp/file2"),

            ("file:///tmp/file.rar//rar:foo.bar",
             "file:///tmp/file.rar//rar:foo.bar"),

            ("file:///tmp/file spacetest",
             "file:///tmp/file%20spacetest"),
        ]

        for human, expected in humans:
            location = Location.from_human(human)
            self.assertEqual(location.as_url(), expected)