mirror of
				https://github.com/qurator-spk/modstool.git
				synced 2025-11-04 03:14:14 +01:00 
			
		
		
		
	🐛 Don't use bare except, check for existence of index column instead
This commit is contained in:
		
							parent
							
								
									1e5cfcc0e5
								
							
						
					
					
						commit
						664900635d
					
				
					 2 changed files with 13 additions and 4 deletions
				
			
		| 
						 | 
					@ -452,3 +452,12 @@ def convert_db_to_parquet(con, table, index_col, output_file):
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    df.to_parquet(output_file)
 | 
					    df.to_parquet(output_file)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def sqlite3_column_exists(con, table, col):
 | 
				
			||||||
 | 
					    """Check if column col exists in table."""
 | 
				
			||||||
 | 
					    cur = con.execute(
 | 
				
			||||||
 | 
					            "SELECT 1 FROM pragma_table_info(?) WHERE name = ? LIMIT 1",
 | 
				
			||||||
 | 
					            (table, col)
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					    return cur.fetchone() is not None
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -20,6 +20,7 @@ from .lib import (
 | 
				
			||||||
    insert_into_db_multiple,
 | 
					    insert_into_db_multiple,
 | 
				
			||||||
    ns,
 | 
					    ns,
 | 
				
			||||||
    sorted_groupby,
 | 
					    sorted_groupby,
 | 
				
			||||||
 | 
					    sqlite3_column_exists,
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -643,17 +644,16 @@ def process(mets_files: list[str], output_file: str, output_page_info: str, mets
 | 
				
			||||||
                logger.exception("Exception in {}".format(mets_file))
 | 
					                logger.exception("Exception in {}".format(mets_file))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    logger.info("Writing DataFrame to {}".format(output_file))
 | 
					    logger.info("Writing DataFrame to {}".format(output_file))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    considered_indexes = ("recordInfo_recordIdentifier", "recordIdentifier-zdb")
 | 
					    considered_indexes = ("recordInfo_recordIdentifier", "recordIdentifier-zdb")
 | 
				
			||||||
    success = False
 | 
					    success = False
 | 
				
			||||||
    for considered_index in considered_indexes:
 | 
					    for considered_index in considered_indexes:
 | 
				
			||||||
        try:
 | 
					        if sqlite3_column_exists(con, "mods_info", considered_index):
 | 
				
			||||||
            convert_db_to_parquet(con, "mods_info", considered_index, output_file)
 | 
					            convert_db_to_parquet(con, "mods_info", considered_index, output_file)
 | 
				
			||||||
            success = True
 | 
					            success = True
 | 
				
			||||||
            break
 | 
					            break
 | 
				
			||||||
        except:
 | 
					 | 
				
			||||||
            pass
 | 
					 | 
				
			||||||
    if not success:
 | 
					    if not success:
 | 
				
			||||||
        raise ValueError(f"None of {considered_indexes} found")
 | 
					        raise ValueError(f"Can't set index, none of {considered_indexes} found")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if output_page_info:
 | 
					    if output_page_info:
 | 
				
			||||||
        logger.info("Writing DataFrame to {}".format(output_page_info))
 | 
					        logger.info("Writing DataFrame to {}".format(output_page_info))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue