當前位置: 首頁>>代碼示例>>Python>>正文


Python Bookmarks.save方法代碼示例

本文整理匯總了Python中ranger.container.bookmarks.Bookmarks.save方法的典型用法代碼示例。如果您正苦於以下問題:Python Bookmarks.save方法的具體用法?Python Bookmarks.save怎麽用?Python Bookmarks.save使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ranger.container.bookmarks.Bookmarks的用法示例。


在下文中一共展示了Bookmarks.save方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_bookmark_symlink

# 需要導入模塊: from ranger.container.bookmarks import Bookmarks [as 別名]
# 或者: from ranger.container.bookmarks.Bookmarks import save [as 別名]
def test_bookmark_symlink(tmpdir):
    # Initialize plain file and symlink paths
    bookmarkfile_link = tmpdir.join("bookmarkfile")
    bookmarkfile_orig = tmpdir.join("bookmarkfile.orig")

    # Create symlink pointing towards the original plain file.
    os.symlink(str(bookmarkfile_orig), str(bookmarkfile_link))

    # Initialize the bookmark file and save the file.
    bmstore = Bookmarks(str(bookmarkfile_link))
    bmstore.save()

    # Once saved, the bookmark file should still be a symlink pointing towards the plain file.
    assert os.path.islink(str(bookmarkfile_link))
    assert not os.path.islink(str(bookmarkfile_orig))
開發者ID:phantasea,項目名稱:ranger,代碼行數:17,代碼來源:test_bookmarks.py

示例2: testbookmarks

# 需要導入模塊: from ranger.container.bookmarks import Bookmarks [as 別名]
# 或者: from ranger.container.bookmarks.Bookmarks import save [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

示例3: test_messing_around

# 需要導入模塊: from ranger.container.bookmarks import Bookmarks [as 別名]
# 或者: from ranger.container.bookmarks.Bookmarks import save [as 別名]
	def test_messing_around(self):
		bm = Bookmarks(BMFILE, str, autosave=False)
		bm2 = Bookmarks(BMFILE, str, autosave=False)

		bm.load()
		bm['a'] = 'car'

		bm2.load()
		self.assertRaises(KeyError, bm2.__getitem__, 'a')

		bm2.save()
		bm.update()
		bm.save()
		bm.load()
		bm2.load()

		self.assertEqual(bm['a'], bm2['a'])
開發者ID:Dieterbe,項目名稱:ranger,代碼行數:19,代碼來源:tc_bookmarks.py

示例4: test_sharing_bookmarks_between_instances

# 需要導入模塊: from ranger.container.bookmarks import Bookmarks [as 別名]
# 或者: from ranger.container.bookmarks.Bookmarks import save [as 別名]
	def test_sharing_bookmarks_between_instances(self):
		bm = Bookmarks(BMFILE, str, autosave=True)
		bm2 = Bookmarks(BMFILE, str, autosave=True)

		bm.load()
		bm2.load()
		bm['a'] = 'fooo'
		self.assertRaises(KeyError, bm2.__getitem__, 'a')

		bm.save()
		bm2.load()
		self.assertEqual(bm['a'], bm2['a'])

		bm2['a'] = 'bar'

		bm.save()
		bm2.save()
		bm.load()
		bm2.load()

		self.assertEqual(bm['a'], bm2['a'])
開發者ID:Dieterbe,項目名稱:ranger,代碼行數:23,代碼來源:tc_bookmarks.py

示例5: FM

