drdata commited on
Commit
074e23e
Β·
verified Β·
1 Parent(s): 1efe6cd

Upload folder using huggingface_hub

Browse files
Files changed (4) hide show
  1. Generated/README.md +1 -1
  2. __pycache__/app.cpython-313.pyc +0 -0
  3. app.py +112 -7
  4. temp-app.py +0 -0
Generated/README.md CHANGED
@@ -1,3 +1,3 @@
1
- # Generated
2
 
3
  Placeholder to ensure this directory is tracked.
 
1
+ # view_session
2
 
3
  Placeholder to ensure this directory is tracked.
__pycache__/app.cpython-313.pyc CHANGED
Binary files a/__pycache__/app.cpython-313.pyc and b/__pycache__/app.cpython-313.pyc differ
 
app.py CHANGED
@@ -21,7 +21,7 @@ def ensure_root_directories(main_workspace: Path) -> None:
21
  main_workspace / "static" / "css",
22
  main_workspace / "static" / "js",
23
  main_workspace / "static" / "images",
24
- main_workspace / "view_session",
25
  ]
26
 
27
  for d in required:
@@ -51,6 +51,51 @@ def ensure_root_directories(main_workspace: Path) -> None:
51
  except Exception as e:
52
  print(f"⚠️ Warning: could not ensure {d}: {e}")
53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  def create_symlinks_to_real_folders(cache_dir):
55
  """Create symbolic links in cache directory to real folders in main workspace."""
56
  # Use the directory containing this script as root workspace
@@ -63,7 +108,8 @@ def create_symlinks_to_real_folders(cache_dir):
63
 
64
  for folder_name in folders_to_link:
65
  # Real folder path in main workspace
66
- real_folder = main_workspace / folder_name
 
67
  # Symbolic link path in cache
68
  link_path = cache_dir / folder_name
69
 
@@ -71,19 +117,49 @@ def create_symlinks_to_real_folders(cache_dir):
71
  # Ensure real folder exists (defensive)
72
  real_folder.mkdir(parents=True, exist_ok=True)
73
 
74
- # Remove existing file/folder/link if it exists
75
  if link_path.exists() or link_path.is_symlink():
76
  if link_path.is_symlink():
 
 
 
 
 
 
 
77
  link_path.unlink()
78
  elif link_path.is_dir():
79
- shutil.rmtree(link_path)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
  else:
 
81
  link_path.unlink()
82
-
83
  # Create symbolic link
84
  link_path.symlink_to(real_folder, target_is_directory=True)
85
  print(f"βœ… Created symlink: {link_path} -> {real_folder}")
86
-
87
  except Exception as e:
88
  print(f"⚠️ Warning: Could not create symlink for {folder_name}: {e}")
89
  # Fallback: create empty directory
@@ -93,6 +169,32 @@ def create_symlinks_to_real_folders(cache_dir):
93
  print("🎯 All symbolic links are ready!")
94
  return True
95
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  def modify_byteplus_for_directories(cache_dir):
97
  """Modify the BytePlus app to ensure proper directory handling."""
98
  app_file = cache_dir / "app.py"
@@ -383,7 +485,10 @@ if __name__ == "__main__":
383
  print(f"πŸ“ Cache directory: {cache_dir}")
384
 
385
  # Ensure root directories exist first (as requested)
386
- ensure_root_directories(Path(__file__).parent.resolve())
 
 
 
387
 
388
  # Download the space
389
  if download_space(cache_dir):
 
21
  main_workspace / "static" / "css",
22
  main_workspace / "static" / "js",
23
  main_workspace / "static" / "images",
24
+ main_workspace / "view_session",
25
  ]
26
 
27
  for d in required:
 
51
  except Exception as e:
52
  print(f"⚠️ Warning: could not ensure {d}: {e}")
53
 
54
+ def ensure_view_session_points_to_generated(main_workspace: Path) -> None:
55
+ """Ensure root-level view_session is a symlink to Generated (so UI views read from Generated)."""
56
+ vs = main_workspace / "view_session"
57
+ gen = main_workspace / "Generated"
58
+ try:
59
+ gen.mkdir(parents=True, exist_ok=True)
60
+ if vs.exists() or vs.is_symlink():
61
+ try:
62
+ if vs.is_symlink() and vs.resolve() == gen.resolve():
63
+ print(f"πŸ”— Root symlink already set: {vs} -> {gen}")
64
+ return
65
+ except Exception:
66
+ pass
67
+ if vs.is_symlink():
68
+ vs.unlink()
69
+ elif vs.is_dir():
70
+ # migrate contents into Generated
71
+ for item in vs.iterdir():
72
+ dest = gen / item.name
73
+ try:
74
+ if item.is_dir():
75
+ if dest.exists():
76
+ for sub in item.iterdir():
77
+ sub.rename(dest / sub.name)
78
+ item.rmdir()
79
+ else:
80
+ item.rename(dest)
81
+ else:
82
+ if dest.exists():
83
+ dest.unlink()
84
+ item.rename(dest)
85
+ except Exception as me:
86
+ print(f"⚠️ Root migration warning for {item}: {me}")
87
+ try:
88
+ vs.rmdir()
89
+ except Exception:
90
+ pass
91
+ else:
92
+ vs.unlink()
93
+ # create symlink view_session -> Generated
94
+ vs.symlink_to(gen, target_is_directory=True)
95
+ print(f"πŸ”— Root linked {vs} -> {gen}")
96
+ except Exception as e:
97
+ print(f"⚠️ Could not link root view_session to Generated: {e}")
98
+
99
  def create_symlinks_to_real_folders(cache_dir):
