Skip to content

Commit

Permalink
adding release script
Browse files Browse the repository at this point in the history
  • Loading branch information
dfm committed Jun 22, 2019
1 parent a03b93e commit 7648c60
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
__pycache__
*.pyc
.pytest_cache
adsabs.alfredworkflow
42 changes: 21 additions & 21 deletions info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -113,25 +113,6 @@
<key>version</key>
<integer>1</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>browser</key>
<string></string>
<key>spaces</key>
<string></string>
<key>url</key>
<string>{query}</string>
<key>utf8</key>
<true/>
</dict>
<key>type</key>
<string>alfred.workflow.action.openurl</string>
<key>uid</key>
<string>407E7C1B-5537-436F-8D97-71204E3433D3</string>
<key>version</key>
<integer>1</integer>
</dict>
<dict>
<key>config</key>
<dict>
Expand Down Expand Up @@ -181,6 +162,25 @@
<key>version</key>
<integer>3</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>browser</key>
<string></string>
<key>spaces</key>
<string></string>
<key>url</key>
<string>{query}</string>
<key>utf8</key>
<true/>
</dict>
<key>type</key>
<string>alfred.workflow.action.openurl</string>
<key>uid</key>
<string>407E7C1B-5537-436F-8D97-71204E3433D3</string>
<key>version</key>
<integer>1</integer>
</dict>
</array>
<key>readme</key>
<string>Search for papers using SAO/NASA Astrophysics Data System</string>
Expand All @@ -203,7 +203,7 @@
<key>88F638D8-273F-4E10-979E-6CFBCBC1AD83</key>
<dict>
<key>xpos</key>
<integer>50</integer>
<integer>40</integer>
<key>ypos</key>
<integer>60</integer>
</dict>
Expand All @@ -228,7 +228,7 @@
<string>ADS_DEV_KEY</string>
</array>
<key>version</key>
<string>0.1.1</string>
<string>0.1.2</string>
<key>webaddress</key>
<string>https://github.com/dfm/adsabs.alfredworkflow</string>
</dict>
Expand Down
54 changes: 54 additions & 0 deletions release.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import zipfile
import plistlib

VERSION = "0.1.2"
OUTFILE = "adsabs.alfredworkflow"

# Remove the previous build
if os.path.exists(OUTFILE):
os.remove(OUTFILE)

# Load the plist
with open("info.plist", "rb") as f:
plist = plistlib.load(f)

# Remove Alfred 3 incompatible arguments
objects = plist.get("objects", [])
for obj in objects:
if "config" not in obj:
continue
config = obj["config"]
config.pop("argumenttreatemptyqueryasnil", None)
obj["config"] = config

if "version" in obj and obj.get("version") > 2:
obj["version"] = 2

# Clear variables
plist["variables"]["ADS_PYTHON"] = "python"
plist["variables"]["ADS_DEV_KEY"] = ""

# Update the version number
plist["version"] = VERSION

# Create the zip file
with zipfile.ZipFile(OUTFILE, "w") as zf:

# Save the plist
print("writing info.plist")
zf.writestr("info.plist", plistlib.dumps(plist))

# Copy the other files
for fn in os.listdir("."):
if fn in ["info.plist", "__pycache__", "build", "release.py", OUTFILE]:
continue
if fn.startswith("."):
continue
if fn.endswith(".pyc"):
continue
print("writing {0}".format(fn))
zf.write(fn)
6 changes: 5 additions & 1 deletion run_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def set_ratelimit(ratelimit):
return_error("Install the 'ads' Python library to enable search",
"https://github.com/andycasey/ads",
sub=("Or set you prefered python interpreter in the "
"~/.ads/python file"))
"ADS_PYTHON variable for this workflow"))

# Make sure that the ~/.ads directory exists
if not os.path.exists(os.path.expanduser("~/.ads")):
Expand All @@ -62,6 +62,10 @@ def set_ratelimit(ratelimit):

# Parse the query
query = " ".join(sys.argv[1:]).strip()
if len(query) < 3:
sys.stdout.write(json.dumps(dict(items=[])))
sys.exit(0)

try:
query_string = parse_query_string(query)
except Exception:
Expand Down

0 comments on commit 7648c60

Please sign in to comment.