# 需要導入模塊: from ranger.container.bookmarks import Bookmarks [as 別名]
# 或者: from ranger.container.bookmarks.Bookmarks import save [as 別名]
class FM(Actions,  # pylint: disable=too-many-instance-attributes
         SignalDispatcher):
    input_blocked = False
    input_blocked_until = 0
    mode = 'normal'  # either 'normal' or 'visual'.
    search_method = 'ctime'

    _previous_selection = None
    _visual_reverse = False
    _visual_pos_start = None
    _visual_move_cycles = None

    def __init__(self, ui=None, bookmarks=None, tags=None, paths=None):
        """Initialize FM."""
        Actions.__init__(self)
        SignalDispatcher.__init__(self)
        self.ui = ui if ui is not None else UI()
        self.start_paths = paths if paths is not None else ['.']
        self.directories = dict()
        self.bookmarks = bookmarks
        self.current_tab = 1
        self.tabs = {}
        self.tags = tags
        self.restorable_tabs = deque([], ranger.MAX_RESTORABLE_TABS)
        self.py3 = sys.version_info >= (3, )
        self.previews = {}
        self.default_linemodes = deque()
        self.loader = Loader()
        self.copy_buffer = set()
        self.do_cut = False
        self.metadata = MetadataManager()
        self.image_displayer = None
        self.run = None
        self.rifle = None
        self.thistab = None

        try:
            self.username = pwd.getpwuid(os.geteuid()).pw_name
        except KeyError:
            self.username = 'uid:' + str(os.geteuid())
        self.hostname = socket.gethostname()
        self.home_path = os.path.expanduser('~')

        mimetypes.knownfiles.append(os.path.expanduser('~/.mime.types'))
        mimetypes.knownfiles.append(self.relpath('data/mime.types'))
        self.mimetypes = mimetypes.MimeTypes()

    def initialize(self):
        """If ui/bookmarks are None, they will be initialized here."""

        self.tabs = dict((n + 1, Tab(path)) for n, path in enumerate(self.start_paths))
        tab_list = self.get_tab_list()
        if tab_list:
            self.current_tab = tab_list[0]
            self.thistab = self.tabs[self.current_tab]
        else:
            self.current_tab = 1
            self.tabs[self.current_tab] = self.thistab = Tab('.')

        if not ranger.args.clean and os.path.isfile(self.confpath('rifle.conf')):
            rifleconf = self.confpath('rifle.conf')
        else:
            rifleconf = self.relpath('config/rifle.conf')
        self.rifle = Rifle(rifleconf)
        self.rifle.reload_config()

        def set_image_displayer():
            self.image_displayer = self._get_image_displayer()
        set_image_displayer()
        self.settings.signal_bind('setopt.preview_images_method', set_image_displayer,
                                  priority=settings.SIGNAL_PRIORITY_AFTER_SYNC)

        self.settings.signal_bind(
            'setopt.preview_images',
            lambda signal: signal.fm.previews.clear(),
        )

        if ranger.args.clean:
            self.tags = TagsDummy("")
        elif self.tags is None:
            self.tags = Tags(self.datapath('tagged'))

        if self.bookmarks is None:
            if ranger.args.clean:
                bookmarkfile = None
            else:
                bookmarkfile = self.datapath('bookmarks')
            self.bookmarks = Bookmarks(
                bookmarkfile=bookmarkfile,
                bookmarktype=Directory,
                autosave=self.settings.autosave_bookmarks)
            self.bookmarks.load()

        self.ui.setup_curses()
        self.ui.initialize()

        self.rifle.hook_before_executing = lambda a, b, flags: \
            self.ui.suspend() if 'f' not in flags else None
        self.rifle.hook_after_executing = lambda a, b, flags: \
            self.ui.initialize() if 'f' not in flags else None
#.........這裏部分代碼省略.........
開發者ID:nfnty,項目名稱:ranger,代碼行數:103,代碼來源:fm.py

示例6: FM

