当前位置: 首页>>代码示例>>Python>>正文


Python Bookmarks.remember方法代码示例

本文整理汇总了Python中ranger.container.bookmarks.Bookmarks.remember方法的典型用法代码示例。如果您正苦于以下问题:Python Bookmarks.remember方法的具体用法?Python Bookmarks.remember怎么用?Python Bookmarks.remember使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ranger.container.bookmarks.Bookmarks的用法示例。


在下文中一共展示了Bookmarks.remember方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: testbookmarks

# 需要导入模块: from ranger.container.bookmarks import Bookmarks [as 别名]
# 或者: from ranger.container.bookmarks.Bookmarks import remember [as 别名]
def testbookmarks(tmpdir):
    # Bookmarks point to directory location and allow fast access to
    # 'favorite' directories. They are persisted to a bookmark file, plain text.
    bookmarkfile = tmpdir.join("bookmarkfile")
    bmstore = Bookmarks(str(bookmarkfile))

    # loading an empty bookmark file doesnot crash
    bmstore.load()

    # One can add / remove and check existing of bookmark
    bmstore["h"] = "world"
    assert "h" in bmstore
    del bmstore["h"]

    # Only one letter/digit bookmarks are valid, adding something else fails
    # silently
    bmstore["hello"] = "world"
    assert "hello" not in bmstore

    # The default bookmark is ', remember allows to set it
    bmstore.remember("the milk")
    assert bmstore["'"] == "the milk"

    # We can persist bookmarks to disk and restore them from disk
    bmstore.save()
    secondstore = Bookmarks(str(bookmarkfile))
    secondstore.load()
    assert "'" in secondstore
    assert secondstore["'"] == "the milk"

    # We don't unnecessary update when the file on disk does not change
    origupdate = secondstore.update

    class OutOfDateException(Exception):
        pass

    def crash():
        raise OutOfDateException("Don't access me")
    secondstore.update = crash
    secondstore.update_if_outdated()

    # If the modification time change, we try to read the file
    newtime = time.time() - 5
    os.utime(str(bookmarkfile), (newtime, newtime))
    with pytest.raises(OutOfDateException):
        secondstore.update_if_outdated()
    secondstore.update = origupdate
    secondstore.update_if_outdated()
开发者ID:ajtluser,项目名称:ranger,代码行数:50,代码来源:test_bookmarks.py

示例2: FM

# 需要导入模块: from ranger.container.bookmarks import Bookmarks [as 别名]
# 或者: from ranger.container.bookmarks.Bookmarks import remember [as 别名]

