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


Python paths_helper.PathsHelper类代码示例

本文整理汇总了Python中AutoBackups.autobackups.paths_helper.PathsHelper的典型用法代码示例。如果您正苦于以下问题:Python PathsHelper类的具体用法?Python PathsHelper怎么用?Python PathsHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: run

    def run(self):
        path = self.window.active_view().file_name()

        recover_path = os.path.dirname(path) if path else self.window.folders()[0]
        normalized_path = PathsHelper.normalise_path(recover_path)
        backups_path = PathsHelper.get_base_dir(True)

        confirmation = sublime.ok_cancel_dialog(self.DIALOG_TEXT % recover_path)
        if confirmation:
            restore_folder(backups_path, normalized_path, recover_path)
开发者ID:cryzed,项目名称:sublimetext-autobackups,代码行数:10,代码来源:AutoBackups.py

示例2: is_backup_file

    def is_backup_file(self, path):
        backup_per_time = settings.get('backup_per_time')
        path = PathsHelper.normalise_path(path)
        base_dir = PathsHelper.get_base_dir(False)
        base_dir = PathsHelper.normalise_path(base_dir)
        if (backup_per_time == 'folder'):
            base_dir = base_dir[:-7]

        backup_dir_len = len(base_dir)
        sub = path[0:backup_dir_len]

        if sub == base_dir:
            return True
        else:
            return False
开发者ID:bizoo,项目名称:sublimetext-autobackups,代码行数:15,代码来源:AutoBackups.py

示例3: run

    def run(self):
        import datetime
        basedir = PathsHelper.get_base_dir(True)
        backup_time = self.backup_time

        if (backup_time < 1):
            return

        diff = (backup_time + 1) * 24 * 3600
        deleted = 0
        now_time = time.time()
        for folder in os.listdir(basedir):
            match = re.search(r"^[0-9]{4}-[0-9]{2}-[0-9]{2}$", folder)
            if match is not None:
                folder_time = time.mktime(
                    datetime.datetime.strptime(folder, "%Y-%m-%d").timetuple())
                if (now_time - folder_time > diff):
                    fldr = basedir + '/' + folder
                    try:
                        shutil.rmtree(fldr, onerror=self.onerror)
                        deleted = deleted + 1
                    except Exception as e:
                        print(e)

        if (deleted > 0):
            diff = backup_time * 24 * 3600
            dt = now_time - diff
            date = datetime.datetime.fromtimestamp(dt).strftime('%Y-%m-%d')
            print('AutoBackups: Deleted ' + str(deleted) +
                  ' backup folders older than ' + date)
开发者ID:bizoo,项目名称:sublimetext-autobackups,代码行数:30,代码来源:AutoBackups.py

示例4: run

	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,代码行数:25,代码来源:AutoBackups.py

示例5: plugin_loaded

def plugin_loaded():
    global settings
    global hashes

    hashes = {}
    platform = sublime.platform().title()

    if (platform == "Osx"):
        platform = "OSX"
    settings = sublime.load_settings('AutoBackups ('+platform+').sublime-settings')

    backup_dir = settings.get('backup_dir')
    backup_per_day = settings.get('backup_per_day')
    backup_per_time = settings.get('backup_per_time')

    PathsHelper.initialize(platform, backup_dir, backup_per_day, backup_per_time)
    cprint('AutoBackups: Plugin Initialized')
    sublime.set_timeout(gc, 10000)
开发者ID:mayroncachina,项目名称:sublimetext-autobackups,代码行数:18,代码来源:AutoBackups.py

示例6: save_backup

	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,代码行数:56,代码来源:AutoBackups.py

示例7: save_backup

    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,代码行数:52,代码来源:AutoBackups.py

