I'm having a bit of an issue. For some reason, this class I'm trying to put together is throwing a NoneType error when, for all intents and purposes it should be responding properly as far as I can tell.
import re
import subprocess
class progEnv( object ) :
hostName_regex = re.compile( '[a-z][a-z]prog[a-z][a-z][a-z]\d\d' )
hostDomain_regex = re.compile( '(prod|dev|qa1|stag)\.company\.net' )
hostNum_regex = re.compile( '[a-z][a-z]prog[a-z][a-z][a-z](\d\d)' )
hostPrefix_regex = re.compile( '\w\wprog' )
hostTier_regex = re.compile( '(web|app)' )
hostId_regex = re.compile( '[a-z][a-z]prog[a-z][a-z][a-z]\d\d([a-z])' )
hostEnv_regex = re.compile( '(prod|dev|qa1|stag)' )
def __init__( self ) :
self.hostnameProc = subprocess.Popen( 'hostname', stdout=subprocess.PIPE )
self.fqdn = self.hostnameProc.stdout.read()
self.hostName = self.hostName_regex.search( self.fqdn )
self.hostDomain = self.hostDomain_regex.search( self.fqdn )
self.hostNum = self.hostNum_regex.search( self.hostName.group() )
self.hostPrefix = self.hostPrefix_regex.search( self.hostName.group() )
self.hostTier = self.hostTier_regex.search( self.hostName.group() )
self.hostId = self.hostId_regex.search( self.hostName.group() )
self.hostEnv = self.hostEnv_regex.search( self.hostName.group() )
When I instantiate the progEnv class the program fails on the call to self.hostName.group() with an error of:
Traceback (most recent call last):
File "./test.py", line 5, in <module>
env = prog_env.progEnv()
File "/prog/eclipse/workspace/PROG Management Command/prog_env.py", line 28, in __init__
self.hostNum = self.hostNum_regex.search( self.hostName.group() )
AttributeError: 'NoneType' object has no attribute 'group'
Any thoughts on what is happening?