def cache_updateable(): work_q = Queue.Queue() done_q = Queue.Queue() workflows = get_compatible() # create a fixed numbner of threads for i in range(10): t = threading.Thread(target=check_update, args=(work_q, done_q, len(workflows))) t.daemon = True t.start() alfred.notify("Monkey Patch", "Checking updates for %i workflows" % (len(workflows)), text='Please wait...', sound=False) for i, w in enumerate(workflows): # w.check_for_update() work_q.put(w) work_q.join() alfred.notify("Monkey Patch", "Checking updates done", sound=False) workflows = [ w.to_dict() for w in workflows if w.has_update or w.has_check_errors ] alfred.cache.set('workflow.update', workflows, expire=86400)
def download(w_dir, w_cached=None, direct=False, current=None, total=None): try: if w_cached is None: workflows = get_updateable() w_cached = [ w for w in workflows if w['has_update'] and not w['has_check_errors'] and w['dirname'] == w_dir ][0] w = w_cached download_file = os.path.join( os.path.expanduser("~/Downloads"), "{0} v{1}.alfredworkflow".format(w['name'], w['update']['version'])) if os.path.exists(download_file): os.remove(download_file) tmp = tempfile.mkdtemp() f = tempfile.NamedTemporaryFile(suffix=".alfredworkflow", dir=tmp, delete=False) f.write(urllib2.urlopen(w['update']['download']).read()) f.close() shutil.copy(f.name, download_file) info = "Downloaded" if current is not None and total is not None: info = "Downloaded %i of %i" % (current, total) alfred.notify("Monkey Patch", info, text=os.path.basename(download_file), sound=False) autolog(info + ' ' + os.path.basename(download_file)) # we can remove this entry from our cache if direct: updateables = get_updateable(force=False) if updateables is not None: for i, u in enumerate(updateables): if u['dirname'] == w['dirname']: del updateables[i] break alfred.cache.set('workflow.update', updateables, expire=86400) call(['open', download_file]) except Exception, e: w_name = w_dir if w is not None: w_name = w['name'] autolog('error while trying to download %s - %s' % (w_name, str(e))) alfred.notify("Monkey Patch", "Download error", text=w_name, sound=False)
def download(w_dir, w_cached=None, direct=False, current=None, total=None): try: if w_cached is None: workflows = get_updateable() w_cached = [w for w in workflows if w['has_update'] and not w['has_check_errors'] and w['dirname'] == w_dir][0] w = w_cached download_file = os.path.join(os.path.expanduser("~/Downloads"), "{0} v{1}.alfredworkflow".format(w['name'], w['update']['version'])) if os.path.exists(download_file): os.remove(download_file) tmp = tempfile.mkdtemp() f = tempfile.NamedTemporaryFile(suffix=".alfredworkflow", dir=tmp, delete=False) f.write(urllib2.urlopen(w['update']['download']).read()) f.close() shutil.copy(f.name, download_file) info = "Downloaded" if current is not None and total is not None: info = "Downloaded %i of %i" % (current, total) alfred.notify("Monkey Patch", info, text=os.path.basename(download_file), sound=False) autolog(info + ' ' + os.path.basename(download_file)) # we can remove this entry from our cache if direct: updateables = get_updateable(force=False) if updateables is not None: for i, u in enumerate(updateables): if u['dirname'] == w['dirname']: del updateables[i] break alfred.cache.set('workflow.update', updateables, expire=86400) call(['open', download_file]) except Exception, e: w_name = w_dir if w is not None: w_name = w['name'] autolog('error while trying to download %s - %s' % (w_name, str(e))) alfred.notify("Monkey Patch", "Download error", text=w_name, sound=False)
def cache_updateable(): work_q = Queue.Queue() done_q = Queue.Queue() workflows = get_compatible() # create a fixed numbner of threads for i in range(10): t = threading.Thread(target=check_update, args=(work_q, done_q, len(workflows))) t.daemon = True t.start() alfred.notify("Monkey Patch", "Checking updates for %i workflows" % (len(workflows)), text='Please wait...', sound=False) for i, w in enumerate(workflows): # w.check_for_update() work_q.put(w) work_q.join() alfred.notify("Monkey Patch", "Checking updates done", sound=False) workflows = [w.to_dict() for w in workflows if w.has_update or w.has_check_errors] alfred.cache.set('workflow.update', workflows, expire=86400)