Skip to content

Commit

Permalink
Add self-update and longer logging
Browse files Browse the repository at this point in the history
  • Loading branch information
deanishe committed May 10, 2016
1 parent 515223d commit e15683e
Show file tree
Hide file tree
Showing 14 changed files with 3,088 additions and 617 deletions.
125 changes: 125 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@

# Created by https://www.gitignore.io/api/python,sublimetext,vim

### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
*.dist-info/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# IPython Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# dotenv
.env

# virtualenv
venv/
ENV/

# Spyder project settings
.spyderproject

# Rope project settings
.ropeproject


### SublimeText ###
# cache files for sublime text
*.tmlanguage.cache
*.tmPreferences.cache
*.stTheme.cache

# workspace files are user-specific
*.sublime-workspace

# project files should be checked into the repository, unless a significant
# proportion of contributors will probably not be using SublimeText
# *.sublime-project

# sftp configuration file
sftp-config.json


### Vim ###
# swap
[._]*.s[a-w][a-z]
[._]s[a-w][a-z]
# session
Session.vim
# temporary
.netrwhist
*~
# auto-generated tag files
tags

Binary file not shown.
3 changes: 3 additions & 0 deletions TODO.taskpaper
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
Bugs:
- `mdfind` finds everything that matches ".sublime-project", not only *.sublime-project files.
Ensure all results end with '.sublime-project'.
Updating:
- Re-jigger caching/filtering behaviour?
Currently, `locate` results are purged before caching. This means that files on disks currently not connected will disappear for up to a week. Is it better to store all the results and filter them on retrieval (in `sublime.py`) or will `mdfind` likely pick them up?
Expand Down
14 changes: 12 additions & 2 deletions src/sublime.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
ICON_WARNING, ICON_INFO, ICON_SETTINGS, ICON_SYNC)
from workflow.background import run_in_background, is_running

VERSION = '2.0'
# Auto-update URL
UPDATE_SETTINGS = {
'github_slug': 'deanishe/alfred-sublime-text'
}

# Location of `locate` database
LOCATE_DB = '/var/db/locate.database'
Expand Down Expand Up @@ -148,6 +151,13 @@ def main(wf):
for key in DEFAULT_SETTINGS:
wf.settings[key] = DEFAULT_SETTINGS[key]

# Show if update is available
if wf.update_available:
wf.add_item('Newer version available',
'Action this item to install the update.',
autocomplete='workflow:update',
icon=ICON_SYNC)

# Load cached data if it exists. If it's out-of-date, we'll take
# care of that directly
projects = wf.cached_data('projects', None, max_age=0)
Expand Down Expand Up @@ -193,6 +203,6 @@ def main(wf):


if __name__ == '__main__':
wf = Workflow()
wf = Workflow(update_settings=UPDATE_SETTINGS)
log = wf.logger
sys.exit(wf.run(main))
16 changes: 9 additions & 7 deletions src/update_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import sys
import os
import subprocess
from time import time
from time import sleep, time
from fnmatch import fnmatch

from workflow import Workflow
Expand Down Expand Up @@ -86,33 +86,35 @@ def main(wf):
proc = procs.pop(0)
if proc.poll() is None:
procs.append(proc)
sleep(0.05)
continue
output = proc.communicate()[0]
paths.update([s.strip() for s in
paths.update([os.path.abspath(s.strip()) for s in
decode(output).split('\n') if s.strip()])

projects = []
exclude_patterns = wf.settings.get('excludes', [])
for path in paths:
j = len(paths)
for i, path in enumerate(sorted(paths)):
# Exclude paths that don't exist. This is important, as `locate`
# returns paths that may have long since been deleted or are on
# drives that are currently not connected
if not os.path.exists(path):
continue
valid = True

# Exclude results based on globbing patterns
for pat in exclude_patterns:
if fnmatch(path, pat):
log.debug('Excluded [{}] {}'.format(pat, path))
valid = False
break
if valid:
else: # Path is valid
log.debug('[%3d/%3d] %r', i+1, j, path)
projects.append(path)

# Save data to cache
wf.cache_data('projects', sorted(projects))

log.debug('{} projects found in {:0.2f} seconds'.format(
log.debug('{} projects found in {:0.2f} seconds.'.format(
len(paths), time() - start))

if __name__ == '__main__':
Expand Down
1 change: 1 addition & 0 deletions src/version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.1
Binary file added src/workflow/Notify.tgz
Binary file not shown.
Loading

0 comments on commit e15683e

Please sign in to comment.