From fd210c6fe33973c66c02f1b3819a6f1783732ffa Mon Sep 17 00:00:00 2001 From: Hidden Z Date: Wed, 13 Oct 2010 17:32:34 +0000 Subject: [PATCH] injector: add command-line arguments parsing And first option is: path to hosts.txt for parse --- injector | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/injector b/injector index f1af0d0..aeefb9b 100755 --- a/injector +++ b/injector @@ -2,6 +2,7 @@ import os import sys +import argparse # django setup DJANGO_SETTINGS_MODULE = 'settings' @@ -10,10 +11,15 @@ sys.path.insert(1, DJANGO_PROJECT_PATH) os.environ['DJANGO_SETTINGS_MODULE'] = DJANGO_SETTINGS_MODULE from web.postkey.models import i2phost -# hosts.txt we want to parse -hostsfile = os.environ['HOME'] + '/.i2p/hosts.txt' +# parse command line options +parser = argparse.ArgumentParser( + description='Hosts injector for py-i2phosts.', + epilog='Report bugs to http://zzz.i2p/topics/733') +parser.add_argument('-f', '--file', default=os.environ['HOME'] + '/.i2p/hosts.txt', dest='hostsfile', + help='hosts.txt for parsing') +args = parser.parse_args() -f = open(hostsfile, 'r') +f = open(args.hostsfile, 'r') for line in f: entry = line.split('=') # Check for already existed hosts in database to avoid adding duplicates.