Ejemplo n.º 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())
Ejemplo n.º 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())
Ejemplo n.º 3
0
    def test_location_parent(self):
        parent_texts = [
            ("file:///home/juser/test.rar//rar:file_inside.rar",
             ("file", "/home/juser/test.rar", [Payload("rar", "")])),
            ("file:///home/juser/test.rar", ("file", "/home/juser", [])),
            ("file:///home/juser/test.rar//rar", ("file", "/home/juser", [])),
            ("file:///tmp/", ("file", "/", [])),
            ("file:///home/juser/test.rar//rar:file_inside.rar//rar:file.txt",
             ("file", "/home/juser/test.rar",
              [Payload("rar", "file_inside.rar"),
               Payload("rar", "")])),
            ("file:///home/juser/test.rar//rar:file_inside.rar//rar",
             ("file", "/home/juser/test.rar", [Payload("rar", "")])),
            ("file:///test.rar//rar:one//rar:two//rar:three",
             ("file", "/test.rar", [
                 Payload("rar", "one"),
                 Payload("rar", "two"),
                 Payload("rar", "")
             ]))
        ]

        for text, (protocol, abspath, payloads) in parent_texts:
            location = Location.from_url(text)
            location = location.parent()
            self.assertEqual(location._protocol, protocol, text)
            self.assertEqual(location._path, abspath, text)
            self.assertEqual(location._payloads, payloads, text)
Ejemplo n.º 4
0
    def test_location_parent(self):
        parent_texts = [
            ("file:///home/juser/test.rar//rar:file_inside.rar",
             ("file", "/home/juser/test.rar", [Payload("rar", "")])),

            ("file:///home/juser/test.rar",
             ("file", "/home/juser", [])),

            ("file:///home/juser/test.rar//rar",
             ("file", "/home/juser", [])),

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

            ("file:///home/juser/test.rar//rar:file_inside.rar//rar:file.txt",
             ("file", "/home/juser/test.rar", [Payload("rar", "file_inside.rar"), Payload("rar", "")])),

            ("file:///home/juser/test.rar//rar:file_inside.rar//rar",
             ("file", "/home/juser/test.rar", [Payload("rar", "")])),

            ("file:///test.rar//rar:one//rar:two//rar:three",
             ("file", "/test.rar", [Payload("rar", "one"), Payload("rar", "two"), Payload("rar", "")]))
        ]

        for text, (protocol, abspath, payloads) in parent_texts:
            location = Location.from_url(text)
            location = location.parent()
            self.assertEqual(location._protocol, protocol, text)
            self.assertEqual(location._path, abspath, text)
            self.assertEqual(location._payloads, payloads, text)
Ejemplo n.º 5
0
 def test_ancestry(self):
     location = Location.from_url("file:///home/juser/test.rar//rar:bar/foo.zip//zip:bar.png")
     result = location.ancestry()
     expected = [
         Location.from_url('file:///'),
         Location.from_url('file:///home'),
         Location.from_url('file:///home/juser'),
         Location.from_url('file:///home/juser/test.rar//rar'),
         Location.from_url('file:///home/juser/test.rar//rar:bar'),
         Location.from_url('file:///home/juser/test.rar//rar:bar/foo.zip//zip'),
         Location.from_url('file:///home/juser/test.rar//rar:bar/foo.zip//zip:bar.png')
     ]
     self.assertEqual(result, expected)
Ejemplo n.º 6
0
    def test_basename(self):
        testcases = [
            ("file:///home/juser/test.rar//rar:bar/foo.zip//zip:bar.png",
             "bar.png"),
            ("file:///home/juser/test.rar//rar:bar/foo.zip//zip",
             "foo.zip//zip"),
            ("file:///home/juser/foo.zip//zip:test.rar", "test.rar"),
            ("file:///home/juser/test.rar", "test.rar"),
        ]

        for url, expected in testcases:
            location = Location.from_url(url)
            result = location.basename()
            self.assertEqual(result, expected)
