本文整理汇总了Python中AutoBackups.autobackups.paths_helper.PathsHelper.get_base_dir方法的典型用法代码示例。如果您正苦于以下问题:Python PathsHelper.get_base_dir方法的具体用法?Python PathsHelper.get_base_dir怎么用?Python PathsHelper.get_base_dir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AutoBackups.autobackups.paths_helper.PathsHelper
的用法示例。
在下文中一共展示了PathsHelper.get_base_dir方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from AutoBackups.autobackups.paths_helper import PathsHelper [as 别名]
# 或者: from AutoBackups.autobackups.paths_helper.PathsHelper import get_base_dir [as 别名]
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)
示例2: run
# 需要导入模块: from AutoBackups.autobackups.paths_helper import PathsHelper [as 别名]
# 或者: from AutoBackups.autobackups.paths_helper.PathsHelper import get_base_dir [as 别名]
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)
示例3: is_backup_file
# 需要导入模块: from AutoBackups.autobackups.paths_helper import PathsHelper [as 别名]
# 或者: from AutoBackups.autobackups.paths_helper.PathsHelper import get_base_dir [as 别名]
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
示例4: getData
# 需要导入模块: from AutoBackups.autobackups.paths_helper import PathsHelper [as 别名]
# 或者: from AutoBackups.autobackups.paths_helper.PathsHelper import get_base_dir [as 别名]
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))
#.........这里部分代码省略.........