Skip to content

Commit

Permalink
Add .alfredversionchecked file and touch info.plist
Browse files Browse the repository at this point in the history
Lets Alfred know the workflow has been updated and doesn't suffer from
the Sierra bug.
  • Loading branch information
deanishe committed Jun 23, 2017
1 parent 20e0728 commit 260ee88
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 57 deletions.
Binary file not shown.
51 changes: 37 additions & 14 deletions src/fixum.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
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')

Expand All @@ -82,10 +85,16 @@
MATCH_INITIALS_STARTSWITH |
MATCH_SUBSTRING)

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


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


def read_plist(path):
"""Convert plist to XML and read its contents."""
cmd = [b'plutil', b'-convert', b'xml1', b'-o', b'-', path]
Expand Down Expand Up @@ -139,7 +148,7 @@ def get_workflow_info(dirpath):
if not aw:
return None

return Workflow(name, bid, dirpath, aw.version, aw.path)
return Workflow(name, bid, dirpath, aw)


def get_workflow_directory():
Expand Down Expand Up @@ -189,12 +198,21 @@ def _newname(path):
def update_workflow(info):
"""Replace outdated version of Alfred-Workflow."""
log.info(' updating "%s" ...', info.name)
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')
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)

# Add marker file to indicate workflow doesn't have the Sierra bug
okfile = os.path.join(info.aw.path, OK_FILENAME)
open(okfile, 'wb')

# 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)


def list_actions(opts):
Expand Down Expand Up @@ -286,17 +304,22 @@ def main(wf):

if not os.path.isdir(p):
log.debug('ignoring non-directory: %s', dn)
continue

try:
info = get_workflow_info(p)
except Exception as err:
log.error('could not read workflow: %s: %s', dn, err)
continue

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

if info.id == wf.bundleid:
log.debug('ignoring self')
continue

ok = True
for pat in blacklisted:
if fnmatch(info.id, pat):
Expand All @@ -312,24 +335,24 @@ def main(wf):
log.info('found AW workflow: %s', dn)
log.info(' name: %s', info.name)
log.info(' bundle ID: %s', info.id)
log.info(' AW version: %s', info.aw_version)
log.info(' AW version: %s', info.aw.version)

if info.aw_version >= MIN_VERSION:
log.info('[OK] workflow "%s" has a working version of '
if info.aw.version >= MIN_VERSION:
log.info('[OK] workflow "%s" has current version of '
'Alfred-Workflow', info.name)
log.info('')
continue

log.info('[!!] workflow "%s" is using outdated version '
'(%s) of Alfred-Workflow', info.name, info.aw_version)
'(%s) of Alfred-Workflow', info.name, info.aw.version)

if not dry_run:
try:
update_workflow(info)
except Exception as err:
failed += 1
log.error('failed to update workflow "%s" (%s): %s',
info.name, info.aw_dir, err, exc_info=True)
info.name, info.aw.path, err, exc_info=True)
log.info('')
continue

Expand Down
88 changes: 45 additions & 43 deletions src/info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,55 @@
<string>Fixum</string>
<key>objects</key>
<array>
<dict>
<key>config</key>
<dict>
<key>concurrently</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>
</dict>
<key>type</key>
<string>alfred.workflow.action.script</string>
<key>uid</key>
<string>97033D94-9B6F-446C-94E5-AB677B5ABB4F</string>
<key>version</key>
<integer>2</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 @@ -88,48 +132,6 @@
<key>version</key>
<integer>2</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>concurrently</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>
</dict>
<key>type</key>
<string>alfred.workflow.action.script</string>
<key>uid</key>
<string>97033D94-9B6F-446C-94E5-AB677B5ABB4F</string>
<key>version</key>
<integer>2</integer>
</dict>
<dict>
<key>config</key>
<dict>
Expand Down Expand Up @@ -181,7 +183,7 @@ It is primarily a workaround to fix bugs that are preventing the workflows from
</dict>
</dict>
<key>version</key>
<string>0.2</string>
<string>0.3</string>
<key>webaddress</key>
<string></string>
</dict>
Expand Down

0 comments on commit 260ee88

Please sign in to comment.