精简打包之前
This commit is contained in:
@ -39,6 +39,24 @@ except ImportError:
|
||||
print("WARNING: 未安装tqdm库,将不显示进度条。如需进度条,请运行: pip install tqdm")
|
||||
|
||||
|
||||
def _safe_print(msg):
|
||||
"""
|
||||
安全打印函数,保证任何情况下不因打印而失败
|
||||
避免 Windows 控制台编码问题导致的 OSError
|
||||
"""
|
||||
try:
|
||||
print(msg)
|
||||
except Exception:
|
||||
try:
|
||||
# 回退方案:移除非ASCII字符后打印
|
||||
safe_msg = str(msg).encode('ascii', 'ignore').decode('ascii', 'ignore')
|
||||
sys.stdout.write(safe_msg + '\n')
|
||||
sys.stdout.flush()
|
||||
except Exception:
|
||||
# 最终回退:静默失败,不影响程序运行
|
||||
pass
|
||||
|
||||
|
||||
def create_height_bins(heights, bin_size=2.0):
|
||||
"""
|
||||
将高度数据按指定间隔分档
|
||||
@ -101,7 +119,7 @@ def load_excel_data(file_path):
|
||||
pd.DataFrame: 读取的数据
|
||||
"""
|
||||
try:
|
||||
print(f"正在读取Excel文件: {Path(file_path).name}")
|
||||
_safe_print(f"正在读取Excel文件: {Path(file_path).name}")
|
||||
|
||||
# 读取Excel文件
|
||||
df = pd.read_excel(file_path)
|
||||
@ -111,7 +129,7 @@ def load_excel_data(file_path):
|
||||
return df
|
||||
|
||||
except Exception as e:
|
||||
print(f" 文件读取失败: {Path(file_path).name}")
|
||||
_safe_print(f" 文件读取失败: {Path(file_path).name}")
|
||||
print(f" 错误详情: {e}")
|
||||
sys.exit(1)
|
||||
|
||||
@ -555,7 +573,7 @@ def adjust_altitude(df):
|
||||
Returns:
|
||||
pd.DataFrame: 添加调整后高度字段的DataFrame
|
||||
"""
|
||||
print("📏 创建调整后的高度字段...")
|
||||
print(" 创建调整后的高度字段...")
|
||||
|
||||
if 'fAltitudeFused' in df.columns:
|
||||
min_altitude = df['fAltitudeFused'].min()
|
||||
@ -729,7 +747,7 @@ def process_excel_file(file_path, config_path=None):
|
||||
file_path: Excel文件路径
|
||||
config_path: 配置文件路径,用于读取gases配置
|
||||
"""
|
||||
print(f" === 开始处理文件: {Path(file_path).name} ===\n")
|
||||
_safe_print(f" === 开始处理文件: {Path(file_path).name} ===\n")
|
||||
|
||||
# 1. 读取数据
|
||||
df = load_excel_data(file_path)
|
||||
@ -771,7 +789,7 @@ def process_excel_file(file_path, config_path=None):
|
||||
df.to_csv(output_path, index=False, encoding='utf-8-sig')
|
||||
|
||||
print(f"\n 处理完成!")
|
||||
print(f" 输出文件: {output_path}")
|
||||
_safe_print(f" 输出文件: {output_path}")
|
||||
print(f" 最终数据: {df.shape[0]:,} 行 × {df.shape[1]} 列")
|
||||
print(f" 最终字段: {', '.join(df.columns)}")
|
||||
|
||||
@ -807,7 +825,7 @@ def process_file(input_file, output_file=None, config_file=None):
|
||||
if output_file:
|
||||
output_path = Path(output_file)
|
||||
df.to_csv(output_path, index=False, encoding='utf-8-sig')
|
||||
print(f"额外保存到: {output_path}")
|
||||
_safe_print(f"额外保存到: {output_path}")
|
||||
|
||||
return df
|
||||
|
||||
@ -972,7 +990,7 @@ def main(input_file=None, output_file=None, interactive=False):
|
||||
if output_file:
|
||||
output_path = Path(output_file)
|
||||
df.to_csv(output_path, index=False, encoding='utf-8-sig')
|
||||
print(f"额外保存到: {output_path}")
|
||||
_safe_print(f"额外保存到: {output_path}")
|
||||
|
||||
return df
|
||||
|
||||
|
||||
@ -79,57 +79,57 @@ def cleanup_expired_tasks():
|
||||
""").fetchall()
|
||||
|
||||
if rows:
|
||||
current_app.logger.info(f"Janitor found {len(rows)} expired tasks to clean up")
|
||||
current_app.logger.info(f"Janitor found {len(rows)} expired tasks to clean up")
|
||||
|
||||
for row in rows:
|
||||
task_id = row['task_id']
|
||||
output_dir = row['output_dir']
|
||||
for row in rows:
|
||||
task_id = row['task_id']
|
||||
output_dir = row['output_dir']
|
||||
|
||||
try:
|
||||
delete_targets = []
|
||||
try:
|
||||
delete_targets = []
|
||||
|
||||
# 记录在库中的 output_dir
|
||||
if output_dir:
|
||||
p = Path(output_dir)
|
||||
delete_targets.append(p)
|
||||
# 记录在库中的 output_dir
|
||||
if output_dir:
|
||||
p = Path(output_dir)
|
||||
delete_targets.append(p)
|
||||
|
||||
# 兜底:按约定 outputs/<task_id>
|
||||
derived_output_dir = output_base / task_id if output_base else None
|
||||
if derived_output_dir and derived_output_dir not in delete_targets:
|
||||
delete_targets.append(derived_output_dir)
|
||||
# 兜底:按约定 outputs/<task_id>
|
||||
derived_output_dir = output_base / task_id if output_base else None
|
||||
if derived_output_dir and derived_output_dir not in delete_targets:
|
||||
delete_targets.append(derived_output_dir)
|
||||
|
||||
# 同时删除 uploads/<task_id>
|
||||
derived_upload_dir = upload_base / task_id if upload_base else None
|
||||
if derived_upload_dir:
|
||||
delete_targets.append(derived_upload_dir)
|
||||
# 同时删除 uploads/<task_id>
|
||||
derived_upload_dir = upload_base / task_id if upload_base else None
|
||||
if derived_upload_dir:
|
||||
delete_targets.append(derived_upload_dir)
|
||||
|
||||
if dry_run:
|
||||
for tgt in delete_targets:
|
||||
if tgt:
|
||||
current_app.logger.info(f"[DRY RUN] Would delete task {task_id} path: {tgt}")
|
||||
else:
|
||||
# 实际删除
|
||||
for tgt in delete_targets:
|
||||
try:
|
||||
if tgt and tgt.exists():
|
||||
shutil.rmtree(tgt, ignore_errors=True)
|
||||
current_app.logger.info(f"Deleted path for task {task_id}: {tgt}")
|
||||
else:
|
||||
current_app.logger.warning(f"Path not found for task {task_id}: {tgt}")
|
||||
except Exception as e:
|
||||
current_app.logger.error(f"Failed to delete path {tgt} for task {task_id}: {e}")
|
||||
if dry_run:
|
||||
for tgt in delete_targets:
|
||||
if tgt:
|
||||
current_app.logger.info(f"[DRY RUN] Would delete task {task_id} path: {tgt}")
|
||||
else:
|
||||
# 实际删除
|
||||
for tgt in delete_targets:
|
||||
try:
|
||||
if tgt and tgt.exists():
|
||||
shutil.rmtree(tgt, ignore_errors=True)
|
||||
current_app.logger.info(f"Deleted path for task {task_id}: {tgt}")
|
||||
else:
|
||||
current_app.logger.warning(f"Path not found for task {task_id}: {tgt}")
|
||||
except Exception as e:
|
||||
current_app.logger.error(f"Failed to delete path {tgt} for task {task_id}: {e}")
|
||||
|
||||
# Hard delete from database
|
||||
conn.execute(
|
||||
"DELETE FROM tasks WHERE task_id = ?",
|
||||
(task_id,)
|
||||
)
|
||||
conn.commit()
|
||||
current_app.logger.info(f"Hard deleted task {task_id} from database")
|
||||
# Hard delete from database
|
||||
conn.execute(
|
||||
"DELETE FROM tasks WHERE task_id = ?",
|
||||
(task_id,)
|
||||
)
|
||||
conn.commit()
|
||||
current_app.logger.info(f"Hard deleted task {task_id} from database")
|
||||
|
||||
except Exception as e:
|
||||
current_app.logger.error(f"Failed to delete task {task_id}: {str(e)}", exc_info=True)
|
||||
# Continue with other tasks even if one fails
|
||||
except Exception as e:
|
||||
current_app.logger.error(f"Failed to delete task {task_id}: {str(e)}", exc_info=True)
|
||||
# Continue with other tasks even if one fails
|
||||
|
||||
# Debug: Check all failed tasks
|
||||
debug_failed = conn.execute("""
|
||||
|
||||
Reference in New Issue
Block a user