Skip to content

Commit

Permalink
Added ignore_regexes setting. Added Donate menu item
Browse files Browse the repository at this point in the history
  • Loading branch information
akalongman committed May 2, 2015
1 parent 7903a07 commit a2453dd
Show file tree
Hide file tree
Showing 4 changed files with 280 additions and 1 deletion.
261 changes: 261 additions & 0 deletions AutoBackups.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ def save_backup(self, view, on_load_event):
if filename == None:
return

# Check file path in excluded regexes
if self.is_excluded(filename):
#cprint("AutoBackups: " + filename + " is excluded");
return



# not create file backup if current file is backup
if on_load_event & self.is_backup_file(filename):
return
Expand Down Expand Up @@ -176,6 +183,22 @@ def is_backup_file(self, path):
else:
return False

def is_excluded(self, filename):
# check
ignore_regexes = settings.get('ignore_regexes')

if (ignore_regexes is None or ignore_regexes == ""):
return False

for regex in ignore_regexes:
prog = re.compile('.*'+regex+'.*')
result = prog.match(filename)
if result is not None:
return True

return False


def console(self, text):
cprint(text)

Expand Down Expand Up @@ -439,6 +462,244 @@ def onerror(self, func, path, exc_info):
raise


class AutoBackupsDonateCommand(sublime_plugin.WindowCommand):
def run(self, paths = []):
sublime.message_dialog('AutoBackups: Thanks for your support ^_^')
browser = settings.get("default_browser", "")
AutoBackupsOpenInBrowserThread('','').try_open("https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=MVCBM7M2RCEX6&lc=US&item_name=Support%20our%20open%2dsource%20initiatives&item_number=donation&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donate_LG%2egif%3aNonHosted", browser)


class AutoBackupsOpenInBrowserThread(threading.Thread):
def __init__(self, url, browser):
self.url = url
self.browser = browser
threading.Thread.__init__(self)

def run(self):
url = self.url
browser = self.browser

self.try_open(url, browser)

def try_open(self, url, browser):
import subprocess

if sublime.platform() == 'windows':
import winreg

browser = browser.lower().strip();
items = []

if browser == 'chrome':
if sublime.platform() == 'osx':
items.extend(['open'])
commands = ['-a', '/Applications/Google Chrome.app', url]
elif sublime.platform() == 'windows':
aKey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, r"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders")
reg_value, reg_type = winreg.QueryValueEx (aKey, "Local AppData")

items.extend([
'%HOMEPATH%\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe'

,reg_value+'\\Chrome\\Application\\chrome.exe'
,reg_value+'\\Google\\Chrome\\Application\\chrome.exe'
,'%HOMEPATH%\\Google\\Chrome\\Application\\chrome.exe'
,'%PROGRAMFILES%\\Google\\Chrome\\Application\\chrome.exe'
,'%PROGRAMFILES(X86)%\\Google\\Chrome\\Application\\chrome.exe'
,'%USERPROFILE%\\Local\ Settings\\Application\ Data\\Google\\Chrome\\chrome.exe'
,'%HOMEPATH%\\Chromium\\Application\\chrome.exe'
,'%PROGRAMFILES%\\Chromium\\Application\\chrome.exe'
,'%PROGRAMFILES(X86)%\\Chromium\\Application\\chrome.exe'
,'%HOMEPATH%\\Local\ Settings\\Application\ Data\\Google\\Chrome\\Application\\chrome.exe'
,'%HOMEPATH%\\Local Settings\\Application Data\\Google\\Chrome\\Application\\chrome.exe'
,'chrome.exe'
])


commands = ['-new-tab', url]
else:
items.extend([
'/usr/bin/google-chrome'
,'/opt/google/chrome/chrome'
,'chrome'
,'google-chrome'
])
commands = ['-new-tab', url]

