From cfb76e7c8461a6c155a6c0420af4fcc21c5c1ccb Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Sun, 27 May 2012 10:24:24 +0200 Subject: [PATCH] Move argument parsing to top of code --- parse | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/parse b/parse index 4c2b582..56f20b2 100755 --- a/parse +++ b/parse @@ -2,6 +2,23 @@ import os, argparse, hashlib, email, email.header, glob, sqlite3 +parser = argparse.ArgumentParser(description='Parses emails into an SQLite database, and optionally renders static HTML files.') + +parser.add_argument('-p', dest='pattern', action='store', default='*', + help='glob pattern (including path) that has to be matched for a file to be parsed') + +parser.add_argument('-d', dest='database', action='store', default='emails.db', + help='path of the database that should be used to store the emails (will be created if it does not exist yet)') + +parser.add_argument('-a', dest='attachment_dir', action='store', default='attachments', + help='path where attachments should be stored (will be created if it does not exist yet)') + +parser.add_argument('-r', '--render', dest='render', action='store_true', + help='render static HTML files using the template files in templates/') + +args = parser.parse_args() +options = vars(args) + def getheader(header_text, default="ascii"): headers = email.header.decode_header(header_text) header_sections = [unicode(text, charset or default) for text, charset in headers] @@ -31,23 +48,6 @@ def get_charset(part): else: return "ascii" -parser = argparse.ArgumentParser(description='Parses emails into an SQLite database, and optionally renders static HTML files.') - -parser.add_argument('-p', dest='pattern', action='store', default='*', - help='glob pattern (including path) that has to be matched for a file to be parsed') - -parser.add_argument('-d', dest='database', action='store', default='emails.db', - help='path of the database that should be used to store the emails (will be created if it does not exist yet)') - -parser.add_argument('-a', dest='attachment_dir', action='store', default='attachments', - help='path where attachments should be stored (will be created if it does not exist yet)') - -parser.add_argument('-r', '--render', dest='render', action='store_true', - help='render static HTML files using the template files in templates/') - -args = parser.parse_args() -options = vars(args) - database = sqlite3.connect(options['database']) cursor = database.cursor()