Ejemplo n.º 7
0
 def test_ancestry(self):
     location = Location.from_url(
         "file:///home/juser/test.rar//rar:bar/foo.zip//zip:bar.png")
     result = location.ancestry()
     expected = [
         Location.from_url('file:///'),
         Location.from_url('file:///home'),
         Location.from_url('file:///home/juser'),
         Location.from_url('file:///home/juser/test.rar//rar'),
         Location.from_url('file:///home/juser/test.rar//rar:bar'),
         Location.from_url(
             'file:///home/juser/test.rar//rar:bar/foo.zip//zip'),
         Location.from_url(
             'file:///home/juser/test.rar//rar:bar/foo.zip//zip:bar.png')
     ]
     self.assertEqual(result, expected)
Ejemplo n.º 8
0
    def test_origin(self):
        testcases = [
            (Location.from_url("file:///home/juser/test.rar//rar:bar/foo1.zip//zip:bar.png"),
             Location.from_url("file:///home/juser/test.rar//rar:bar/foo1.zip")),

            (Location.from_url("file:///home/juser/test.rar//rar:bar/foo2.zip//zip"),
             Location.from_url("file:///home/juser/test.rar//rar:bar/foo2.zip")),

            (Location.from_url("file:///home/juser/test.rar//rar:bar/foo3.zip//zip:"),
             Location.from_url("file:///home/juser/test.rar//rar:bar/foo3.zip")),

            (Location.from_url("file:///home/juser/foo4.zip//zip:test.rar"),
             Location.from_url("file:///home/juser/foo4.zip")),

            (Location.from_url("file:///home/juser/test5.rar"),
             None)
        ]

        for location, expected in testcases:
            result = location.origin()
            self.assertEqual(result, expected)
Ejemplo n.º 9
0
    def get_entries(self) -> List['Location']:
        try:
            with open(self.config_filename, "r") as fin:
                lines = fin.read().splitlines()

                result = []
                for line in lines:
                    try:
                        result.append(Location.from_url(line))
                    except Exception as err:
                        logger.warning("ignoring bookmark entry: %s: %s", line, err)

                return sorted(result)

        except FileNotFoundError:
            return []
Ejemplo n.º 10
0
    def test_origin(self):
        testcases = [
            (Location.from_url(
                "file:///home/juser/test.rar//rar:bar/foo1.zip//zip:bar.png"),
             Location.from_url("file:///home/juser/test.rar//rar:bar/foo1.zip")
             ),
            (Location.from_url(
                "file:///home/juser/test.rar//rar:bar/foo2.zip//zip"),
             Location.from_url("file:///home/juser/test.rar//rar:bar/foo2.zip")
             ),
            (Location.from_url(
                "file:///home/juser/test.rar//rar:bar/foo3.zip//zip:"),
             Location.from_url("file:///home/juser/test.rar//rar:bar/foo3.zip")
             ),
            (Location.from_url("file:///home/juser/foo4.zip//zip:test.rar"),
             Location.from_url("file:///home/juser/foo4.zip")),
            (Location.from_url("file:///home/juser/test5.rar"), None)
        ]

        for location, expected in testcases:
            result = location.origin()
            self.assertEqual(result, expected)
Ejemplo n.º 11
0
    def get_entries(self, limit: Optional[int] = None) -> List[Location]:
        c = self._db.cursor()
        c.execute("SELECT group_id, date, location "
                  "FROM history "
                  "ORDER BY date DESC" +
                  (" LIMIT {}".format(limit) if limit is not None else ""))

        results: List[Location] = []
        for group_id, date, location_url in c.fetchall():
            try:
                loc = Location.from_url(location_url)
            except Exception:
                logging.exception("Location parsing failed")
            else:
                results.append(loc)

        return results