elif browser == 'canary':
if sublime.platform() == 'osx':
items.extend(['open'])
commands = ['-a', '/Applications/Google Chrome Canary.app', url]
elif sublime.platform() == 'windows':
aKey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, r"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders")
reg_value, reg_type = winreg.QueryValueEx (aKey, "Local AppData")

items.extend([
'%HOMEPATH%\\AppData\\Local\\Google\\Chrome SxS\\Application\\chrome.exe'

,reg_value+'\\Chrome SxS\\Application\\chrome.exe'
,reg_value+'\\Google\\Chrome SxS\\Application\\chrome.exe'
,'%HOMEPATH%\\Google\\Chrome SxS\\Application\\chrome.exe'
,'%PROGRAMFILES%\\Google\\Chrome SxS\\Application\\chrome.exe'
,'%PROGRAMFILES(X86)%\\Google\\Chrome SxS\\Application\\chrome.exe'
,'%USERPROFILE%\\Local\ Settings\\Application\ Data\\Google\\Chrome SxS\\chrome.exe'
,'%HOMEPATH%\\Local\ Settings\\Application\ Data\\Google\\Chrome SxS\\Application\\chrome.exe'
,'%HOMEPATH%\\Local Settings\\Application Data\\Google\\Chrome SxS\\Application\\chrome.exe'
])

commands = ['-new-tab', url]

elif browser == 'chromium':
if sublime.platform() == 'osx':
items.extend(['open'])
commands = ['-a', '/Applications/Chromium.app', url]
elif sublime.platform() == 'windows':
aKey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, r"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders")
reg_value, reg_type = winreg.QueryValueEx (aKey, "Local AppData")
items.extend([
'%HOMEPATH%\\AppData\\Local\\Google\\Chrome SxS\\Application\\chrome.exe'

, reg_value+'\\Chromium\\Application\\chromium.exe'
,'%USERPROFILE%\\Local Settings\\Application Data\\Google\\Chrome\\chromium.exe'
,'%USERPROFILE%\\Local\ Settings\\Application\ Data\\Google\\Chrome\\chromium.exe'
,'%HOMEPATH%\\Chromium\\Application\\chromium.exe'
,'%PROGRAMFILES%\\Chromium\\Application\\chromium.exe'
,'%PROGRAMFILES(X86)%\\Chromium\\Application\\chromium.exe'
,'%HOMEPATH%\\Local Settings\\Application\ Data\\Google\\Chrome\\Application\\chromium.exe'
,'%HOMEPATH%\\Local Settings\\Application Data\\Google\\Chrome\\Application\\chromium.exe'
,'chromium.exe'

, reg_value+'\\Chromium\\Application\\chrome.exe'
,'%USERPROFILE%\\Local Settings\\Application Data\\Google\\Chrome\\chrome.exe'
,'%USERPROFILE%\\Local\ Settings\\Application\ Data\\Google\\Chrome\\chrome.exe'
,'%HOMEPATH%\\Chromium\\Application\\chrome.exe'
,'%PROGRAMFILES%\\Chromium\\Application\\chrome.exe'
,'%PROGRAMFILES(X86)%\\Chromium\\Application\\chrome.exe'
,'%HOMEPATH%\\Local\ Settings\\Application\ Data\\Google\\Chrome\\Application\\chrome.exe'
,'%HOMEPATH%\\Local Settings\\Application Data\\Google\\Chrome\\Application\\chrome.exe'
,'chrome.exe'

])
commands = ['-new-tab', url]
else:
items.extend([
'/usr/bin/chromium'
,'chromium'
,'/usr/bin/chromium-browser'
,'chromium-browser'
])
commands = ['-new-tab', url]
elif browser == 'firefox':
if sublime.platform() == 'osx':
items.extend(['open'])
commands = ['-a', '/Applications/Firefox.app', url]
else:
items.extend([
'/usr/bin/firefox'

,'%PROGRAMFILES%\\Nightly\\firefox.exe'
,'%PROGRAMFILES(X86)%\\Nightly\\firefox.exe'

,'%PROGRAMFILES%\\Mozilla Firefox\\firefox.exe'
,'%PROGRAMFILES(X86)%\\Mozilla Firefox\\firefox.exe'

,'firefox'
,'firefox.exe'
])
commands = ['-new-tab', url]
elif browser == 'aurora':
if sublime.platform() == 'osx':
items.extend(['open'])
commands = ['-a', '/Applications/FirefoxAurora.app', url]
else:
items.extend([
'/usr/bin/aurora'

,'%PROGRAMFILES%\\Aurora\\firefox.exe'
,'%PROGRAMFILES(X86)%\\Aurora\\firefox.exe'

,'firefox'
,'firefox.exe'
])
commands = ['-new-tab', url]
elif browser == 'opera':
if sublime.platform() == 'osx':
items.extend(['open'])
commands = ['-a', '/Applications/Opera.app', url]
else:
items.extend([
'/usr/bin/opera'
,'/usr/bin/opera-next'
,'/usr/bin/operamobile'

,'%PROGRAMFILES%\\Opera\\opera.exe'
,'%PROGRAMFILES(X86)%\\Opera\\opera.exe'

,'%PROGRAMFILES%\\Opera Next\\opera.exe'
,'%PROGRAMFILES(X86)%\\Opera Next\\opera.exe'

,'%PROGRAMFILES%\\Opera Mobile Emulator\\OperaMobileEmu.exe'
,'%PROGRAMFILES(X86)%\\Opera Mobile Emulator\\OperaMobileEmu.exe'

,'opera'
,'opera.exe'
])
commands = ['-newtab', url]
elif browser == 'safari':
if sublime.platform() == 'osx':
items.extend(['open'])
commands = ['-a', 'Safari', url]
else:
items.extend([
'/usr/bin/safari'

,'%PROGRAMFILES%\\Safari\\Safari.exe'
,'%PROGRAMFILES(X86)%\\Safari\\Safari.exe'

,'Safari'
,'Safari.exe'
])
commands = ['-new-tab', '-url', url]
else:
commands = ['-new-tab', url]