#.........这里部分代码省略.........

    @staticmethod
    def relpath(*paths):
        """returns the path relative to rangers library directory"""
        return os.path.join(ranger.RANGERDIR, *paths)

    def get_directory(self, path, **dir_kwargs):
        """Get the directory object at the given path"""
        path = os.path.abspath(path)
        try:
            return self.directories[path]
        except KeyError:
            obj = Directory(path, **dir_kwargs)
            self.directories[path] = obj
            return obj

    def garbage_collect(
            self, age,
            tabs=None):  # tabs=None is for COMPATibility pylint: disable=unused-argument
        """Delete unused directory objects"""
        for key in tuple(self.directories):
            value = self.directories[key]
            if age != -1:
                if not value.is_older_than(age) \
                        or any(value in tab.pathway for tab in self.tabs.values()):
                    continue
            del self.directories[key]
            if value.is_directory:
                value.files = None
        self.settings.signal_garbage_collect()
        self.signal_garbage_collect()

    def loop(self):
        """The main loop of ranger.

        It consists of:
        1. reloading bookmarks if outdated
        2. letting the loader work
        3. drawing and finalizing ui
        4. reading and handling user input
        5. after X loops: collecting unused directory objects
        """

        self.enter_dir(self.thistab.path)

        # for faster lookup:
        ui = self.ui
        throbber = ui.throbber
        loader = self.loader
        zombies = self.run.zombies

        ranger.api.hook_ready(self)

        try:  # pylint: disable=too-many-nested-blocks
            while True:
                loader.work()
                if loader.has_work():
                    throbber(loader.status)
                else:
                    throbber(remove=True)

                ui.redraw()

                ui.set_load_mode(not loader.paused and loader.has_work())

                ui.draw_images()

                ui.handle_input()

                if zombies:
                    for zombie in tuple(zombies):
                        if zombie.poll() is not None:
                            zombies.remove(zombie)

                # gc_tick += 1
                # if gc_tick > ranger.TICKS_BEFORE_COLLECTING_GARBAGE:
                    # gc_tick = 0
                    # self.garbage_collect(ranger.TIME_BEFORE_FILE_BECOMES_GARBAGE)

        except KeyboardInterrupt:
            # this only happens in --debug mode. By default, interrupts
            # are caught in curses_interrupt_handler
            raise SystemExit

        finally:
            self.image_displayer.quit()
            if ranger.args.choosedir and self.thisdir and self.thisdir.path:
                # XXX: UnicodeEncodeError: 'utf-8' codec can't encode character
                # '\udcf6' in position 42: surrogates not allowed
                with open(ranger.args.choosedir, 'w') as fobj:
                    fobj.write(self.thisdir.path)
            self.bookmarks.remember(self.thisdir)
            self.bookmarks.save()

            # Save tabs
            if not ranger.args.clean and self.settings.save_tabs_on_exit and len(self.tabs) > 1:
                with open(self.datapath('tabs'), 'a') as fobj:
                    # Don't save active tab since launching ranger changes the active tab
                    fobj.write('\0'.join(v.path for t, v in self.tabs.items()
                                         if t != self.current_tab) + '\0\0')
开发者ID:nfnty,项目名称:ranger,代码行数:104,代码来源:fm.py

示例3: FM

# 需要导入模块: from ranger.container.bookmarks import Bookmarks [as 别名]
# 或者: from ranger.container.bookmarks.Bookmarks import remember [as 别名]

#.........这里部分代码省略.........
        """returns the path relative to rangers library directory"""
        return os.path.join(ranger.RANGERDIR, *paths)

    def get_directory(self, path):
        """Get the directory object at the given path"""
        path = os.path.abspath(path)
        try:
            return self.directories[path]
        except KeyError:
            obj = Directory(path)
            self.directories[path] = obj
            return obj

    def garbage_collect(self, age, tabs=None):  # tabs=None is for COMPATibility
        """Delete unused directory objects"""
        for key in tuple(self.directories):
            value = self.directories[key]
            if age != -1:
                if not value.is_older_than(age) \
                        or any(value in tab.pathway for tab in self.tabs.values()):
                    continue
            del self.directories[key]
            if value.is_directory:
                value.files = None
        self.settings.signal_garbage_collect()
        self.signal_garbage_collect()

    def loop(self):
        """The main loop of ranger.

        It consists of:
        1. reloading bookmarks if outdated
        2. letting the loader work
        3. drawing and finalizing ui
        4. reading and handling user input
        5. after X loops: collecting unused directory objects
        """

        self.enter_dir(self.thistab.path)

        gc_tick = 0

        # for faster lookup:
        ui = self.ui
        throbber = ui.throbber
        loader = self.loader
        has_throbber = hasattr(ui, 'throbber')
        zombies = self.run.zombies
        sleeping = False

        ranger.api.hook_ready(self)
        self.control_server.start()

        try:
            while True:
                loader.work()
                if has_throbber:
                    if loader.has_work():
                        throbber(loader.status)
                    else:
                        throbber(remove=True)

                if not sleeping:
                    ui.redraw()
                else:
                    ui.sleep_update()

                ui.set_load_mode(not loader.paused and loader.has_work())

                ui.draw_images()

                had_input = ui.handle_input()
                had_command = self.control_server.act_on_messages()

                sleeping = not (had_input or loader.has_work() or had_command)

                if zombies:
                    for zombie in tuple(zombies):
                        if zombie.poll() is not None:
                            zombies.remove(zombie)

                #gc_tick += 1
                #if gc_tick > ranger.TICKS_BEFORE_COLLECTING_GARBAGE:
                    #gc_tick = 0
                    #self.garbage_collect(ranger.TIME_BEFORE_FILE_BECOMES_GARBAGE)

        except KeyboardInterrupt:
            # this only happens in --debug mode. By default, interrupts
            # are caught in curses_interrupt_handler
            raise SystemExit

        finally:
            self.image_displayer.quit()
            self.control_server.stop()
            if ranger.arg.choosedir and self.thisdir and self.thisdir.path:
                # XXX: UnicodeEncodeError: 'utf-8' codec can't encode character
                # '\udcf6' in position 42: surrogates not allowed
                open(ranger.arg.choosedir, 'w').write(self.thisdir.path)
            self.bookmarks.remember(self.thisdir)
            self.bookmarks.save()