# 需要導入模塊: from ranger.container.bookmarks import Bookmarks [as 別名]
# 或者: from ranger.container.bookmarks.Bookmarks import save [as 別名]
class FM(Actions, SignalDispatcher):
    input_blocked = False
    input_blocked_until = 0
    mode = "normal"  # either 'normal' or 'visual'.
    search_method = "ctime"

    _previous_selection = None
    _visual_reverse = False
    _visual_start = None
    _visual_start_pos = None

    def __init__(self, ui=None, bookmarks=None, tags=None, paths=["."]):
        """Initialize FM."""
        Actions.__init__(self)
        SignalDispatcher.__init__(self)
        if ui is None:
            self.ui = UI()
        else:
            self.ui = ui
        self.start_paths = paths
        self.directories = dict()
        self.log = deque(maxlen=20)
        self.bookmarks = bookmarks
        self.current_tab = 1
        self.tabs = {}
        self.tags = tags
        self.restorable_tabs = deque([], ranger.MAX_RESTORABLE_TABS)
        self.py3 = sys.version_info >= (3,)
        self.previews = {}
        self.loader = Loader()
        self.copy_buffer = set()
        self.do_cut = False

        try:
            self.username = pwd.getpwuid(os.geteuid()).pw_name
        except:
            self.username = "uid:" + str(os.geteuid())
        self.hostname = socket.gethostname()
        self.home_path = os.path.expanduser("~")

        self.log.append("ranger {0} started! Process ID is {1}.".format(__version__, os.getpid()))
        self.log.append("Running on Python " + sys.version.replace("\n", ""))

        mimetypes.knownfiles.append(os.path.expanduser("~/.mime.types"))
        mimetypes.knownfiles.append(self.relpath("data/mime.types"))
        self.mimetypes = mimetypes.MimeTypes()

    def initialize(self):
        """If ui/bookmarks are None, they will be initialized here."""

        self.tabs = dict((n + 1, Tab(path)) for n, path in enumerate(self.start_paths))
        tab_list = self._get_tab_list()
        if tab_list:
            self.current_tab = tab_list[0]
            self.thistab = self.tabs[self.current_tab]
        else:
            self.current_tab = 1
            self.tabs[self.current_tab] = self.thistab = Tab(".")

        if not ranger.arg.clean and os.path.isfile(self.confpath("rifle.conf")):
            rifleconf = self.confpath("rifle.conf")
        else:
            rifleconf = self.relpath("config/rifle.conf")
        self.rifle = Rifle(rifleconf)
        self.rifle.reload_config()

        if self.bookmarks is None:
            if ranger.arg.clean:
                bookmarkfile = None
            else:
                bookmarkfile = self.confpath("bookmarks")
            self.bookmarks = Bookmarks(
                bookmarkfile=bookmarkfile, bookmarktype=Directory, autosave=self.settings.autosave_bookmarks
            )
            self.bookmarks.load()

        if not ranger.arg.clean and self.tags is None:
            self.tags = Tags(self.confpath("tagged"))

        self.ui.setup_curses()
        self.ui.initialize()

        self.rifle.hook_before_executing = lambda a, b, flags: self.ui.suspend() if "f" not in flags else None
        self.rifle.hook_after_executing = lambda a, b, flags: self.ui.initialize() if "f" not in flags else None
        self.rifle.hook_logger = self.notify

        def mylogfunc(text):
            self.notify(text, bad=True)

        self.run = Runner(ui=self.ui, logfunc=mylogfunc, fm=self)

    def destroy(self):
        debug = ranger.arg.debug
        if self.ui:
            try:
                self.ui.destroy()
            except:
                if debug:
                    raise
        if self.loader:
#.........這裏部分代碼省略.........
開發者ID:radhermit,項目名稱:ranger,代碼行數:103,代碼來源:fm.py

示例7: FM

# 需要導入模塊: from ranger.container.bookmarks import Bookmarks [as 別名]
# 或者: from ranger.container.bookmarks.Bookmarks import save [as 別名]
class FM(Actions, SignalDispatcher):
    input_blocked = False
    input_blocked_until = 0
    mode = 'normal'  # either 'normal' or 'visual'.
    search_method = 'ctime'

    _previous_selection = None
    _visual_reverse = False
    _visual_start = None
    _visual_start_pos = None

    def __init__(self, ui=None, bookmarks=None, tags=None, paths=['.']):
        """Initialize FM."""
        Actions.__init__(self)
        SignalDispatcher.__init__(self)
        if ui is None:
            self.ui = UI()
        else:
            self.ui = ui
        self.start_paths = paths
        self.directories = dict()
        self.log = deque(maxlen=20)
        self.image_displayer = ImageDisplayer(self)
        self.bookmarks = bookmarks
        self.current_tab = 1
        self.tabs = {}
        self.tags = tags
        self.restorable_tabs = deque([], ranger.MAX_RESTORABLE_TABS)
        self.py3 = sys.version_info >= (3, )
        self.previews = {}
        self.loader = Loader()
        self.copy_buffer = set()
        self.do_cut = False
        self.control_server = RangerControlServer(self)

        try:
            self.username = pwd.getpwuid(os.geteuid()).pw_name
        except:
            self.username = 'uid:' + str(os.geteuid())
        self.hostname = socket.gethostname()
        self.home_path = os.path.expanduser('~')

        self.log.append('ranger {0} started! Process ID is {1}.' \
                .format(__version__, os.getpid()))
        self.log.append('Running on Python ' + sys.version.replace('\n',''))

        mimetypes.knownfiles.append(os.path.expanduser('~/.mime.types'))
        mimetypes.knownfiles.append(self.relpath('data/mime.types'))
        self.mimetypes = mimetypes.MimeTypes()

    def initialize(self):
        """If ui/bookmarks are None, they will be initialized here."""

        self.tabs = dict((n+1, Tab(path)) for n, path in
                enumerate(self.start_paths))
        tab_list = self._get_tab_list()
        if tab_list:
            self.current_tab = tab_list[0]
            self.thistab = self.tabs[self.current_tab]
        else:
            self.current_tab = 1
            self.tabs[self.current_tab] = self.thistab = Tab('.')

        if not ranger.arg.clean and os.path.isfile(self.confpath('rifle.conf')):
            rifleconf = self.confpath('rifle.conf')
        else:
            rifleconf = self.relpath('config/rifle.conf')
        self.rifle = Rifle(rifleconf)
        self.rifle.reload_config()

        if self.bookmarks is None:
            if ranger.arg.clean:
                bookmarkfile = None
            else:
                bookmarkfile = self.confpath('bookmarks')
            self.bookmarks = Bookmarks(
                    bookmarkfile=bookmarkfile,
                    bookmarktype=Directory,
                    autosave=self.settings.autosave_bookmarks)
            self.bookmarks.load()

        if not ranger.arg.clean and self.tags is None:
            self.tags = Tags(self.confpath('tagged'))

        self.ui.setup_curses()
        self.ui.initialize()

        self.rifle.hook_before_executing = lambda a, b, flags: \
            self.ui.suspend() if 'f' not in flags else None
        self.rifle.hook_after_executing = lambda a, b, flags: \
            self.ui.initialize() if 'f' not in flags else None
        self.rifle.hook_logger = self.notify

        # This hook allows image viewers to open all images in the current
        # directory, keeping the order of files the same as in ranger.
        # The requirements to use it are:
        # 1. set open_all_images to true
        # 2. ensure no files are marked
        # 3. call rifle with a command that starts with "sxiv " or "feh "
        def sxiv_workaround_hook(command):
