Skip to content

Commit

Permalink
Added setting backup_per_day
Browse files Browse the repository at this point in the history
  • Loading branch information
akalongman committed Jun 3, 2013
1 parent 0aad485 commit 3b3f4b7
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 109 deletions.
21 changes: 12 additions & 9 deletions AutoBackups (Linux).sublime-settings
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
{
// Don't make changes to this file directly as they can get wiped out when the
// plugin is updated. Instead transfer what you need to the 'Settings - User' file.
// Don't make changes to this file directly as they can get wiped out when the
// plugin is updated. Instead transfer what you need to the 'Settings - User' file.

// The directory where we'll keep our backups. If empty, we'll try to put them in
// ~/sublime_backups
"backup_dir": "~/sublime_backups",
// The directory where we'll keep our backups. If empty, we'll try to put them in
// ~/sublime_backups
"backup_dir": "~/sublime_backups",

// If true, also save a backup copy any time a file is opened (if backup file not exists)
"backup_on_open_file": true,
// If true, also save a backup copy any time a file is opened (if backup file not exists)
"backup_on_open_file": true,

// Files larger than this many bytes won't be backed up.
"max_backup_file_size_bytes": 262144 // = 256 KB
// If true, backups saved per day, in separate folders, for example ~/sublime_backups/2013-05-23
"backup_per_day": false,

// Files larger than this many bytes won't be backed up.
"max_backup_file_size_bytes": 262144 // = 256 KB

}
21 changes: 12 additions & 9 deletions AutoBackups (OSX).sublime-settings
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
{
// Don't make changes to this file directly as they can get wiped out when the
// plugin is updated. Instead transfer what you need to the 'Settings - User' file.
// Don't make changes to this file directly as they can get wiped out when the
// plugin is updated. Instead transfer what you need to the 'Settings - User' file.

// The directory where we'll keep our backups. If empty, we'll try to put them in
// ~/sublime_backups
"backup_dir": "~/sublime_backups",
// The directory where we'll keep our backups. If empty, we'll try to put them in
// ~/sublime_backups
"backup_dir": "~/sublime_backups",

// If true, also save a backup copy any time a file is opened (if backup file not exists)
"backup_on_open_file": true,
// If true, also save a backup copy any time a file is opened (if backup file not exists)
"backup_on_open_file": true,

// Files larger than this many bytes won't be backed up.
"max_backup_file_size_bytes": 262144 // = 256 KB
// If true, backups saved per day, in separate folders, for example ~/sublime_backups/2013-05-23
"backup_per_day": false,

// Files larger than this many bytes won't be backed up.
"max_backup_file_size_bytes": 262144 // = 256 KB

}
21 changes: 12 additions & 9 deletions AutoBackups (Windows).sublime-settings
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
{
// Don't make changes to this file directly as they can get wiped out when the
// plugin is updated. Instead transfer what you need to the 'Settings - User' file.
// Don't make changes to this file directly as they can get wiped out when the
// plugin is updated. Instead transfer what you need to the 'Settings - User' file.

// The directory where we'll keep our backups. If empty, we'll try to put them in
// D:/Sublime Text Backups
"backup_dir": "D:/Sublime Text Backups",
// The directory where we'll keep our backups. If empty, we'll try to put them in
// D:/Sublime Text Backups
"backup_dir": "D:/Sublime Text Backups",

// If true, also save a backup copy any time a file is opened (if backup file not exists)
"backup_on_open_file": true,
// If true, also save a backup copy any time a file is opened (if backup file not exists)
"backup_on_open_file": true,

// Files larger than this many bytes won't be backed up.
"max_backup_file_size_bytes": 262144 // = 256 KB
// If true, backups saved per day, in separate folders, for example D:/Sublime Text Backups/2013-05-23
"backup_per_day": false,

// Files larger than this many bytes won't be backed up.
"max_backup_file_size_bytes": 262144 // = 256 KB

}
2 changes: 1 addition & 1 deletion AutoBackups.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def save_backup(self, view, on_load_event):
newname = PathsHelper.get_backup_filepath(filename)
if newname == None:
return

print(newname)
# not create file backup if current file is backup

if on_load_event & self.is_backup_file(filename):
Expand Down
104 changes: 54 additions & 50 deletions autobackups/paths_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,72 +4,76 @@
import os
import re
import sys

if sublime.platform() == 'windows':
try:
from AutoBackups.autobackups.win_helper import WinHelper
except (ImportError):
from win_helper import WinHelper
import datetime

class PathsHelper(object):

