1
0
mirror of https://github.com/r4sas/py-i2phosts synced 2025-01-09 06:18:05 +00:00
py-i2phosts/injector
Hidden Z e3ec6c34bc Redefine DJANGO_PROJECT_PATH in scripts
Assume that wep-part are located in <scriptdir>/web. Later we should use
a config variable for it. In production environment scripts will be
located in /usr/bin/
2010-10-14 17:44:50 +00:00

37 lines
1.1 KiB
Python
Executable File

#!/usr/bin/python
import os
import sys
import argparse
# django setup
DJANGO_SETTINGS_MODULE = 'settings'
DJANGO_PROJECT_PATH = os.path.dirname(sys.argv[0]) + '/web'
sys.path.insert(1, DJANGO_PROJECT_PATH)
os.environ['DJANGO_SETTINGS_MODULE'] = DJANGO_SETTINGS_MODULE
from web.postkey.models import i2phost
# 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(args.hostsfile, 'r')
for line in f:
entry = line.split('=')
# Check for already existed hosts in database to avoid adding duplicates.
# Do lookup by hostname only.
qs = i2phost.objects.filter(name=entry[0])
if qs.exists():
print 'Host %s already exists' % entry[0]
else:
print 'Adding %s' % entry[0]
host = i2phost(name=entry[0], b64hash=entry[1],
description='Auto-added from external hosts.txt',
activated=True)
host.save()
f.close()