#.........這裏部分代碼省略.........
開發者ID:trishume,項目名稱:MacRanger,代碼行數:103,代碼來源:fm.py

示例8: FM

# 需要導入模塊: from ranger.container.bookmarks import Bookmarks [as 別名]
# 或者: from ranger.container.bookmarks.Bookmarks import save [as 別名]
class FM(Actions, SignalDispatcher):
    input_blocked = False
    input_blocked_until = 0

    def __init__(self, ui=None, bookmarks=None, tags=None):
        """Initialize FM."""
        Actions.__init__(self)
        SignalDispatcher.__init__(self)
        self.ui = ui
        self.log = deque(maxlen=20)
        self.bookmarks = bookmarks
        self.tags = tags
        self.tabs = {}
        self.py3 = sys.version_info >= (3,)
        self.previews = {}
        self.current_tab = 1
        self.loader = Loader()

        self.log.append("ranger {0} started! Process ID is {1}.".format(__version__, os.getpid()))
        self.log.append("Running on Python " + sys.version.replace("\n", ""))

        mimetypes.knownfiles.append(os.path.expanduser("~/.mime.types"))
        mimetypes.knownfiles.append(self.relpath("data/mime.types"))
        self.mimetypes = mimetypes.MimeTypes()

    def initialize(self):
        """If ui/bookmarks are None, they will be initialized here."""
        if self.bookmarks is None:
            if ranger.arg.clean:
                bookmarkfile = None
            else:
                bookmarkfile = self.confpath("bookmarks")
            self.bookmarks = Bookmarks(
                bookmarkfile=bookmarkfile, bookmarktype=Directory, autosave=self.settings.autosave_bookmarks
            )
            self.bookmarks.load()

        if not ranger.arg.clean and self.tags is None:
            self.tags = Tags(self.confpath("tagged"))

        if self.ui is None:
            self.ui = UI()
            self.ui.initialize()

        def mylogfunc(text):
            self.notify(text, bad=True)

        self.run = Runner(ui=self.ui, apps=self.apps, logfunc=mylogfunc, fm=self)

        self.env.signal_bind("cd", self._update_current_tab)

        if self.settings.init_function:
            self.settings.init_function(self)

    def destroy(self):
        debug = ranger.arg.debug
        if self.ui:
            try:
                self.ui.destroy()
            except:
                if debug:
                    raise
        if self.loader:
            try:
                self.loader.destroy()
            except:
                if debug:
                    raise

    def block_input(self, sec=0):
        self.input_blocked = sec != 0
        self.input_blocked_until = time() + sec

    def input_is_blocked(self):
        if self.input_blocked and time() > self.input_blocked_until:
            self.input_blocked = False
        return self.input_blocked

    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")
#.........這裏部分代碼省略.........
開發者ID:benemal,項目名稱:ranger,代碼行數:103,代碼來源:fm.py


注:本文中的ranger.container.bookmarks.Bookmarks.save方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。