Ejemplo n.º 12
0
    def test_pure(self):
        testcases = [
            ("file:///home/juser/test.rar//rar:bar/foo.zip//zip:bar.png",
             "file:///home/juser/test.rar//rar:bar/foo.zip//zip:bar.png"),
            ("file:///home/juser/test.rar//rar:bar/foo2.zip//zip",
             "file:///home/juser/test.rar//rar:bar/foo2.zip"),
            ("file:///home/juser/test.rar//rar:bar/foo3.zip//zip:",
             "file:///home/juser/test.rar//rar:bar/foo3.zip"),
            ("file:///home/juser/foo.zip//zip:test.rar",
             "file:///home/juser/foo.zip//zip:test.rar"),
            ("file:///home/juser/test.rar", "file:///home/juser/test.rar")
        ]

        for url, expected in testcases:
            location = Location.from_url(url)
            result = location.pure()
            self.assertEqual(result.as_url(), expected)
Ejemplo n.º 13
0
    def get_entries(self) -> List['Location']:
        try:
            with open(self.config_filename, "r") as fin:
                lines = fin.read().splitlines()

                result = []
                for line in lines:
                    try:
                        result.append(Location.from_url(line))
                    except Exception as err:
                        logger.warning("ignoring bookmark entry: %s: %s", line,
                                       err)

                return sorted(result)

        except FileNotFoundError:
            return []
Ejemplo n.º 14
0
    def get_entries(self, limit: Optional[int] = None) -> List[Location]:
        c = self._db.cursor()
        c.execute("SELECT group_id, date, location "
                  "FROM history "
                  "ORDER BY date DESC" +
                  (" LIMIT {}".format(limit) if limit is not None else ""))

        results: List[Location] = []
        for group_id, date, location_url in c.fetchall():
            try:
                loc = Location.from_url(location_url)
            except Exception:
                logging.exception("Location parsing failed")
            else:
                results.append(loc)

        return results
Ejemplo n.º 15
0
    def test_basename(self):
        testcases = [
            ("file:///home/juser/test.rar//rar:bar/foo.zip//zip:bar.png",
             "bar.png"),

            ("file:///home/juser/test.rar//rar:bar/foo.zip//zip",
             "foo.zip//zip"),

            ("file:///home/juser/foo.zip//zip:test.rar",
             "test.rar"),

            ("file:///home/juser/test.rar",
             "test.rar"),
        ]

        for url, expected in testcases:
            location = Location.from_url(url)
            result = location.basename()
            self.assertEqual(result, expected)
Ejemplo n.º 16
0
    def test_location_join(self):
        join_texts = [
            ("file:///home/juser/test.rar//rar", "foobar",
             ("file", "/home/juser/test.rar", [Payload("rar", "foobar")])),
            ("file:///home/juser/test.rar//rar:foo.rar//rar", "foobar.png",
             ("file", "/home/juser/test.rar",
              [Payload("rar", "foo.rar"),
               Payload("rar", "foobar.png")])),
            ("file:///home/juser/test.rar//rar:foo.rar//rar:foobar", "bar.png",
             ("file", "/home/juser/test.rar",
              [Payload("rar", "foo.rar"),
               Payload("rar", "foobar/bar.png")])),
        ]

        for base_text, join_text, (protocol, abspath, payloads) in join_texts:
            base = Location.from_url(base_text)
            result = Location.join(base, join_text)

            self.assertEqual(result._protocol, protocol, base_text)
            self.assertEqual(result._path, abspath, base_text)
            self.assertEqual(result._payloads, payloads, base_text)
Ejemplo n.º 17
0
    def test_pure(self):
        testcases = [
            ("file:///home/juser/test.rar//rar:bar/foo.zip//zip:bar.png",
             "file:///home/juser/test.rar//rar:bar/foo.zip//zip:bar.png"),

            ("file:///home/juser/test.rar//rar:bar/foo2.zip//zip",
             "file:///home/juser/test.rar//rar:bar/foo2.zip"),

            ("file:///home/juser/test.rar//rar:bar/foo3.zip//zip:",
             "file:///home/juser/test.rar//rar:bar/foo3.zip"),

            ("file:///home/juser/foo.zip//zip:test.rar",
             "file:///home/juser/foo.zip//zip:test.rar"),

            ("file:///home/juser/test.rar",
             "file:///home/juser/test.rar")
        ]

        for url, expected in testcases:
            location = Location.from_url(url)
            result = location.pure()
            self.assertEqual(result.as_url(), expected)