100
  """Create symbolic links in cache directory to real folders in main workspace."""
101
  # Use the directory containing this script as root workspace
 
108
 
109
  for folder_name in folders_to_link:
110
  # Real folder path in main workspace
111
+ # Map view_session to Generated so the UI reads sessions from Generated
112
+ real_folder = (main_workspace / "Generated") if folder_name == "view_session" else (main_workspace / folder_name)
113
  # Symbolic link path in cache
114
  link_path = cache_dir / folder_name
115
 
 
117
  # Ensure real folder exists (defensive)
118
  real_folder.mkdir(parents=True, exist_ok=True)
119
 
120
+ # If an entry exists at the link path, handle safely
121
  if link_path.exists() or link_path.is_symlink():
122
  if link_path.is_symlink():
123
+ try:
124
+ # If already correct, keep it
125
+ if link_path.resolve() == real_folder.resolve():
126
+ print(f"βœ… Symlink already set: {link_path} -> {real_folder}")
127
+ continue
128
+ except Exception:
129
+ pass
130
  link_path.unlink()
131
  elif link_path.is_dir():
132
+ # Migrate existing contents to the real folder before replacing
133
+ for item in link_path.iterdir():
134
+ dest = real_folder / item.name
135
+ try:
136
+ if item.is_dir():
137
+ if dest.exists():
138
+ # Merge directories
139
+ for sub in item.iterdir():
140
+ sub.rename(dest / sub.name)
141
+ item.rmdir()
142
+ else:
143
+ item.rename(dest)
144
+ else:
145
+ if dest.exists():
146
+ dest.unlink()
147
+ item.rename(dest)
148
+ except Exception as me:
149
+ print(f"⚠️ Migration warning for {item}: {me}")
150
+ # Remove the now-empty directory
151
+ try:
152
+ link_path.rmdir()
153
+ except Exception:
154
+ pass
155
  else:
156
+ # Regular file – remove so we can place a symlink
157
  link_path.unlink()
158
+
159
  # Create symbolic link
160
  link_path.symlink_to(real_folder, target_is_directory=True)
161
  print(f"βœ… Created symlink: {link_path} -> {real_folder}")
162
+
163
  except Exception as e:
164
  print(f"⚠️ Warning: Could not create symlink for {folder_name}: {e}")
165
  # Fallback: create empty directory
 
169
  print("🎯 All symbolic links are ready!")
170
  return True
171
 
172
+ def verify_cache_symlink(cache_dir: Path, name: str, root_dir: Path) -> bool:
173
+ """Verify a specific symlink in cache points to the corresponding root dir and is writable."""
174
+ link = cache_dir / name
175
+ target = root_dir / name
176
+ try:
177
+ if not link.exists():
178
+ print(f"❌ Missing link/path in cache: {link}")
179
+ return False
180
+ if not link.is_symlink():
181
+ print(f"⚠️ Cache path is not a symlink (still usable): {link}")
182
+ else:
183
+ if link.resolve() != target.resolve():
184
+ print(f"⚠️ Symlink target mismatch: {link.resolve()} != {target}")
185
+ else:
186
+ print(f"πŸ”— Verified symlink: {link} -> {target}")
187
+ # Write/read test
188
+ tf = link / ".__verify__"
189
+ tf.write_text("ok")
190
+ assert (target / ".__verify__").read_text() == "ok"
191
+ tf.unlink(missing_ok=True)
192
+ print(f"βœ… Write/Read OK via cache link: {link}")
193
+ return True
194
+ except Exception as e:
195
+ print(f"❌ Verification failed for {link}: {e}")
196
+ return False
197
+
198
  def modify_byteplus_for_directories(cache_dir):
199
  """Modify the BytePlus app to ensure proper directory handling."""
200
  app_file = cache_dir / "app.py"
 
485
  print(f"πŸ“ Cache directory: {cache_dir}")
486
 
487
  # Ensure root directories exist first (as requested)
488
+ root = Path(__file__).parent.resolve()
489
+ ensure_root_directories(root)
490
+ # Ensure view_session at root points to Generated for History/View/ZIP
491
+ ensure_view_session_points_to_generated(root)
492
 
493
  # Download the space
494
  if download_space(cache_dir):
temp-app.py ADDED
File without changes