Skip to content

Commit

Permalink
Mark workflows as updated and valid
Browse files Browse the repository at this point in the history
  • Loading branch information
deanishe committed Jun 23, 2017
2 parents 260ee88 + 8d09df1 commit 627ad95
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 75 deletions.
Binary file modified Fixum-0.3.alfredworkflow
Binary file not shown.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ If everything looks good, run **Fix Workflows**.

### Alfred commands ###

- `fixnum` — Show available actions
- `fixum` — Show available actions
- **A newer version of Fixum is available** — Shown if an update
for Fixum is available.
- **Dry Run** — Analyse installed workflows, but don't change anything
Expand Down
48 changes: 21 additions & 27 deletions src/fixum.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,17 @@

log = None

# bundle IDs of workflows to skip
BLACKLIST = [
'net.deanishe.alfred.fixum', # this workflow
]

ICON_UPDATE = 'update-available.png'

# version of AW in this workflow
VERSION_FILE = os.path.join(os.path.dirname(__file__), 'workflow/version')
MIN_VERSION = Version(open(VERSION_FILE).read())

# File that tells Alfred that this workflow is ok
OK_FILENAME = '.alfredversionchecked'

# path to good copy of Alfred-Workflow
WF_DIR = os.path.join(os.path.dirname(__file__), 'workflow')

# Alfred 3 preferences property list
# Alfred 3 preferences property list. Contains path to workflow
# directory
ALFRED_PREFS = os.path.expanduser(
'~/Library/Preferences/com.runningwithcrayons.Alfred-Preferences-3.plist')

Expand All @@ -86,11 +79,11 @@
MATCH_SUBSTRING)

Workflow = namedtuple('Workflow', 'name id dir aw')
AWInfo = namedtuple('AWInfo', 'path version')
AWInfo = namedtuple('AWInfo', 'dir version')


def touch(path):
"""Update the modtime of ``path`` to now."""
"""Set mtime and atime of ``path`` to now."""
with open(path, 'a'):
os.utime(path, None)

Expand Down Expand Up @@ -170,7 +163,7 @@ def get_workflow_directory():

def load_blacklist():
"""Load bundle IDs of blacklisted workflows."""
blacklisted = BLACKLIST[:]
blacklisted = []
p = wf.datafile('blacklist.txt')
if os.path.exists(p):
with open(p) as fp:
Expand Down Expand Up @@ -198,21 +191,18 @@ def _newname(path):
def update_workflow(info):
"""Replace outdated version of Alfred-Workflow."""
log.info(' updating "%s" ...', info.name)
newdir = _newname(info.aw.path + '.old')
log.debug(' moving %s to %s ...', info.aw.path, newdir)
os.rename(info.aw.path, newdir)
log.debug(' copying new version of AW to %s ...', info.aw.path)
shutil.copytree(WF_DIR, info.aw.path)
log.info(' installed new version (%s) of Alfred-Workflow', MIN_VERSION)
newdir = _newname(info.aw.dir + '.old')
log.debug(' moving %s to %s ...', info.aw.dir, newdir)
os.rename(info.aw.dir, newdir)
log.debug(' copying new version of AW to %s ...', info.aw.dir)
shutil.copytree(WF_DIR, info.aw.dir)
log.info(' installed new version of Alfred-Workflow')

# Add marker file to indicate workflow doesn't have the Sierra bug
okfile = os.path.join(info.aw.path, OK_FILENAME)
open(okfile, 'wb')
# Create file to let Alfred know this workflow is okay
open(os.path.join(info.aw.dir, '.alfredversionchecked'), 'w')

# Touch info.plist to let Alfred know the workflow has been updated
iplist = os.path.join(info.dir, 'info.plist')
touch(iplist)
log.debug(' touched %s', iplist)
# Touch info.plist to let Alfred know this workflow has been updated
touch(os.path.join(info.dir, 'info.plist'))


def list_actions(opts):
Expand All @@ -231,19 +221,23 @@ def list_actions(opts):
dict(title='Dry Run',
subtitle='Show what the workflow would update',
arg='dryrun',
uid='dryrun',
valid=True),
dict(title='View Log File',
subtitle='Open the log file in Console.app',
arg='log',
uid='log',
valid=True),
dict(title='Edit Blacklist',
subtitle='List of workflows to *not* update',
arg='blacklist',
uid='blacklist',
valid=True),
dict(title='Fix Workflows',
subtitle=('Replace broken versions of Alfred-Workflow '
'within your workflows'),
arg='fix',
uid='fix',
valid=True),
]

Expand Down Expand Up @@ -312,7 +306,7 @@ def main(wf):
log.error('could not read workflow: %s: %s', dn, err)
continue