Ejemplo n.º 18
0
    def test_location_join(self):
        join_texts = [
            ("file:///home/juser/test.rar//rar",
             "foobar",
             ("file", "/home/juser/test.rar", [Payload("rar", "foobar")])),

            ("file:///home/juser/test.rar//rar:foo.rar//rar",
             "foobar.png",
             ("file", "/home/juser/test.rar", [Payload("rar", "foo.rar"), Payload("rar", "foobar.png")])),

            ("file:///home/juser/test.rar//rar:foo.rar//rar:foobar",
             "bar.png",
             ("file", "/home/juser/test.rar", [Payload("rar", "foo.rar"), Payload("rar", "foobar/bar.png")])),
        ]

        for base_text, join_text, (protocol, abspath, payloads) in join_texts:
            base = Location.from_url(base_text)
            result = Location.join(base, join_text)

            self.assertEqual(result._protocol, protocol, base_text)
            self.assertEqual(result._path, abspath, base_text)
            self.assertEqual(result._payloads, payloads, base_text)
Ejemplo n.º 19
0
    def test_location_init(self):
        ok_texts = [
            ("file:///home/juser/test.rar//rar:file_inside.rar",
             ("file", "/home/juser/test.rar",
              [Payload("rar", "file_inside.rar")])),
            ("file:///home/juser/test.rar", ("file", "/home/juser/test.rar",
                                             [])),
            ("file:///home/juser/test.rar//rar",
             ("file", "/home/juser/test.rar", [Payload("rar", "")])),
            ("file:///tmp/", ("file", "/tmp", [])),
            ("file:///home/juser/test.rar//rar:file_inside.rar//rar:file.txt",
             ("file", "/home/juser/test.rar",
              [Payload("rar", "file_inside.rar"),
               Payload("rar", "file.txt")])),
            ("file:///test.rar//rar:one//rar:two//rar:three",
             ("file", "/test.rar", [
                 Payload("rar", "one"),
                 Payload("rar", "two"),
                 Payload("rar", "three")
             ]))
        ]

        for text, (protocol, abspath, payloads) in ok_texts:
            location = Location.from_url(text)
            self.assertEqual(location._protocol, protocol)
            self.assertEqual(location._path, abspath)
            self.assertEqual(location._payloads, payloads)

        fail_texts = [
            "/home/juser/test.rar", "file://test.rar",
            "file:///test.rar//rar:oeu//"
            "file:///test.rar///rar:foo"
        ]

        for text in fail_texts:
            with self.assertRaises(Exception) as context:
                Location.from_string(text)
Ejemplo n.º 20
0
    def test_location_init(self):
        ok_texts = [
            ("file:///home/juser/test.rar//rar:file_inside.rar",
             ("file", "/home/juser/test.rar", [Payload("rar", "file_inside.rar")])),

            ("file:///home/juser/test.rar",
             ("file", "/home/juser/test.rar", [])),

            ("file:///home/juser/test.rar//rar",
             ("file", "/home/juser/test.rar", [Payload("rar", "")])),

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

            ("file:///home/juser/test.rar//rar:file_inside.rar//rar:file.txt",
             ("file", "/home/juser/test.rar", [Payload("rar", "file_inside.rar"), Payload("rar", "file.txt")])),

            ("file:///test.rar//rar:one//rar:two//rar:three",
             ("file", "/test.rar", [Payload("rar", "one"), Payload("rar", "two"), Payload("rar", "three")]))
        ]

        for text, (protocol, abspath, payloads) in ok_texts:
            location = Location.from_url(text)
            self.assertEqual(location._protocol, protocol)
            self.assertEqual(location._path, abspath)
            self.assertEqual(location._payloads, payloads)

        fail_texts = [
            "/home/juser/test.rar",
            "file://test.rar",
            "file:///test.rar//rar:oeu//"
            "file:///test.rar///rar:foo"
        ]

        for text in fail_texts:
            with self.assertRaises(Exception) as context:
                Location.from_string(text)
Ejemplo n.º 21
0
 def show_file_history(self) -> None:
     self.set_location(Location.from_url("history:///"))