Exemple #1
0
    def identify_container_and_checked(self, path):
        if self.container.isenterable(path):  # is folder
            return self.container, self.checked

        # force one-level archive browsing
        if not isinstance(self.container, FileSystem):
            return None, None

        aclass = get_archive_class(path)

        if not aclass:
            return None, None

        workwin = WorkWin(self)
        workwin.show("Working ...")

        newcontainer = aclass(path)
        newchecked = DirectoryTree(path, newcontainer)

        workwin.close()

        return newcontainer, newchecked
Exemple #2
0
    def identify_container_and_checked(self, path):
        if self.container.isenterable(path):  # is folder
            return self.container, self.checked

        # force one-level archive browsing
        if not isinstance(self.container, FileSystem):
            return None, None

        aclass = get_archive_class(path)

        if not aclass:
            return None, None

        workwin = WorkWin(self)
        workwin.show("Working ...")

        newcontainer = aclass(path)
        newchecked = DirectoryTree(path, newcontainer)

        workwin.close()

        return newcontainer, newchecked
Exemple #3
0
    def loop(self):
        while not self.kill:
            self.ch = self.stdscr.getch()
            h, w = self.stdscr.getmaxyx()

            if self.ch in [ord('q'), ]:
                self.kill = True

            elif self.ch == curses.KEY_UP:
                self.area.set_params(h, offset=-1)

            elif self.ch == curses.KEY_DOWN:
                self.area.set_params(h, offset=1)

            elif self.ch == curses.KEY_PPAGE:
                self.area.set_params(h, offset=-5)

            elif self.ch == curses.KEY_NPAGE:
                self.area.set_params(h, offset=5)

            elif self.ch == 32:
                index = self.area.selected
                if index == -1:
                    curses.flash()
                    continue
                abspath = self.area.get_abspath(index)
                if abspath in self.checked:
                    del self.checked[abspath]
                else:
                    countitems = self.container.count_items(
                        abspath,
                        stop_at=ITEMS_WARNING
                    )
                    if countitems >= ITEMS_WARNING and \
                            self.show_items_warning() != 0:
                        continue
                    self.checked.add(abspath, sub=True)

            elif self.ch in [curses.KEY_RIGHT, 10, 13]:
                index = self.area.selected
                if index == -1:
                    curses.flash()
                    continue
                abspath = self.area.get_abspath(index)

                result = self.chdir(abspath)
                if not result:
                    curses.flash()

            elif self.ch in [curses.KEY_LEFT,
                             127, curses.ascii.BS, curses.KEY_BACKSPACE]:
                if not self.chdir(
                    self.container.dirname(self.area.abspath)
                ):
                    curses.flash()

            elif self.ch in [ord('c'), ord('C')]:
                if isinstance(self.container, FileSystem):
                    aclass = self.container.__class__
                    checked = self.checked
                    container = self.container

                    pathwin = PathWin(self)
                    exitstatus, archivepath = pathwin.show(
                        "Create archive with format/compression based on file"
                        " extension (ENTER to confirm or ESC to cancel):",
                        os.path.join(os.getcwd(), "NewArchive.tar.gz")
                    )
                    pathwin.close()
                    logging.info("window exitstatus: {0}, '{1}'".format(
                        exitstatus, archivepath
                    ))
                    if exitstatus != 0:
                        continue

                    archivepath = os.path.abspath(archivepath)
                    aclass = get_archive_class(archivepath)
                    if aclass is None:
                        curses.flash()
                        continue

                    created = aclass.create(container, archivepath, checked)

                    if created:
                        TextWin(self).show(
                            "Successfully created archive:\n{0}".format(
                                archivepath
                            )
                        )
                    else:
                        curses.flash()

            elif self.ch in [ord('e'), ord('E')]:
                if isinstance(self.container, Archive):
                    aclass = self.container.__class__
                    archive = self.container.archive
                    checked = self.checked
                    container = self.container
                else:
                    index = self.area.selected
                    if index == -1:
                        curses.flash()
                        continue
                    abspath = self.area.get_abspath(index)
                    if not abspath:
                        curses.flash()
                        continue
                    aclass = get_archive_class(abspath)
                    if aclass is None:
                        curses.flash()
                        continue
                    archive = aclass.open(abspath)
                    checked = None
                    container = None

                pathwin = PathWin(self)
                exitstatus, s = pathwin.show(
                    "Extract to "
                    "(press ENTER for confirmation or ESC to cancel):"
                )
                pathwin.close()
                logging.info("window exitstatus: {0}, '{1}'".format(
                    exitstatus, s
                ))
                if exitstatus != 0:
                    continue

                workwin = WorkWin(self)
                workwin.show("Extracting ...")
                aclass.extract(container, archive, s, checked=checked)
                workwin.close()

                TextWin(self).show("Extracted to:\n{0}".format(s))

            elif self.ch in [ord('?'), curses.KEY_F1, ord('h')]:
                textwin = TextWin(self)
                textwin.show(HELP_STRING)

            if self.ch != -1:
                self.refresh_scr()

            if self.kill:
                break
