def sort_by_status(self): """ raise an exception if there is no aip directory for one of the submissions move submission directories into aip subdirectories with same name as submission's status create subdirectories as needed :param aip_dir: path to directory with DSpace aio subdirectories """ idx = self.submissions.col_index_of(VireoSheet.ID) status_idx = self.submissions.col_index_of(VireoSheet.STATUS) department_idx = self.submissions.col_index_of(VireoSheet.DEPARTMENT) multi_author_idx = self.submissions.col_index_of(VireoSheet.MULTI_AUTHOR) for sub_id in self.submissions.id_rows: vals = VireoSheet.row_values(self.submissions.id_rows[sub_id][0]) sub_id = int(float(vals[idx])) if (vals[multi_author_idx].upper() == "YES"): subdir = 'Multi-Author' else: subdir = '' subdir = subdir + "/" + vals[status_idx].replace(' ', '-') dept = vals[department_idx] #print(sub_id, vals[multi_author_idx].upper(), subdir) sub_dir_name = "%s/%s/%s" % ( self.aip_dir, subdir, dept.replace(" ", "_")) if not os.path.exists(sub_dir_name): os.makedirs(sub_dir_name) cur_dir = "%s/submission_%d" % (self.aip_dir, sub_id) new_dir = "%s/submission_%d" % (sub_dir_name, sub_id) os.rename(cur_dir, new_dir)
def main(): try: parser = ArgParser.create() args = parser.parse_args() logging.getLogger().setLevel(args.loglevel) logging.basicConfig() submissions = VireoSheet.createFromExcelFile(args.thesis) submissions.col_index_of(VireoSheet.MULTI_AUTHOR) submissions.log_info() moreCerts = submissions.readMoreCerts(args.add_certs, check_id=False) moreCerts.log_info() restrictions = submissions.readRestrictions(args.restrictions, check_id=False) restrictions.log_info() enhancer = EnhanceAips(submissions, args.aips, args.cover_page) enhancer.addCertiticates(moreCerts) enhancer.addRestrictions(restrictions) enhancer.print_table(file=sys.stdout) enhancer.adjust_aips() if (enhancer.error > 0): raise RuntimeError("%s errors" % enhancer.error) #_enhanceAips(submissions, moreCerts, restrictions, args.aips) sys.exit(0) except Exception as e: logging.error(e) logging.debug(traceback.format_exc()) sys.exit(1)
def snippet(): logging.getLogger().setLevel('INFO') # code snippet when in case you want to test in interactive python wb = openpyxl.load_workbook(filename='Thesis.xlsx') sheet = wb.worksheets[0] v = VireoSheet.createFromExcelFile('Thesis.xlsx') v.log_info() certs = v.readMoreCerts('AdditionalPrograms.xlsx') certs.log_info() return certs
def addCertiticates(self, moreCerts): idx = self.submissions.col_index_of(VireoSheet.ID) cp_idx = self.submissions.col_index_of(VireoSheet.CERTIFICATE_PROGRAM) more_cp_idx = moreCerts.col_index_of(VireoSheet.CERTIFICATE_PROGRAM) for sub in self.submissions_tbl: sub_id = sub[idx] if (sub_id in moreCerts.id_rows): for row in moreCerts.id_rows[sub_id]: pgm = VireoSheet.row_values(row)[more_cp_idx] logging.info( "ADDING cert program '%s' to submission with ID %d" % (pgm, sub[idx])) sub[cp_idx].append(pgm)
def _make_submission_table(self): aip_tbl = [] idx = self.submissions.col_index_of(VireoSheet.ID) stud_idx = self.submissions.col_index_of(VireoSheet.STUDENT_NAME) cp_idx = self.submissions.col_index_of(VireoSheet.CERTIFICATE_PROGRAM) multi_idx = self.submissions.col_index_of(VireoSheet.MULTI_AUTHOR) for sub_id in self.submissions.id_rows: vals = VireoSheet.row_values(self.submissions.id_rows[sub_id][0]) vals[idx] = int(float(vals[idx])) vals[multi_idx] = vals[multi_idx].upper() == "YES" #vals[stud_idx] = [ vals[stud_idx] ] cp = vals[cp_idx] vals[cp_idx] = [cp] if (cp) else [] logging.debug("\t".join(str(_) for _ in vals) + "\n") # add two cols at end for walkin and embargo restrictions aip_tbl.append(vals + [None, None]) return aip_tbl
def main(): try: parser = ArgParser.create() args = parser.parse_args() logging.getLogger().setLevel(args.loglevel) logging.basicConfig() submissions = VireoSheet.createFromExcelFile(args.thesis) submissions.col_index_of(VireoSheet.MULTI_AUTHOR) submissions.log_info() sorter = SortByStatus(submissions, args.aips) sorter.sort_by_status() sys.exit(0) except Exception as e: logging.error(str(e)) logging.debug(traceback.format_exc()) sys.exit(1)
def main(): try: parser = ArgParser.create() args = parser.parse_args() logging.getLogger().setLevel(args.loglevel) logging.basicConfig() submissions = VireoSheet.VireoSheet(args.thesis) submissions.log_info() splits = {} addToSplits(splits, split_on=args.split_col, split_data=submissions, submissions=submissions) if (args.add_certs): moreCerts = submissions.readMoreCerts(args.add_certs) addToSplits(splits, split_on=args.split_col, split_data=moreCerts, submissions=submissions) if (args.all_cols): print_col_names = submissions.col_names() else: # print cols that are in PRIN_COLUMNS and in submission's col_names print_col_names = list( filter(lambda x: x in submissions.col_names(), PRINT_COLUMNS)) print_col_ids = [ submissions.col_index_of(name, required=True) for name in print_col_names ] print_splits(splits, print_col_names, print_col_ids) except Exception as e: logging.error(e) logging.debug(traceback.format_exc())
def main(): try: parser = ArgParser.create() args = parser.parse_args() logging.getLogger().setLevel(args.loglevel) logging.basicConfig() submissions = VireoSheet.createFromExcelFile(args.thesis) submissions.col_index_of(VireoSheet.MULTI_AUTHOR) submissions.log_info() restrictions = submissions.readRestrictions(args.restrictions, check_id=False) restrictions.log_info() matchIds(submissions, restrictions) except Exception as e: logging.error(e) logging.debug(traceback.format_exc()) sys.exit(1)