From 56c177852cefb5a4af9e26a2c0fb41b26e58320f Mon Sep 17 00:00:00 2001 From: Hidden Z Date: Sun, 7 Nov 2010 14:06:12 +0000 Subject: [PATCH] py-i2phosts-injector: rewrite choosing of hosts.txt file for parsing Now we doesn't fail when no HOME env var is present. --- py-i2phosts-injector | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/py-i2phosts-injector b/py-i2phosts-injector index 6cb6c83..a645126 100755 --- a/py-i2phosts-injector +++ b/py-i2phosts-injector @@ -13,7 +13,7 @@ parser = argparse.ArgumentParser( epilog='Report bugs to http://zzz.i2p/topics/733') parser.add_argument('-c', '--config', default='/etc/py-i2phosts/injector.conf', dest='config_file', help='config file to use') -parser.add_argument('-f', '--file', default=os.environ['HOME'] + '/.i2p/hosts.txt', dest='hostsfile', +parser.add_argument('-f', '--file', dest='hostsfile', help='hosts.txt for parsing') parser.add_argument('-d', '--description', default='Auto-added from external hosts.txt', help='provide custom description message') @@ -53,6 +53,17 @@ else: if args.quiet: args.supress = True +# determine what hosts.txt file we should parse +if args.hostsfile: + hostsfile = args.hostsfile +else: + env = os.environ + if 'HOME' in env: + hostsfile = os.environ['HOME'] + '/.i2p/hosts.txt' + else: + sys.stderr.write('unable to determine hosts file for parsing\n') + sys.exit(1) + f = open(args.hostsfile, 'r') for line in f: # ignore comments and empty lines