|
|
@ -16,17 +16,15 @@ hostsfile = os.environ['HOME'] + '/.i2p/hosts.txt' |
|
|
|
f = open(hostsfile, 'r') |
|
|
|
f = open(hostsfile, 'r') |
|
|
|
for line in f: |
|
|
|
for line in f: |
|
|
|
entry = line.split('=') |
|
|
|
entry = line.split('=') |
|
|
|
# check for already existed hosts in database to avoid adding duplicates |
|
|
|
# Check for already existed hosts in database to avoid adding duplicates. |
|
|
|
# 1. do lookup by hostname |
|
|
|
# Do lookup by hostname only. |
|
|
|
# 2. do lookup by base64 hash |
|
|
|
qs = i2phost.objects.filter(name=entry[0]) |
|
|
|
qs1 = i2phost.objects.filter(name=entry[0]) |
|
|
|
if qs.exists(): |
|
|
|
qs2 = i2phost.objects.filter(name=entry[1]) |
|
|
|
print 'Host %s already exists' % entry[0] |
|
|
|
if not qs1.exists() and not qs2.exists(): |
|
|
|
else: |
|
|
|
print 'Adding %s' % entry[0] |
|
|
|
print 'Adding %s' % entry[0] |
|
|
|
host = i2phost(name=entry[0], b64hash=entry[1], |
|
|
|
host = i2phost(name=entry[0], b64hash=entry[1], |
|
|
|
description='Auto-added from external hosts.txt', |
|
|
|
description='Auto-added from external hosts.txt', |
|
|
|
activated=True) |
|
|
|
activated=True) |
|
|
|
host.save() |
|
|
|
host.save() |
|
|
|
else: |
|
|
|
|
|
|
|
print 'Host %s already exists' % entry[0] |
|
|
|
|
|
|
|
f.close() |
|
|
|
f.close() |
|
|
|