Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save clonejo/1773c566a29d0f043d4d to your computer and use it in GitHub Desktop.
Save clonejo/1773c566a29d0f043d4d to your computer and use it in GitHub Desktop.
A solution to the lack of UI for Dash's user docsets in Zeal. Uses Python 3 and easygui (pip3 install easygui)
#!/bin/python3
import json
import os
import tarfile
import urllib.request
import configparser
import easygui
user_docsets_url = 'https://dashes-to-dashes.herokuapp.com/docsets/contrib'
app_title = 'Download Zeal user docsets'
user_docsets_json = 'http://sanfrancisco.kapeli.com/feeds/zzz/user_contributed/build/index.json'
feed_url_template = 'http://{mirror}.kapeli.com/feeds/zzz/user_contributed/build/{key_name}/{archive_name}'
def get_user_docsets(url):
response = urllib.request.urlopen(url)
data = response.read()
text = data.decode('utf-8')
docsets = json.loads(text)
return docsets
def get_user_docets_from_json():
mirror = 'newyork'
data = get_user_docsets(user_docsets_json)
docsets = [
{
'archive': feed_url_template.format(
mirror=mirror,
key_name=key,
archive_name=value.get('archive')
),
'name': value.get('name'),
} for key, value in data.get('docsets').items()
]
return docsets
def choose_docset(user_docsets):
msg = "Choose which user docset to download."
docsets = [d['name'] for d in user_docsets]
docsets.sort(key=str.lower)
choice = easygui.multchoicebox(
msg, app_title, docsets)
return choice
def get_zeal_docsets_dir():
config = configparser.ConfigParser()
config.read([os.path.expanduser('~/.config/Zeal/Zeal.conf')])
return config['docsets']['path']
def download_docset(urls, directory):
for url in urls:
with urllib.request.urlopen(url) as response:
with tarfile.open(fileobj=response, mode='r:gz') as tar:
tar.extractall(directory)
def search_url(choice, user_docsets):
return [d['archive'] for d in user_docsets if d['name'] in choice]
def confirm_docset_download(choice, docset_url, docsets_dir):
return easygui.ccbox('The {0} docset will be downloaded from {1} and extracted into {2}.\n\nPlease wait.'.format(choice, docset_url, docsets_dir), app_title)
def docset_successfully_downloaded(choice):
easygui.msgbox(
'{0} docset successfully downloaded.'.format(choice), app_title)
def download_more_docsets():
return easygui.ynbox('Do you want to download another docset?', app_title, ('Yes', 'No'))
def exit_message():
easygui.msgbox(
'Bye bye.\n\nPlease remember to restart Zeal to refresh the docsets.', app_title, 'Quit')
def show_exception(e):
easygui.exceptionbox('Error: {0}'.format(e), app_title)
if __name__ == '__main__':
try:
# user_docsets = get_user_docsets(user_docsets_url)
user_docsets = get_user_docets_from_json()
while True:
choice = choose_docset(user_docsets)
if not choice:
break
docset_url = search_url(choice, user_docsets)
docsets_dir = get_zeal_docsets_dir()
if confirm_docset_download(choice, docset_url, docsets_dir):
download_docset(docset_url, docsets_dir)
docset_successfully_downloaded(choice)
if not download_more_docsets():
break
exit_message()
except Exception as e:
show_exception(e)
@clonejo
Copy link
Author

clonejo commented Mar 21, 2016

Original code was pretty broken, this worked for me with Zeal 0.2.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment