1
0
mirror of https://github.com/r4sas/py-i2phosts synced 2025-01-22 12:34:17 +00:00

py-i2phosts-injector: rewrite choosing of hosts.txt file for parsing

Now we doesn't fail when no HOME env var is present.
This commit is contained in:
Hidden Z 2010-11-07 14:06:12 +00:00
parent 17431a7973
commit 56c177852c

View File

@ -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