开发者ID:trishume,项目名称:MacRanger,代码行数:104,代码来源:fm.py

示例4: FM

# 需要导入模块: from ranger.container.bookmarks import Bookmarks [as 别名]
# 或者: from ranger.container.bookmarks.Bookmarks import remember [as 别名]

#.........这里部分代码省略.........
        if which == "scope" or which == "all":
            copy("data/scope.sh", "scope.sh")
            os.chmod(self.confpath("scope.sh"), os.stat(self.confpath("scope.sh")).st_mode | stat.S_IXUSR)
        if which not in ("all", "rifle", "scope", "commands", "rc"):
            sys.stderr.write("Unknown config file `%s'\n" % which)

    def confpath(self, *paths):
        """returns the path relative to rangers configuration directory"""
        if ranger.arg.clean:
            assert 0, "Should not access relpath_conf in clean mode!"
        else:
            return os.path.join(ranger.arg.confdir, *paths)

    def relpath(self, *paths):
        """returns the path relative to rangers library directory"""
        return os.path.join(ranger.RANGERDIR, *paths)

    def get_directory(self, path):
        """Get the directory object at the given path"""
        path = os.path.abspath(path)
        try:
            return self.directories[path]
        except KeyError:
            obj = Directory(path)
            self.directories[path] = obj
            return obj

    def garbage_collect(self, age, tabs=None):  # tabs=None is for COMPATibility
        """Delete unused directory objects"""
        for key in tuple(self.directories):
            value = self.directories[key]
            if age != -1:
                if not value.is_older_than(age) or any(value in tab.pathway for tab in self.tabs.values()):
                    continue
            del self.directories[key]
            if value.is_directory:
                value.files = None
        self.settings.signal_garbage_collect()
        self.signal_garbage_collect()

    def loop(self):
        """
		The main loop consists of:
		1. reloading bookmarks if outdated
		2. letting the loader work
		3. drawing and finalizing ui
		4. reading and handling user input
		5. after X loops: collecting unused directory objects
		"""

        self.enter_dir(self.thistab.path)

        gc_tick = 0

        # for faster lookup:
        ui = self.ui
        throbber = ui.throbber
        loader = self.loader
        has_throbber = hasattr(ui, "throbber")
        zombies = self.run.zombies

        ranger.api.hook_ready(self)

        try:
            while True:
                loader.work()
                if has_throbber:
                    if loader.has_work():
                        throbber(loader.status)
                    else:
                        throbber(remove=True)

                ui.redraw()

                ui.set_load_mode(not loader.paused and loader.has_work())

                ui.handle_input()

                if zombies:
                    for zombie in tuple(zombies):
                        if zombie.poll() is not None:
                            zombies.remove(zombie)

                gc_tick += 1
                if gc_tick > ranger.TICKS_BEFORE_COLLECTING_GARBAGE:
                    gc_tick = 0
                    self.garbage_collect(ranger.TIME_BEFORE_FILE_BECOMES_GARBAGE)

        except KeyboardInterrupt:
            # this only happens in --debug mode. By default, interrupts
            # are caught in curses_interrupt_handler
            raise SystemExit

        finally:
            if ranger.arg.choosedir and self.thisdir and self.thisdir.path:
                # XXX: UnicodeEncodeError: 'utf-8' codec can't encode character
                # '\udcf6' in position 42: surrogates not allowed
                open(ranger.arg.choosedir, "w").write(self.thisdir.path)
            self.bookmarks.remember(self.thisdir)
            self.bookmarks.save()