for item in items:
try:
command2 = list(commands)
command2.insert(0, expandVars(item))
subprocess.Popen(command2)
return
except:
try:
command2 = list(commands)
command2.insert(0, item)
subprocess.Popen(command2)
return
except:
pass
try:
if sublime.platform() == 'windows':
commands = ['cmd','/c','start', '', url]
subprocess.Popen(commands)
elif sublime.platform() == 'linux':
commands = ['xdg-open', url]
subprocess.Popen(commands)
else:
commands = ['open', url]
subprocess.Popen(commands)
return
except:
pass

sublime.error_message('Can not open PayPal url. Default browser not found..')










if st_version == 2:
Expand Down
6 changes: 6 additions & 0 deletions Main.sublime-menu
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@
"args": {"file": "${packages}/User/AutoBackups (OSX).sublime-settings", "platform": "OSX"},
"caption": "Settings – User"
},
{ "caption": "-", "id": "autobackups-donate-separator" },
{
"command": "auto_backups_donate",
"args": {},
"caption": "Donate"
},
{ "caption": "-" }
]
}
Expand Down
3 changes: 2 additions & 1 deletion messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
"2.2.1": "messages/2.2.1.txt",
"2.3.0": "messages/2.3.0.txt",
"2.3.1": "messages/2.3.1.txt",
"2.3.2": "messages/2.3.2.txt"
"2.3.2": "messages/2.3.2.txt",
"2.3.3": "messages/2.3.3.txt"
}
11 changes: 11 additions & 0 deletions messages/2.3.3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Sublime AutoBackups 2.3.3 Changelog:


Bug-fixes
------------
- Fixed bugs

Features
------------
- Added ignore_regexes setting
- Added Donate menu item in Preferences - Package Settings - AutoBackups

0 comments on commit a2453dd

Please sign in to comment.