示例8: getData

    def getData(self, time_folder):
        filename = PathsHelper.normalise_path(
            self.window.active_view().file_name(), True)
        basedir = PathsHelper.get_base_dir(True)

        backup_per_time = settings.get('backup_per_time')
        if (backup_per_time):
            if (backup_per_time == 'folder'):
                f_files = []
                if (time_folder is not False):
                    tm_folders = self.getData(False)
                    tm_folder = tm_folders[time_folder][0]
                    basedir = basedir + '/' + tm_folder

                    if (not os.path.isdir(basedir)):
                        sublime.error_message(
                            'Folder ' + basedir + ' not found!')

                    for folder in os.listdir(basedir):
                        fl = basedir + '/' + folder + '/' + filename
                        match = re.search(r"^[0-9+]{6}$", folder)
                        if os.path.isfile(fl) and match is not None:
                            folder_name, file_name = os.path.split(fl)
                            f_file = []
                            thetime = self.formatTime(folder)
                            f_file.append(thetime + ' - ' + file_name)
                            f_file.append(fl)
                            f_files.append(f_file)
                else:
                    path, flname = os.path.split(filename)
                    (filepart, extpart) = os.path.splitext(flname)
                    for folder in os.listdir(basedir):
                        match = re.search(
                            r"^[0-9+]{4}-[0-9+]{2}-[0-9+]{2}$", folder)
                        if match is not None:
                            folder_name, file_name = os.path.split(filename)
                            f_file = []
                            basedir2 = basedir + '/' + folder
                            count = 0
                            last = ''
                            for folder2 in os.listdir(basedir2):
                                match = re.search(r"^[0-9+]{6}$", folder2)
                                if match is not None:
                                    basedir3 = basedir + '/' + folder + \
                                        '/' + folder2 + '/' + filename
                                    if os.path.isfile(basedir3):
                                        count += 1
                                        last = folder2
                            if (count > 0):
                                f_file.append(folder)
                                f_file.append(
                                    'Backups: ' + str(count) + ', Last edit: ' + self.formatTime(last))
                                f_files.append(f_file)
            elif (backup_per_time == 'file'):
                f_files = []
                if (time_folder is not False):
                    tm_folders = self.getData(False)
                    tm_folder = tm_folders[time_folder][0]
                    path, flname = os.path.split(filename)
                    basedir = basedir + '/' + tm_folder + '/' + path
                    (filepart, extpart) = os.path.splitext(flname)

                    if (not os.path.isdir(basedir)):
                        sublime.error_message(
                            'Folder ' + basedir + ' not found!')

                    for folder in os.listdir(basedir):
                        fl = basedir + '/' + folder
                        match = re.search(
                            r"^" + re.escape(filepart) + "_([0-9+]{6})" + re.escape(extpart) + "$", folder)

                        if os.path.isfile(fl) and match is not None:
                            thetime = self.formatTime(match.group(1))
                            f_file = []
                            f_file.append(thetime + ' - ' + flname)
                            f_file.append(fl)
                            f_files.append(f_file)
                else:
                    path, flname = os.path.split(filename)
                    (filepart, extpart) = os.path.splitext(flname)
                    for folder in os.listdir(basedir):
                        match = re.search(
                            r"^[0-9+]{4}-[0-9+]{2}-[0-9+]{2}$", folder)
                        if match is not None:
                            folder_name, file_name = os.path.split(filename)
                            f_file = []
                            basedir2 = basedir + '/' + folder + '/' + path
                            count = 0
                            last = ''
                            if (os.path.isdir(basedir2)):
                                for sfile in os.listdir(basedir2):
                                    match = re.search(
                                        r"^" + re.escape(filepart) + "_([0-9+]{6})" + re.escape(extpart) + "$", sfile)
                                    if match is not None:
                                        count += 1
                                        last = match.group(1)
                            if (count > 0):
                                f_file.append(folder)
                                f_file.append(
                                    'Backups: ' + str(count) + ', Last edit: ' + self.formatTime(last))
#.........这里部分代码省略.........
开发者ID:bizoo,项目名称:sublimetext-autobackups,代码行数:101,代码来源:AutoBackups.py


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