Okay I went over the csv module and updated my code. I have the csv in place and the file is being read but my input value is not giving me an error like it should when the wrong one is put in. Here is what I have now:
#!usr/bin/python
from subprocess import *
import sys
import ConfigParser
import os
import csv
import getopt
import time
import datetime
import logging
from sys import argv
script, solution_id, input_file = argv
#set up logging to file
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
datefmt='%d %b %Y %H:%M:%S',
filename='/etc/nagios/ingestion/logs/catch.log',
filemode='w')
# defining a Handler which writes INFO messages or higher to the sys.stderr
console = logging.StreamHandler()
console.setLevel(logging.INFO)
# setting a format which is simpler for console use
formatter = logging.Formatter('%(asctime)s %(name)-12s %(levelname)-8s %(message)s')
# telling the handler to use this format
console.setFormatter(formatter)
# adding the handler to the root logger
logging.getLogger('').addHandler(console)
#set up configuration Parser
config = ConfigParser.RawConfigParser()
config.read('/etc/nagios/ingestion/objectItems.cfg')
config.read('/etc/nagios/ingestion/action.cfg')
#get objects
objects = config.get('Objects', 'objects')
#get actions
actions = config.get('Actions', 'actions')
#if no object is found, run error
assert(sys.argv[1] != None), "object does not exist"
#logging debug
#logging.debug('object does not exist')
#Get inputs and check value and path to file
def print_all(f):
f.read()
# place an exception for incorrect path
try:
current_file = csv.reader(open(input_file, "rb"))
for row in current_file: solution_id = row[2]
if solution_id != row[2]:
print "invalid solution id"
#list exceptions
except IOError:
#logging error
logging.error('No such file or directory. Please try again')
except IOError:
print("Solution id is invalid. Please check the number and try again")
#logging error
logging.error('Solution id is invalid. Please check the number and try again')
except IOErrorclauses for the sametry. Only the first one will fire. Is this a typo, or is that in your real code?