implementing reset- and delete-functionality

This commit is contained in:
Ronald Schaten 2013-04-04 23:46:00 +02:00
parent 103d7d4a28
commit c84c465a14

View File

@ -234,13 +234,54 @@ def fetch_all_feeds(session):
fetch_single_feed(session, feed) fetch_single_feed(session, feed)
print print
def ask_ok(prompt, retries=4, complaint='Yes or no, please!'):
while True:
ok = raw_input(prompt)
if ok in ('y', 'ye', 'yes'):
return True
if ok in ('n', 'no', 'nop', 'nope'):
return False
retries = retries - 1
if retries < 0:
return False
print complaint
def delete_feed(session, feed_id): def delete_feed(session, feed_id):
print 'deleting feed %d...' % feed_id feed = session.query(Feed).\
# TODO implement delete filter(Feed.id == feed_id).\
first()
print feed
if ask_ok('> Do you really want to delete feed %d? ' % feed_id):
print 'deleting...'
entries = session.query(Entry).\
filter(Entry.feed_id == feed_id).\
all()
for entry in entries:
session.delete(entry)
feedinfo = session.query(Feedinfo).\
filter(Feedinfo.feed_id == feed_id).\
first()
session.delete(feedinfo)
session.delete(feed)
print '... done.'
def reset_feed(session, feed_id): def reset_feed(session, feed_id):
print 'resetting feed %d...' % feed_id feed = session.query(Feed).\
# TODO implement reset filter(Feed.id == feed_id).\
first()
print feed
if ask_ok('> Do you really want to reset feed %d? ' % feed_id):
print 'resetting...'
entries = session.query(Entry).\
filter(Entry.feed_id == feed_id).\
all()
for entry in entries:
session.delete(entry)
feedinfo = session.query(Feedinfo).\
filter(Feedinfo.feed_id == feed_id).\
first()
session.delete(feedinfo)
print '... done.'
if __name__ == '__main__': if __name__ == '__main__':
if (sys.stdout.encoding is None): if (sys.stdout.encoding is None):