开发者ID:radhermit,项目名称:ranger,代码行数:104,代码来源:fm.py

示例5: FM

# 需要导入模块: from ranger.container.bookmarks import Bookmarks [as 别名]
# 或者: from ranger.container.bookmarks.Bookmarks import remember [as 别名]

#.........这里部分代码省略.........
    def copy_config_files(self, which):
        if ranger.arg.clean:
            sys.stderr.write("refusing to copy config files in clean mode\n")
            return
        import shutil

        def copy(_from, to):
            if os.path.exists(self.confpath(to)):
                sys.stderr.write("already exists: %s\n" % self.confpath(to))
            else:
                sys.stderr.write("creating: %s\n" % self.confpath(to))
                try:
                    shutil.copy(self.relpath(_from), self.confpath(to))
                except Exception as e:
                    sys.stderr.write("  ERROR: %s\n" % str(e))

        if which == "apps" or which == "all":
            copy("defaults/apps.py", "apps.py")
        if which == "commands" or which == "all":
            copy("defaults/commands.py", "commands.py")
        if which == "rc" or which == "all":
            copy("defaults/rc.conf", "rc.conf")
        if which == "options" or which == "all":
            copy("defaults/options.py", "options.py")
        if which == "scope" or which == "all":
            copy("data/scope.sh", "scope.sh")
            os.chmod(self.confpath("scope.sh"), os.stat(self.confpath("scope.sh")).st_mode | stat.S_IXUSR)
        if which not in ("all", "apps", "scope", "commands", "rc", "options"):
            sys.stderr.write("Unknown config file `%s'\n" % which)

    def confpath(self, *paths):
        """returns the path relative to rangers configuration directory"""
        if ranger.arg.clean:
            assert 0, "Should not access relpath_conf in clean mode!"
        else:
            return os.path.join(ranger.arg.confdir, *paths)

    def relpath(self, *paths):
        """returns the path relative to rangers library directory"""
        return os.path.join(ranger.RANGERDIR, *paths)

    def loop(self):
        """
		The main loop consists of:
		1. reloading bookmarks if outdated
		2. letting the loader work
		3. drawing and finalizing ui
		4. reading and handling user input
		5. after X loops: collecting unused directory objects
		"""

        self.env.enter_dir(self.env.path)

        gc_tick = 0

        # for faster lookup:
        ui = self.ui
        throbber = ui.throbber
        loader = self.loader
        env = self.env
        has_throbber = hasattr(ui, "throbber")
        zombies = self.run.zombies

        try:
            while True:
                loader.work()
                if has_throbber:
                    if loader.has_work():
                        throbber(loader.status)
                    else:
                        throbber(remove=True)

                ui.redraw()

                ui.set_load_mode(loader.has_work())

                ui.handle_input()

                if zombies:
                    for zombie in tuple(zombies):
                        if zombie.poll() is not None:
                            zombies.remove(zombie)

                gc_tick += 1
                if gc_tick > TICKS_BEFORE_COLLECTING_GARBAGE:
                    gc_tick = 0
                    env.garbage_collect(TIME_BEFORE_FILE_BECOMES_GARBAGE, self.tabs)

        except KeyboardInterrupt:
            # this only happens in --debug mode. By default, interrupts
            # are caught in curses_interrupt_handler
            raise SystemExit

        finally:
            if ranger.arg.choosedir and self.env.cwd and self.env.cwd.path:
                # XXX: UnicodeEncodeError: 'utf-8' codec can't encode character
                # '\udcf6' in position 42: surrogates not allowed
                open(ranger.arg.choosedir, "w").write(self.env.cwd.path)
            self.bookmarks.remember(env.cwd)
            self.bookmarks.save()
开发者ID:benemal,项目名称:ranger,代码行数:104,代码来源:fm.py


注:本文中的ranger.container.bookmarks.Bookmarks.remember方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。