if not info or not info.aw.path:
if not info or not info.aw.dir:
log.debug('not an AW workflow: %s', dn)
continue

Expand Down Expand Up @@ -352,7 +346,7 @@ def main(wf):
except Exception as err:
failed += 1
log.error('failed to update workflow "%s" (%s): %s',
info.name, info.aw.path, err, exc_info=True)
info.name, info.aw.dir, err, exc_info=True)
log.info('')
continue

Expand Down
92 changes: 45 additions & 47 deletions src/info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -48,52 +48,29 @@
<dict>
<key>config</key>
<dict>
<key>concurrently</key>
<key>lastpathcomponent</key>
<false/>
<key>escaping</key>
<integer>102</integer>
<key>script</key>
<string>mode=$1
datadir="$alfred_workflow_data"
cachedir="$alfred_workflow_cache"
blacklist="${datadir}/blacklist.txt"
logfile="${cachedir}/net.deanishe.alfred.fixum.log"
# create data &amp; cache directories, logfile and blacklist
test -d "$cachedir" || mkdir -p "$cachedir"
test -f "$logfile" || touch "$logfile"
test -d "$datadir" || mkdir -p "$datadir"
test -f "$blacklist" || cp blacklist.default.txt "$blacklist"
# script actions
[[ "$mode" = dryrun ]] &amp;&amp; /usr/bin/python fixum.py --nothing
[[ "$mode" = fix ]] &amp;&amp; /usr/bin/python fixum.py
[[ "$mode" = blacklist ]] &amp;&amp; open "$blacklist"
[[ "$mode" = log ]] &amp;&amp; open -a Console "$logfile"
exit 0</string>
<key>scriptargtype</key>
<integer>1</integer>
<key>scriptfile</key>
<string></string>
<key>type</key>
<integer>5</integer>
<key>onlyshowifquerypopulated</key>
<true/>
<key>removeextension</key>
<false/>
<key>text</key>
<string>{query}</string>
<key>title</key>
<string>Fixum</string>
</dict>
<key>type</key>
<string>alfred.workflow.action.script</string>
<string>alfred.workflow.output.notification</string>
<key>uid</key>
<string>97033D94-9B6F-446C-94E5-AB677B5ABB4F</string>
<string>90302262-60E4-4C1C-AAEA-2A5C3F4C025A</string>
<key>version</key>
<integer>2</integer>
<integer>1</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>alfredfiltersresults</key>
<false/>
<key>argumenttrimmode</key>
<integer>0</integer>
<key>argumenttype</key>
<integer>1</integer>
<key>escaping</key>
Expand Down Expand Up @@ -135,23 +112,44 @@ exit 0</string>
<dict>
<key>config</key>
<dict>
<key>lastpathcomponent</key>
<false/>
<key>onlyshowifquerypopulated</key>
<true/>
<key>removeextension</key>
<key>concurrently</key>
<false/>
<key>text</key>
<string>{query}</string>
<key>title</key>
<string>Fixum</string>
<key>escaping</key>
<integer>102</integer>
<key>script</key>
<string>mode=$1
datadir="$alfred_workflow_data"
cachedir="$alfred_workflow_cache"
blacklist="${datadir}/blacklist.txt"
logfile="${cachedir}/net.deanishe.alfred.fixum.log"
# create data &amp; cache directories, logfile and blacklist
test -d "$cachedir" || mkdir -p "$cachedir"
test -f "$logfile" || touch "$logfile"
test -d "$datadir" || mkdir -p "$datadir"
test -f "$blacklist" || cp blacklist.default.txt "$blacklist"
# script actions
[[ "$mode" = dryrun ]] &amp;&amp; /usr/bin/python fixum.py --nothing
[[ "$mode" = fix ]] &amp;&amp; /usr/bin/python fixum.py
[[ "$mode" = blacklist ]] &amp;&amp; open "$blacklist"
[[ "$mode" = log ]] &amp;&amp; open -a Console "$logfile"
exit 0</string>
<key>scriptargtype</key>
<integer>1</integer>
<key>scriptfile</key>
<string></string>
<key>type</key>
<integer>5</integer>
</dict>
<key>type</key>
<string>alfred.workflow.output.notification</string>
<string>alfred.workflow.action.script</string>
<key>uid</key>
<string>90302262-60E4-4C1C-AAEA-2A5C3F4C025A</string>
<string>97033D94-9B6F-446C-94E5-AB677B5ABB4F</string>
<key>version</key>
<integer>1</integer>
<integer>2</integer>
</dict>
</array>
<key>readme</key>
Expand Down

0 comments on commit 627ad95

Please sign in to comment.