def get_categories(): """Returns the all job category details. Returning element is a dictionary whose keys are job ids and values are tuples with format (jobname, jobtype) """ job_categories = {} with open(job_category_file) as inf: for line in inf: data = tkutil.parse_line(line) job_categories[data[0]] = ((data[1], JobType.WORK if data[2] == '1' else JobType.NON_WORK)) return job_categories
def search_jobs_for_ids(search_words): """Searchs for jobs whose name matches any of the given search words. It searches eagerly, not for exact match. It returns a list that contains tuples with format (jobid, jobname ) """ joblist = [] with open(job_category_file,'r') as inf: for line in inf: data = tkutil.parse_line(line) if contains_any(data[1],search_words): joblist.append((data[0], data[1])) return joblist
def search_jobs_for_ids(search_words): """Searchs for jobs whose name matches any of the given search words. It searches eagerly, not for exact match. It returns a list that contains tuples with format (jobid, jobname ) """ joblist = [] with open(job_category_file, 'r') as inf: for line in inf: data = tkutil.parse_line(line) if contains_any(data[1], search_words): joblist.append((data[0], data[1])) return joblist
def pop_from_currents(): """Returns the job id and start time of the job started before and clears the file (or related storage element)""" details = {} with open(current_job_file,'r') as inf: try: line = inf.read() data = tkutil.parse_line(line) jobid = data[0] start_time = datetime.strptime(data[1],DateFormat.COMPACT) # to ensure that data in the file is still as we have saved. details["jobid"] = jobid details["start_time"] = start_time except IndexError: pass # so no job started before return an empty dictinary open(current_job_file,'w').close() # clear file return details
def pop_from_currents(): """Returns the job id and start time of the job started before and clears the file (or related storage element)""" details = {} with open(current_job_file, 'r') as inf: try: line = inf.read() data = tkutil.parse_line(line) jobid = data[0] start_time = datetime.strptime( data[1], DateFormat.COMPACT ) # to ensure that data in the file is still as we have saved. details["jobid"] = jobid details["start_time"] = start_time except IndexError: pass # so no job started before return an empty dictinary open(current_job_file, 'w').close() # clear file return details
def add_job_category(jobtype, jobname): """Adds a new job category to job_category_file and return the id of the inserted job. If the job with exact match exists, then it raises an exception. New job will be given a job id which is (max_id_of_previous_jobs + 1) """ jobid = -1 try: with open(job_category_file,'r') as inf: for line in inf: data = tkutil.parse_line(line) if data[1] == jobname: msg = 'The job "%s" is already exists with id: %s' % (jobname, data[0]) raise ValueError(msg) # find a better exception jobid = max(jobid, int(data[0])) except IOError: pass # so first time it is running not important jobid += 1 # next job id to use with open(job_category_file,'a') as outf: outf.write(str(jobid) + "=>" + jobname + "=>" + str(jobtype) + "\n") return jobid
def add_job_category(jobtype, jobname): """Adds a new job category to job_category_file and return the id of the inserted job. If the job with exact match exists, then it raises an exception. New job will be given a job id which is (max_id_of_previous_jobs + 1) """ jobid = -1 try: with open(job_category_file, 'r') as inf: for line in inf: data = tkutil.parse_line(line) if data[1] == jobname: msg = 'The job "%s" is already exists with id: %s' % ( jobname, data[0]) raise ValueError(msg) # find a better exception jobid = max(jobid, int(data[0])) except IOError: pass # so first time it is running not important jobid += 1 # next job id to use with open(job_category_file, 'a') as outf: outf.write(str(jobid) + "=>" + jobname + "=>" + str(jobtype) + "\n") return jobid