re.search experts needed on fqdn stripping..

R

rh0dium

Hi all,

Ok I have a list

hosts = [ "poundcake.fqdn.com", "scorpion.fqdn.com", "loghost",
"scorpian", "localhost", "lan", "lan.fpdn.com" ]

Assumptions:
scorpian.fqdn.com == scorpian
lan == lan.fqdn.com

I want pear this list down based on the following:
1. ignore loghost, localhost, timehost, mailhost
2. Use the first found name used reguardless if it is the fqdn or not

So what you would get back out is this..

hosts = [ "poundcake.fqdn.com", "scorpion.fqdn.com", "lan" ]

Now here is my code - and I have a problem with the splitting. I am
really looking for a cool ( but understandable ) way to simplify this..

e =[]
for host in hosts:

sn = re.split( "\.", host)

ig = 1
ignore = [ "localhost", "loghost", "timehost", "mailhost" ]
for i in ignore:
if i == sn[0]:
ig = 0
if ig:
print "%s not ignored" % sn[0]
found = 0
for n in e:
sm = re.split( "\.", n)
print "checking %s to %s" % (sm[0], sn[0])
if sm[0] == sn[0]:
print "match";
found = 1
if found == 0:
print "appending %s " % host
e.append(host)

print e


Which kicks out..
poundcake not ignored
appending poundcake.nsc.com
scorpion not ignored
checking poundcake to scorpion
appending scorpion.nsc.com
scorpian not ignored
checking poundcake to scorpian
checking scorpion to scorpian
appending scorpian
lan not ignored
checking poundcake to lan
checking scorpion to lan
checking scorpian to lan
appending lan
['poundcake.fpdn.com', 'scorpion.fpdn.com', 'scorpian', 'lan']

Crap still wrong..
 
R

rh0dium

OK Duh..

After thinking about it for a bit longer i simplified it but still have
the same problem..

e =[]
hosts = [ "poundcake.fpdn.com", "scorpion.fpdn.com", "loghost",
"scorpian", "localhost", "lan" ]

ignore = [ "localhost", "loghost", "timehost", "mailhost" ]

for host in hosts:
sn = re.split( "\.", host)
if not sn[0] in ignore:
e.append(host)
ignore.append(sn[0])
print e

But this STILL gives me some problems..
['poundcake.nsc.com', 'scorpion.fqdn.com', 'scorpian', 'lan']

Nope - OK I am an idiot - try spelling idiot..

Thanks
 
M

Mike Meyer

rh0dium said:
After thinking about it for a bit longer i simplified it but still have
the same problem..

e =[]
hosts = [ "poundcake.fpdn.com", "scorpion.fpdn.com", "loghost",
"scorpian", "localhost", "lan" ]

ignore = [ "localhost", "loghost", "timehost", "mailhost" ]

for host in hosts:
sn = re.split( "\.", host)

This should be host.split(".").
if not sn[0] in ignore:
e.append(host)
ignore.append(sn[0])
print e

But this STILL gives me some problems..
['poundcake.nsc.com', 'scorpion.fqdn.com', 'scorpian', 'lan']

Nope - OK I am an idiot - try spelling idiot..

Can I take it that you saw that "scorpion" is not the same as
"scorpian"?

BTW, if you're using 2.4 and don't care about portability, I'd make
ignore a set instead of a list.

<mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,264
Messages
2,571,323
Members
48,005
Latest member
ChasityFan

Latest Threads

Top