@staticmethod
def get_base_dir():
platform = sublime.platform().title()
settings = sublime.load_settings('AutoBackups ('+platform+').sublime-settings')
# Configured setting
backup_dir = settings.get('backup_dir')
@staticmethod
def get_base_dir():
platform = sublime.platform().title()
settings = sublime.load_settings('AutoBackups ('+platform+').sublime-settings')
# Configured setting
backup_dir = settings.get('backup_dir')
now_date = datetime.datetime.now()
date = str(now_date)[:10]

backup_per_day = settings.get('backup_per_day')
if (backup_per_day):
backup_dir = backup_dir +'/'+ date


if backup_dir != '':
return os.path.expanduser(backup_dir)

# Windows: <user folder>/My Documents/Sublime Text Backups
if (sublime.platform() == 'windows'):
backup_dir = 'D:/Sublime Text Backups'
if (backup_per_day):
backup_dir = backup_dir +'/'+ date
return backup_dir

if backup_dir != '':
return os.path.expanduser(backup_dir)
# Linux/OSX/other: ~/sublime_backups
backup_dir = '~/.sublime/backups'
if (backup_per_day):
backup_dir = backup_dir +'/'+ date
return os.path.expanduser(backup_dir)

# Windows: <user folder>/My Documents/Sublime Text Backups
if sublime.platform() == 'windows':
return os.path.join(
WinHelper.get_shell_folder('Personal'),
'Sublime Text Backups')
@staticmethod
def timestamp_file(filename):
(filepart, extensionpart) = os.path.splitext(filename)
return '%s%s' % (filepart, extensionpart,)

# Linux/OSX/other: ~/sublime_backups
return os.path.expanduser('~/.sublime/backups')
@staticmethod
def get_backup_path(filepath):
path = os.path.expanduser(os.path.split(filepath)[0])
backup_base = PathsHelper.get_base_dir()
path = PathsHelper.normalise_path(path)
return os.path.join(backup_base, path)

@staticmethod
def timestamp_file(filename):
@staticmethod
def normalise_path(path):

(filepart, extensionpart) = os.path.splitext(filename)
return '%s%s' % (
filepart,
extensionpart,
)
if sublime.platform() != 'windows':
# remove any leading / before combining with backup_base
path = re.sub(r'^/', '', path)
return path

@staticmethod
def get_backup_path(filepath):
path = os.path.expanduser(os.path.split(filepath)[0])
backup_base = PathsHelper.get_base_dir()
path = PathsHelper.normalise_path(path)
return os.path.join(backup_base, path)
path = path.replace('/', '\\')

@staticmethod
def normalise_path(path):

if sublime.platform() != 'windows':
# remove any leading / before combining with backup_base
path = re.sub(r'^/', '', path)
return path
# windows only: transform C: into just C
path = re.sub(r'^(\w):', r'\1', path)

path = path.replace('/', '\\')
# windows only: transform \\remotebox\share into network\remotebox\share
path = re.sub(r'^\\\\([\w\-]{2,})', r'network\\\1', path)
return path


# windows only: transform C: into just C
path = re.sub(r'^(\w):', r'\1', path)

# windows only: transform \\remotebox\share into network\remotebox\share
path = re.sub(r'^\\\\([\w\-]{2,})', r'network\\\1', path)
return path
@staticmethod
def get_backup_filepath(filepath):
@staticmethod
def get_backup_filepath(filepath):

filename = os.path.split(filepath)[1]
filename = os.path.split(filepath)[1]

return os.path.join(PathsHelper.get_backup_path(filepath), PathsHelper.timestamp_file(filename))
return os.path.join(PathsHelper.get_backup_path(filepath), PathsHelper.timestamp_file(filename))

28 changes: 0 additions & 28 deletions autobackups/win_helper.py

This file was deleted.

6 changes: 3 additions & 3 deletions packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
"description": "AutoBackups is a Sublime Text 2/3 plugin, which automatically save a backup copy every time you save or open (if backup file not exists) a file. (Like DreamWeaver)",
"author": "Avtandil Kikabidze",
"homepage": "https://github.com/akalongman/sublimetext-autobackups",
"last_modified": "2013-05-13 13:44",
"last_modified": "2013-06-04 02:17",
"platforms": {
"*": [
{
"version": "1.1",
"url": "https://nodeload.github.com/akalongman/sublimetext-autobackups/zip/1.1"
"version": "1.2",
"url": "https://nodeload.github.com/akalongman/sublimetext-autobackups/zip/1.2"
}
]
}
Expand Down

0 comments on commit 3b3f4b7

Please sign in to comment.