Esempio n. 1
0
File: main.py Progetto: chergert/ddg
def result_cb(walker, path, dirs, files):
    for file in files:
        if file.endswith('.devhelp'):
            task = gtask.Task(get_info, os.path.join(path, file))
            task.add_callback(add_to_store, store)
            gtask.schedule(task)
Esempio n. 2
0
def parse(data):
    p = rss.Parser()
    p.load_from_data(data, len(data))
    l = p.get_document().get_items()
    l.reverse() # order newest article first
    return l

def printit(i):
    print 'Title:   %s' % i.props.title
    print 'Author:  %s' % i.props.author
    print 'Date:    %s' % i.props.pub_date
    print ''

# download the url as an async task
task = gtask.Task(lambda: urllib.urlopen(url).read())

# process the content into a list of rss articles.
# the result of the task will be the first argument to parse().
task.add_callback(parse)

# print each article to the command line
task.add_callback(lambda l: [printit(i) for i in l])

# quit the main loop when we are done
task.add_callback(lambda _: loop.quit())

# schedule the task for execution
gtask.schedule(task)

loop.run()
Esempio n. 3
0
#!/usr/bin/env python

import gtask
import glib

loop = glib.MainLoop()

def puts(*a): print ' '.join(a)

t = gtask.Task(lambda: puts("starting") or someBadFunc())
t.add_callback(lambda _: puts('some bad mamo jamo'))
t.add_errback(lambda _: puts('i should be called'))
t.add_callback(lambda _: puts('quitting') or loop.quit())
t.add_errback(lambda _: puts('oops, error not unset?'))

gtask.schedule(t)

loop.run()