moved config. saved a workable state

This commit is contained in:
buenosairesam
2025-05-13 04:23:40 -03:00
parent f531be7158
commit 7995040c82
4 changed files with 102 additions and 62 deletions

View File

@@ -4,11 +4,7 @@ from typing import Optional
import state
from bson import ObjectId
from pymongo import MongoClient
client = MongoClient()
db = client.deskmeter
tasks = db.task
from config import logger, tasks
task_file = "/home/mariano/wdir/def/deskmeter/dmapp/dmcore/sample_task_file"
@@ -16,14 +12,13 @@ task_file = "/home/mariano/wdir/def/deskmeter/dmapp/dmcore/sample_task_file"
def parse_line(line: str) -> tuple[Optional[str], Optional[str]]:
"""Parse a task line to extract task name and ID."""
line = line.strip()
if not line:
return None, None
# Split by | and check if we have an ID part
parts = line.split("|")
if len(parts) > 1:
task_name = parts[0].strip()
# Take everything after | and clean it up
task_id = parts[1].split()[0].strip()
return task_name, task_id
@@ -64,6 +59,15 @@ def file_to_db(filepath: str):
seen_paths.add(full_path)
tasks.createIndex(
{"path": 1},
{
name: "idx_tasks_path_ci",
background: true,
collation: {locale: "es", strength: 1},
},
)
def format_task_line(
path_parts: list, indent_level: int, task_id: str, current_task: str
@@ -79,7 +83,7 @@ def format_task_line(
def db_to_file_as_is(filepath: str):
"""Write tasks from MongoDB to file exactly as they were read."""
current_task = state.get_current_task()
current_task = state.retrieve("current").get("task")
all_tasks = list(tasks.find())
with open(filepath, "w") as f:
@@ -95,9 +99,13 @@ def db_to_file_as_is(filepath: str):
f.write(f"{line}\n")
def get_all_tasks(prefix):
return list(tasks.find({"path": {"$ne": ""}}).sort("path", 1))
def db_to_file_consolidated(filepath: str):
"""Write tasks from MongoDB to file as a consolidated tree."""
current_task = state.get_current_task()
current_task = state.retrieve("current").get("task")
all_tasks = list(tasks.find({"path": {"$ne": ""}}).sort("path", 1))
with open(filepath, "w") as f:
@@ -128,15 +136,15 @@ def extract(line: str) -> Optional[str]:
# Extract everything between | and * and strip spaces
id_part = line[pipe_index + 1 : -1].strip()
if len(id_part) == 8:
state.update_current_task(id_part)
state.save("current", task=id_part)
return id_part
return None
def read_and_extract(file_path: str) -> Optional[str]:
"""Read file and update state if current task is found."""
if not Path(file_path).exists():
return None
if file_path is None:
file_path = task_file
with open(file_path, "r") as file:
for line in file: