def __init__(self, config): # keep a reference to the config self.config = config # validate corpus path exists if os.path.exists(config.corpusPath) == False: io.printErrorAndExit("corpus not found at {}".format( config.corpusPath)) # validate that students.txt exists, create array studentText = io.readFile(config.corpusPath + "students.txt") self.students = [] studentText = studentText.strip().split("\n") for student in studentText: self.students.append(student.strip()) # try to load the semester map self.hasSemesters = False self.semesterMap = {} if os.path.exists(config.corpusPath + "semesters.csv"): handle = open(config.corpusPath + "semesters.csv", "r") reader = csv.reader(handle) for row in reader: self.semesterMap[row[0]] = row[1].strip() self.hasSemesters = True
def __init__(self, configFile): try: # Read the JSON, set basic attributes self.rawJSON = io.readJSON(configFile) self.corpusPath = self.rawJSON['corpusPath'] # Make sure corpus path ends in '/' if self.corpusPath[-1] != '/': self.corpusPath = self.corpusPath + "/" # Process the jobs self.jobs = [] for job in self.rawJSON['jobs']: self.jobs.append(Job(job)) except: io.printErrorAndExit("Invalid configuration file.")
def __init__(self, config): self.mode = "all" self.jobs = [] self.options = [] args = sys.argv[1:] if len(args) > 0: # check if the first arg is a mode if args[0].lower() in ["all", 'preprocess', 'postprocess', 'process', 'process+post']: self.mode = args[0].lower() args = args[1:] # process jobs and options while len(args) > 0: arg = args[0] args = args[1:] found = False for job in config.jobs: # case sensitive if job.name == arg: self.jobs.append(arg) found = True break if found == False and arg.lower() in ["--force", "--clean", "--cleanpre"]: self.options.append(arg[2:].lower()) found = True if found == False: # job not found or option invalid io.printErrorAndExit('Invalid job name or option specified as argument.') # no jobs? Add them all. if len(self.jobs) == 0: for job in config.jobs: self.jobs.append(job.name) # Mode not 'all'? Add force. if self.mode != 'all' and 'force' not in self.options: self.options.append('force') # Have "clean"? Add force. if "clean" in self.options or "cleanpre" in self.options: self.options.append('force')
def __init__(self, config): # keep a reference to the config self.config = config # validate corpus path exists if os.path.exists(config.corpusPath) == False: io.printErrorAndExit("corpus not found at {}".format(config.corpusPath)) # validate that students.txt exists, create array studentText = io.readFile(config.corpusPath + "students.txt") self.students = [] studentText = studentText.strip().split("\n") for student in studentText: self.students.append(student.strip()) # try to load the semester map self.hasSemesters = False self.semesterMap = {} if os.path.exists(config.corpusPath + "semesters.csv"): handle = open(config.corpusPath + "semesters.csv", "r") reader = csv.reader(handle) for row in reader: self.semesterMap[row[0]] = row[1].strip() self.hasSemesters = True