Exemple #4
0
 def test_get_archive_class(self):
     archive_class = get_archive_class(self.testarchivepath)
     self.assertEqual(archive_class, LibArchive)
Exemple #5
0
    def loop(self):
        while not self.kill:
            self.ch = self.stdscr.getch()
            h, w = self.stdscr.getmaxyx()

            if self.ch in [ord('q'), ]:
                self.kill = True

            elif self.ch == curses.KEY_UP:
                self.area.set_params(h, offset=-1)

            elif self.ch == curses.KEY_DOWN:
                self.area.set_params(h, offset=1)

            elif self.ch == curses.KEY_PPAGE:
                self.area.set_params(h, offset=-5)

            elif self.ch == curses.KEY_NPAGE:
                self.area.set_params(h, offset=5)

            elif self.ch == 32:
                index = self.area.selected
                if index == -1:
                    curses.flash()
                    continue
                abspath = self.area.get_abspath(index)
                if abspath in self.checked:
                    del self.checked[abspath]
                else:
                    countitems = self.container.count_items(
                        abspath,
                        stop_at=ITEMS_WARNING
                    )
                    if countitems >= ITEMS_WARNING and \
                            self.show_items_warning() != 0:
                        continue
                    self.checked.add(abspath, sub=True)

            elif self.ch in [curses.KEY_RIGHT, 10, 13]:
                index = self.area.selected
                if index == -1:
                    curses.flash()
                    continue
                abspath = self.area.get_abspath(index)

                result = self.chdir(abspath)
                if not result:
                    curses.flash()

            elif self.ch in [curses.KEY_LEFT,
                             127, curses.ascii.BS, curses.KEY_BACKSPACE]:
                if not self.chdir(
                    self.container.dirname(self.area.abspath)
                ):
                    curses.flash()

            elif self.ch in [ord('c'), ord('C')]:
                if isinstance(self.container, FileSystem):
                    aclass = self.container.__class__
                    checked = self.checked
                    container = self.container

                    pathwin = PathWin(self)
                    exitstatus, archivepath = pathwin.show(
                        "Create archive with format/compression based on file"
                        " extension (ENTER to confirm or ESC to cancel):",
                        os.path.join(os.getcwd(), "NewArchive.tar.gz")
                    )
                    pathwin.close()
                    logging.info("window exitstatus: {0}, '{1}'".format(
                        exitstatus, archivepath
                    ))
                    if exitstatus != 0:
                        continue

                    archivepath = os.path.abspath(archivepath)
                    aclass = get_archive_class(archivepath)
                    if aclass is None:
                        curses.flash()
                        continue

                    created = aclass.create(container, archivepath, checked)

                    if created:
                        TextWin(self).show(
                            "Successfully created archive:\n{0}".format(
                                archivepath
                            )
                        )
                    else:
                        curses.flash()

            elif self.ch in [ord('e'), ord('E')]:
                if isinstance(self.container, Archive):
                    aclass = self.container.__class__
                    archive = self.container.archive
                    checked = self.checked
                    container = self.container
                else:
                    index = self.area.selected
                    if index == -1:
                        curses.flash()
                        continue
                    abspath = self.area.get_abspath(index)
                    if not abspath:
                        curses.flash()
                        continue
                    aclass = get_archive_class(abspath)
                    if aclass is None:
                        curses.flash()
                        continue
                    archive = aclass.open(abspath)
                    checked = None
                    container = None

                pathwin = PathWin(self)
                exitstatus, s = pathwin.show(
                    "Extract to "
                    "(press ENTER for confirmation or ESC to cancel):"
                )
                pathwin.close()
                logging.info("window exitstatus: {0}, '{1}'".format(
                    exitstatus, s
                ))
                if exitstatus != 0:
                    continue

                workwin = WorkWin(self)
                workwin.show("Extracting ...")
                aclass.extract(container, archive, s, checked=checked)
                workwin.close()

                TextWin(self).show("Extracted to:\n{0}".format(s))

            elif self.ch in [ord('?'), curses.KEY_F1]:
                curses.curs_set(0)
                textwin = TextWin(self)
                textwin.show(HELP_STRING)

            if self.ch == ord('h'):
                if self.show_hiddens == True:
                    self.show_hiddens = False
                else:
                    self.show_hiddens = True
                self.chdir(self.area.abspath)

            if self.ch != -1:
                self.refresh_scr()

            if self.kill:
                break