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


Python PathsHelper.get_backup_filepath方法代碼示例

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


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

示例1: run

# 需要導入模塊: from AutoBackups.autobackups.paths_helper import PathsHelper [as 別名]
# 或者: from AutoBackups.autobackups.paths_helper.PathsHelper import get_backup_filepath [as 別名]
    def run(self):
        backup_per_day = settings.get('backup_per_day')

        window = self.window
        view = window.active_view()

        open_in_same_line = settings.get('open_in_same_line', True)
        if (open_in_same_line):
            (row, col) = view.rowcol(view.sel()[0].begin())
            self.curline = row + 1

        if (not backup_per_day):
            filepath = view.file_name()
            newname = PathsHelper.get_backup_filepath(filepath)
            if os.path.isfile(newname):
                window.open_file(newname)
            else:
                sublime.error_message(
                    'Backup for ' + filepath + ' not exists!')
        else:
            f_files = self.getData(False)

            if not f_files:
                sublime.error_message('Backups for this file not exists!')
                return

            backup_per_time = settings.get('backup_per_time')
            if (backup_per_time):
                window.show_quick_panel(f_files, self.timeFolders)
            else:
                window.show_quick_panel(f_files, self.openFile)
            return
開發者ID:bizoo,項目名稱:sublimetext-autobackups,代碼行數:34,代碼來源:AutoBackups.py

示例2: run

# 需要導入模塊: from AutoBackups.autobackups.paths_helper import PathsHelper [as 別名]
# 或者: from AutoBackups.autobackups.paths_helper.PathsHelper import get_backup_filepath [as 別名]
	def run(self, edit):
		backup_per_day = settings.get('backup_per_day')

		if (not backup_per_day):
			window = sublime.active_window()
			view = sublime.Window.active_view(window)
			filepath = view.file_name()
			newname = PathsHelper.get_backup_filepath(filepath)
			if os.path.isfile(newname):
				window.open_file(newname)
			else:
				sublime.error_message('Backup for ' + filepath + ' not exists!')
		else:
			f_files = self.getData(False)

			if not f_files:
				sublime.error_message('Backups for this file not exists!')
				return

			backup_per_time = settings.get('backup_per_time')
			if (backup_per_time):
				self.view.window().show_quick_panel(f_files, self.timeFolders)
			else:
				self.view.window().show_quick_panel(f_files, self.openFile)
			return
開發者ID:mateatslc,項目名稱:sublimetext-autobackups,代碼行數:27,代碼來源:AutoBackups.py

示例3: save_backup

# 需要導入模塊: from AutoBackups.autobackups.paths_helper import PathsHelper [as 別名]
# 或者: from AutoBackups.autobackups.paths_helper.PathsHelper import get_backup_filepath [as 別名]
	def save_backup(self, view, on_load_event):
		view_size = view.size()
		max_backup_file_size = settings.get('max_backup_file_size_bytes')
		if (view_size is None):
			self.console('Size of view not available')
			return

		if (max_backup_file_size is None):
			self.console('Max allowed size from config not available')
			return



		# don't save files above configured size
		if view_size > max_backup_file_size:
			self.console('Backup not saved, file too large (%d bytes)' % view.size())
			return

		filename = view.file_name()
		newname = PathsHelper.get_backup_filepath(filename)
		if newname == None:
			return

		buffer_id = view.buffer_id()
		content = filename+view.substr(sublime.Region(0, view_size))
		content = self.encode(content)
		current_hash = hashlib.md5(content).hexdigest()

		last_hash = ''
		try:
			last_hash = hashes[buffer_id]
		except Exception as e:
			last_hash = ''


		# not create file backup if no changes from last backup
		if (last_hash == current_hash):
			return

		# not create file backup if current file is backup
		if on_load_event & self.is_backup_file(filename):
			return

		# not create file if exists
		if on_load_event & os.path.isfile(newname):
			return

		(backup_dir, file_to_write) = os.path.split(newname)

		if os.access(backup_dir, os.F_OK) == False:
			os.makedirs(backup_dir)

		shutil.copy(filename, newname)

		hashes[buffer_id] = current_hash
		self.console('Backup saved to: '+newname.replace('\\', '/'))
開發者ID:mateatslc,項目名稱:sublimetext-autobackups,代碼行數:58,代碼來源:AutoBackups.py

示例4: save_backup

# 需要導入模塊: from AutoBackups.autobackups.paths_helper import PathsHelper [as 別名]
# 或者: from AutoBackups.autobackups.paths_helper.PathsHelper import get_backup_filepath [as 別名]
    def save_backup(self, view, on_load_event):
        if not view or view.is_read_only():
            return

        view_size = view.size()
        max_backup_file_size = settings.get('max_backup_file_size_bytes')
        if (view_size is None):
            self.console('Size of view not available')
            return

        if (max_backup_file_size is None):
            self.console('Max allowed size from config not available')
            return

        # don't save files above configured size
        if view_size > max_backup_file_size:
            self.console(
                'Backup not saved, file too large (%d bytes)' % view.size())
            return

        filename = view.file_name()
        if filename is None:
            return

        # not create file backup if current file is backup
        if on_load_event & self.is_backup_file(filename):
            return

        newname = PathsHelper.get_backup_filepath(filename, on_load_event)
        if newname is None:
            return

        last_backupname = lastbackups.get(filename)

        # not create file backup if no changes from last backup
        if filename and last_backupname:
            if filecmp.cmp(filename, last_backupname):
                return

        # not create file if exists
        if on_load_event & os.path.isfile(newname):
            return

        (backup_dir, file_to_write) = os.path.split(newname)

        if not os.access(backup_dir, os.F_OK):
            os.makedirs(backup_dir)

        shutil.copy(filename, newname)

        lastbackups[filename] = newname
        self.console('Backup saved to: ' + newname.replace('\\', '/'))
開發者ID:bizoo,項目名稱:sublimetext-autobackups,代碼行數:54,代碼來源:AutoBackups.py


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