Browse Source

injector: use more efficient exists() method

pull/1/head
Hidden Z 14 years ago
parent
commit
b71f2fc511
  1. 15
      injector

15
injector

@ -19,13 +19,14 @@ for line in f: @@ -19,13 +19,14 @@ for line in f:
# check for already existed hosts in database to avoid adding duplicates
# 1. do lookup by hostname
# 2. do lookup by base64 hash
if not i2phost.objects.filter(name=entry[0]) \
and not i2phost.objects.filter(b64hash=entry[1]):
print 'Adding %s' % entry[0]
host = i2phost(name=entry[0], b64hash=entry[1],
description='Auto-added from external hosts.txt',
activated=True)
host.save()
qs1 = i2phost.objects.filter(name=entry[0])
qs2 = i2phost.objects.filter(name=entry[1])
if not qs1.exists() and not qs2.exists():
print 'Adding %s' % entry[0]
host = i2phost(name=entry[0], b64hash=entry[1],
description='Auto-added from external hosts.txt',
activated=True)
host.save()
else:
print 'Host %s already exists' % entry[0]
f.close()

Loading…
Cancel
Save