HOPStudio commited on
Commit
88d0709
·
verified ·
1 Parent(s): fb6b387

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +46 -0
main.py CHANGED
@@ -465,6 +465,48 @@ def is_comfy_portable_ready():
465
  return os.path.exists(COMFY_PORTABLE_PYTHON) and os.path.exists(COMFYUI_MAIN)
466
 
467
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
468
  def download_comfy_portable_from_modelscope():
469
  if is_comfy_portable_ready():
470
  print(f"检测到已解压的 comfy_portable: {COMFY_PORTABLE_DIR}")
@@ -559,6 +601,8 @@ def extract_comfy_portable():
559
  with zipfile.ZipFile(COMFY_PORTABLE_ZIP_PATH, "r") as zf:
560
  zf.extractall("/root")
561
 
 
 
562
  if is_comfy_portable_ready():
563
  print(f"comfy_portable 解压完成: {COMFY_PORTABLE_DIR}")
564
  return True
@@ -587,6 +631,8 @@ def start_comfyui_process():
587
  print("comfy_portable 准备失败,跳过 ComfyUI 启动。")
588
  return
589
 
 
 
590
  if not os.path.exists(COMFY_PORTABLE_PYTHON):
591
  print(f"未找到便携 Python: {COMFY_PORTABLE_PYTHON}")
592
  return
 
465
  return os.path.exists(COMFY_PORTABLE_PYTHON) and os.path.exists(COMFYUI_MAIN)
466
 
467
 
468
+ def ensure_comfy_portable_permissions():
469
+ """修复 zip 解压后丢失的可执行权限,只作用于 comfy_portable。"""
470
+ if not os.path.isdir(COMFY_PORTABLE_DIR):
471
+ return
472
+
473
+ paths_to_chmod = [
474
+ COMFY_PORTABLE_PYTHON,
475
+ os.path.join(COMFY_PORTABLE_DIR, "python", "bin", "python"),
476
+ os.path.join(COMFY_PORTABLE_DIR, "python", "bin", "python3.10"),
477
+ os.path.join(COMFY_PORTABLE_DIR, "start.sh"),
478
+ ]
479
+
480
+ for path in paths_to_chmod:
481
+ if not os.path.exists(path):
482
+ continue
483
+
484
+ try:
485
+ current_mode = os.stat(path).st_mode
486
+ os.chmod(path, current_mode | 0o755)
487
+ print(f"已修复执行权限: {path}")
488
+ except Exception as e:
489
+ print(f"修复执行权限失败: {path}, {e}")
490
+
491
+ python_bin_dir = os.path.join(COMFY_PORTABLE_DIR, "python", "bin")
492
+ if os.path.isdir(python_bin_dir):
493
+ try:
494
+ subprocess.run(
495
+ [
496
+ "bash",
497
+ "-lc",
498
+ f"find {python_bin_dir!r} -type f -exec chmod +x {{}} \\;"
499
+ ],
500
+ check=False,
501
+ stdout=subprocess.DEVNULL,
502
+ stderr=subprocess.DEVNULL,
503
+ timeout=60
504
+ )
505
+ print(f"已修复 python/bin 下文件执行权限: {python_bin_dir}")
506
+ except Exception as e:
507
+ print(f"批量修复 python/bin 权限失败: {e}")
508
+
509
+
510
  def download_comfy_portable_from_modelscope():
511
  if is_comfy_portable_ready():
512
  print(f"检测到已解压的 comfy_portable: {COMFY_PORTABLE_DIR}")
 
601
  with zipfile.ZipFile(COMFY_PORTABLE_ZIP_PATH, "r") as zf:
602
  zf.extractall("/root")
603
 
604
+ ensure_comfy_portable_permissions()
605
+
606
  if is_comfy_portable_ready():
607
  print(f"comfy_portable 解压完成: {COMFY_PORTABLE_DIR}")
608
  return True
 
631
  print("comfy_portable 准备失败,跳过 ComfyUI 启动。")
632
  return
633
 
634
+ ensure_comfy_portable_permissions()
635
+
636
  if not os.path.exists(COMFY_PORTABLE_PYTHON):
637
  print(f"未找到便携 Python: {COMFY_PORTABLE_PYTHON}")
638
  return