Skip to content

Commit

Permalink
Update Alfred-Workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
deanishe committed May 28, 2020
1 parent ed152bf commit 5354681
Show file tree
Hide file tree
Showing 10 changed files with 231 additions and 103 deletions.
Binary file not shown.
96 changes: 49 additions & 47 deletions src/info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,44 @@
<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>
<dict>
<key>config</key>
Expand All @@ -73,6 +94,8 @@
<false/>
<key>alfredfiltersresultsmatchmode</key>
<integer>0</integer>
<key>argumenttreatemptyqueryasnil</key>
<false/>
<key>argumenttrimmode</key>
<integer>0</integer>
<key>argumenttype</key>
Expand Down Expand Up @@ -111,49 +134,28 @@
<key>uid</key>
<string>4FFEB019-EBD2-452B-AC8B-54E7C33ABE9F</string>
<key>version</key>
<integer>2</integer>
<integer>3</integer>
</dict>
<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>
</array>
<key>readme</key>
Expand Down Expand Up @@ -185,7 +187,7 @@ It is primarily a workaround to fix bugs that are preventing the workflows from
</dict>
</dict>
<key>version</key>
<string>0.9</string>
<string>0.10</string>
<key>webaddress</key>
<string></string>
</dict>
Expand Down
5 changes: 1 addition & 4 deletions src/workflow/background.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,7 @@ def _job_pid(name):
if _process_exists(pid):
return pid

try:
os.unlink(pidfile)
except Exception: # pragma: no cover
pass
os.unlink(pidfile)


def is_running(name):
Expand Down
18 changes: 10 additions & 8 deletions src/workflow/notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ def install_notifier():
# z.extractall(destdir)
tgz = tarfile.open(archive, 'r:gz')
tgz.extractall(destdir)
assert os.path.exists(n), \
'Notify.app could not be installed in %s' % destdir
if not os.path.exists(n): # pragma: nocover
raise RuntimeError('Notify.app could not be installed in ' + destdir)

# Replace applet icon
icon = notifier_icon_path()
Expand Down Expand Up @@ -253,8 +253,9 @@ def png_to_icns(png_path, icns_path):
try:
iconset = os.path.join(tempdir, 'Icon.iconset')

assert not os.path.exists(iconset), \
'iconset already exists: ' + iconset
if os.path.exists(iconset): # pragma: nocover
raise RuntimeError('iconset already exists: ' + iconset)

os.makedirs(iconset)

# Copy source icon to icon set and generate all the other
Expand Down Expand Up @@ -283,8 +284,9 @@ def png_to_icns(png_path, icns_path):
if retcode != 0:
raise RuntimeError('iconset exited with %d' % retcode)

assert os.path.exists(icns_path), \
'generated ICNS file not found: ' + repr(icns_path)
if not os.path.exists(icns_path): # pragma: nocover
raise ValueError(
'generated ICNS file not found: ' + repr(icns_path))
finally:
try:
shutil.rmtree(tempdir)
Expand Down Expand Up @@ -332,8 +334,8 @@ def ustr(s):
print('converting {0!r} to {1!r} ...'.format(o.png, icns),
file=sys.stderr)

assert not os.path.exists(icns), \
'destination file already exists: ' + icns
if os.path.exists(icns):
raise ValueError('destination file already exists: ' + icns)

png_to_icns(o.png, icns)
sys.exit(0)
Expand Down
12 changes: 5 additions & 7 deletions src/workflow/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ class Version(object):
"""

#: Match version and pre-release/build information in version strings
match_version = re.compile(r'([0-9\.]+)(.+)?').match
match_version = re.compile(r'([0-9][0-9\.]*)(.+)?').match

def __init__(self, vstr):
"""Create new `Version` object.
Expand All @@ -247,7 +247,7 @@ def _parse(self, vstr):
else:
m = self.match_version(vstr)
if not m:
raise ValueError('invalid version number: {!r}'.format(vstr))
raise ValueError('invalid version number: ' + vstr)

version, suffix = m.groups()
parts = self._parse_dotted_string(version)
Expand All @@ -257,7 +257,7 @@ def _parse(self, vstr):
if len(parts):
self.patch = parts.pop(0)
if not len(parts) == 0:
raise ValueError('version number too long: {!r}'.format(vstr))
raise ValueError('version number too long: ' + vstr)

if suffix:
# Build info
Expand All @@ -268,11 +268,9 @@ def _parse(self, vstr):
if suffix:
if not suffix.startswith('-'):
raise ValueError(
'suffix must start with - : {0}'.format(suffix))
'suffix must start with - : ' + suffix)
self.suffix = suffix[1:]

# wf().logger.debug('version str `{}` -> {}'.format(vstr, repr(self)))

def _parse_dotted_string(self, s):
"""Parse string ``s`` into list of ints and strings."""
parsed = []
Expand Down Expand Up @@ -521,7 +519,7 @@ def install_update():
path = retrieve_download(Download.from_dict(dl))

wf().logger.info('installing updated workflow ...')
subprocess.call(['open', path])
subprocess.call(['open', path]) # nosec

wf().cache_data(key, no_update)
return True
Expand Down
Loading

0 comments on commit 5354681

Please sign in to comment.