boffire commited on
Commit
73bf55b
·
verified ·
1 Parent(s): 51af045

Update upload_suggestions.py

Browse files
Files changed (1) hide show
  1. upload_suggestions.py +25 -2
upload_suggestions.py CHANGED
@@ -3,6 +3,7 @@ import sqlite3
3
  import json
4
  import csv
5
  import hashlib
 
6
  from datetime import datetime
7
  from huggingface_hub import HfApi, hf_hub_download
8
 
@@ -18,8 +19,11 @@ CSV_OUTPUT_PATH = "/tmp/suggestions.csv"
18
  CHECKSUM_FILE_JSON = "/tmp/.last_suggestions_json_checksum"
19
  CHECKSUM_FILE_CSV = "/tmp/.last_suggestions_csv_checksum"
20
 
 
 
21
  possible_paths = [
22
- "/app/db/suggestions.db",
 
23
  "/app/suggestions.db",
24
  "/root/.local/share/db/suggestions.db",
25
  "/home/libretranslate/.local/share/db/suggestions.db"
@@ -27,11 +31,30 @@ possible_paths = [
27
 
28
  def find_db():
29
  print(f"Running in CWD: {os.getcwd()}")
 
 
30
  for path in possible_paths:
31
  if os.path.exists(path):
32
  print(f"Found suggestions.db at {path}")
33
  return path
34
- print("suggestions.db not found in any known path.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  return None
36
 
37
  def extract_suggestions(db_path):
 
3
  import json
4
  import csv
5
  import hashlib
6
+ import subprocess
7
  from datetime import datetime
8
  from huggingface_hub import HfApi, hf_hub_download
9
 
 
19
  CHECKSUM_FILE_JSON = "/tmp/.last_suggestions_json_checksum"
20
  CHECKSUM_FILE_CSV = "/tmp/.last_suggestions_csv_checksum"
21
 
22
+ # If start.sh found the DB and symlinked it, this will hit first.
23
+ # Otherwise we fall back to a dynamic search.
24
  possible_paths = [
25
+ "/app/db/suggestions.db", # symlink created by start.sh
26
+ "/app/.local/share/db/suggestions.db", # when HOME=/app
27
  "/app/suggestions.db",
28
  "/root/.local/share/db/suggestions.db",
29
  "/home/libretranslate/.local/share/db/suggestions.db"
 
31
 
32
  def find_db():
33
  print(f"Running in CWD: {os.getcwd()}")
34
+
35
+ # 1. Try known paths
36
  for path in possible_paths:
37
  if os.path.exists(path):
38
  print(f"Found suggestions.db at {path}")
39
  return path
40
+
41
+ # 2. Dynamic fallback: search the whole filesystem
42
+ print("Known paths missed — running dynamic search...")
43
+ try:
44
+ result = subprocess.run(
45
+ ["find", "/", "-name", "suggestions.db", "2>/dev/null"],
46
+ capture_output=True, text=True, timeout=15
47
+ )
48
+ # The stderr redirect in the shell command won't work via subprocess,
49
+ # so we filter empty lines.
50
+ lines = [l for l in result.stdout.splitlines() if l.strip()]
51
+ if lines:
52
+ print(f"Found suggestions.db via search at {lines[0]}")
53
+ return lines[0]
54
+ except Exception as e:
55
+ print(f"Dynamic search failed: {e}")
56
+
57
+ print("suggestions.db not found anywhere.")
58
  return None
59
 
60
  def extract_suggestions(db_path):