Update app.py
Browse files
app.py
CHANGED
|
@@ -5,7 +5,6 @@ import os
|
|
| 5 |
import sys
|
| 6 |
|
| 7 |
# Disable Streamlit's telemetry and usage statistics
|
| 8 |
-
# This prevents it from trying to write to /.streamlit directory
|
| 9 |
os.environ['STREAMLIT_ANALYTICS_ENABLED'] = 'false'
|
| 10 |
os.environ['STREAMLIT_METRICS_ENABLED'] = 'false'
|
| 11 |
os.environ['STREAMLIT_BROWSER_GATHER_USAGE_STATS'] = '0'
|
|
@@ -192,38 +191,25 @@ STATUS_COLORS = {
|
|
| 192 |
"Done": "done"
|
| 193 |
}
|
| 194 |
|
| 195 |
-
#
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
|
|
|
| 199 |
possible_locations = [
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
"/
|
| 203 |
-
"
|
| 204 |
-
"/data"
|
|
|
|
| 205 |
]
|
| 206 |
|
| 207 |
for location in possible_locations:
|
| 208 |
-
|
| 209 |
-
# Test if we can write to this location
|
| 210 |
-
test_file = os.path.join(location, "test_write.txt")
|
| 211 |
-
os.makedirs(location, exist_ok=True)
|
| 212 |
-
with open(test_file, 'w') as f:
|
| 213 |
-
f.write('test')
|
| 214 |
-
os.remove(test_file)
|
| 215 |
return location
|
| 216 |
-
except (PermissionError, OSError):
|
| 217 |
-
continue
|
| 218 |
|
| 219 |
-
|
| 220 |
-
# Just use current directory without writing to disk
|
| 221 |
-
return os.getcwd()
|
| 222 |
-
|
| 223 |
-
# Set up paths
|
| 224 |
-
DATA_DIR = get_data_path()
|
| 225 |
-
TASKS_FILE = os.path.join(DATA_DIR, "tasks.csv")
|
| 226 |
-
ASSIGNEE_FILE = os.path.join(DATA_DIR, "Assignee.txt")
|
| 227 |
|
| 228 |
def create_empty_df():
|
| 229 |
"""Create an empty DataFrame with the required columns"""
|
|
@@ -247,10 +233,6 @@ def load_tasks():
|
|
| 247 |
def save_tasks():
|
| 248 |
"""Save tasks to CSV file with better error handling"""
|
| 249 |
try:
|
| 250 |
-
# Make sure parent directory exists
|
| 251 |
-
os.makedirs(os.path.dirname(TASKS_FILE), exist_ok=True)
|
| 252 |
-
|
| 253 |
-
# Save with appropriate permissions
|
| 254 |
st.session_state.tasks.to_csv(TASKS_FILE, index=False)
|
| 255 |
return True
|
| 256 |
except Exception:
|
|
@@ -258,29 +240,44 @@ def save_tasks():
|
|
| 258 |
return False
|
| 259 |
|
| 260 |
def load_assignees():
|
| 261 |
-
"""Load assignees from text file
|
| 262 |
default_assignees = ["John Doe", "Jane Smith", "Alex Johnson", "Maria Garcia"]
|
| 263 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 264 |
try:
|
| 265 |
-
if not os.path.exists(ASSIGNEE_FILE):
|
| 266 |
-
# Create a sample file
|
| 267 |
-
try:
|
| 268 |
-
with open(ASSIGNEE_FILE, "w") as f:
|
| 269 |
-
f.write("John Doe - Producer\nJane Smith - Director\nAlex Johnson - Camera Operator\nMaria Garcia - Editor\n")
|
| 270 |
-
except:
|
| 271 |
-
return default_assignees
|
| 272 |
-
|
| 273 |
assignees = []
|
| 274 |
-
with open(
|
| 275 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 276 |
for line in lines:
|
| 277 |
if '-' in line:
|
| 278 |
name_part = line.split('-')[0].strip()
|
| 279 |
if ' ' in name_part:
|
| 280 |
assignees.append(name_part)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 281 |
|
| 282 |
-
|
| 283 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 284 |
return default_assignees
|
| 285 |
|
| 286 |
# Initialize session state ONLY ONCE
|
|
|
|
| 5 |
import sys
|
| 6 |
|
| 7 |
# Disable Streamlit's telemetry and usage statistics
|
|
|
|
| 8 |
os.environ['STREAMLIT_ANALYTICS_ENABLED'] = 'false'
|
| 9 |
os.environ['STREAMLIT_METRICS_ENABLED'] = 'false'
|
| 10 |
os.environ['STREAMLIT_BROWSER_GATHER_USAGE_STATS'] = '0'
|
|
|
|
| 191 |
"Done": "done"
|
| 192 |
}
|
| 193 |
|
| 194 |
+
# Set up paths
|
| 195 |
+
TASKS_FILE = "tasks.csv" # Simplified path for tasks
|
| 196 |
+
|
| 197 |
+
# Check all possible locations for Assignee.txt
|
| 198 |
+
def find_assignee_file():
|
| 199 |
possible_locations = [
|
| 200 |
+
"Assignee.txt", # Root directory
|
| 201 |
+
"./Assignee.txt", # Explicit current directory
|
| 202 |
+
"/app/Assignee.txt", # Docker app directory
|
| 203 |
+
os.path.join(os.getcwd(), "Assignee.txt"), # Full path to current directory
|
| 204 |
+
"/data/Assignee.txt", # Data directory
|
| 205 |
+
"../Assignee.txt", # Parent directory
|
| 206 |
]
|
| 207 |
|
| 208 |
for location in possible_locations:
|
| 209 |
+
if os.path.exists(location):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 210 |
return location
|
|
|
|
|
|
|
| 211 |
|
| 212 |
+
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 213 |
|
| 214 |
def create_empty_df():
|
| 215 |
"""Create an empty DataFrame with the required columns"""
|
|
|
|
| 233 |
def save_tasks():
|
| 234 |
"""Save tasks to CSV file with better error handling"""
|
| 235 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 236 |
st.session_state.tasks.to_csv(TASKS_FILE, index=False)
|
| 237 |
return True
|
| 238 |
except Exception:
|
|
|
|
| 240 |
return False
|
| 241 |
|
| 242 |
def load_assignees():
|
| 243 |
+
"""Load assignees from text file with extensive debugging and fallbacks"""
|
| 244 |
default_assignees = ["John Doe", "Jane Smith", "Alex Johnson", "Maria Garcia"]
|
| 245 |
|
| 246 |
+
# Find the Assignee.txt file
|
| 247 |
+
assignee_file_path = find_assignee_file()
|
| 248 |
+
|
| 249 |
+
if not assignee_file_path:
|
| 250 |
+
# Debugging: log available files in the current directory
|
| 251 |
+
files_in_cwd = os.listdir(os.getcwd())
|
| 252 |
+
print(f"Files in current directory: {files_in_cwd}")
|
| 253 |
+
return default_assignees
|
| 254 |
+
|
| 255 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 256 |
assignees = []
|
| 257 |
+
with open(assignee_file_path, "r") as f:
|
| 258 |
+
content = f.read()
|
| 259 |
+
# Debug: Print the content of the file
|
| 260 |
+
print(f"Content of {assignee_file_path}: {content}")
|
| 261 |
+
|
| 262 |
+
lines = [line.strip() for line in content.split('\n') if line.strip()]
|
| 263 |
for line in lines:
|
| 264 |
if '-' in line:
|
| 265 |
name_part = line.split('-')[0].strip()
|
| 266 |
if ' ' in name_part:
|
| 267 |
assignees.append(name_part)
|
| 268 |
+
else:
|
| 269 |
+
# If there's no dash, just use the whole line if it has a space
|
| 270 |
+
if ' ' in line:
|
| 271 |
+
assignees.append(line)
|
| 272 |
|
| 273 |
+
# If we successfully parsed assignees, return them
|
| 274 |
+
if assignees:
|
| 275 |
+
return assignees
|
| 276 |
+
|
| 277 |
+
# If no assignees were extracted, return defaults
|
| 278 |
+
return default_assignees
|
| 279 |
+
except Exception as e:
|
| 280 |
+
print(f"Error loading assignees: {str(e)}")
|
| 281 |
return default_assignees
|
| 282 |
|
| 283 |
# Initialize session state ONLY ONCE
|