auto task switch for work desktop (default)

This commit is contained in:
buenosairesam
2025-05-13 05:00:46 -03:00
parent 7995040c82
commit 7a75d1caae
5 changed files with 26 additions and 7 deletions

1
.gitignore vendored
View File

@@ -3,3 +3,4 @@ __pycache__
nohup.out nohup.out
dm.out dm.out
dm.err dm.err
sample_task_file

View File

@@ -9,7 +9,13 @@ logging.basicConfig(
format="%(asctime)s %(levelname)-8s [%(filename)s:%(lineno)d] %(message)s", format="%(asctime)s %(levelname)-8s [%(filename)s:%(lineno)d] %(message)s",
datefmt="%Y-%m-%d %H:%M:%S", datefmt="%Y-%m-%d %H:%M:%S",
) )
# 2) Get your modules logger and bump it to DEBUG
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
# 3) Silence pymongo (and any other libs you find chatty)
logging.getLogger("pymongo").setLevel(logging.WARNING)
# MongoDB configuration # MongoDB configuration
client = MongoClient() client = MongoClient()

View File

@@ -64,9 +64,14 @@ while True:
last_doc = switches.find_one(sort=[("_id", -1)]) last_doc = switches.find_one(sort=[("_id", -1)])
# work workflow # work workflow
if current_workspace in work_desktops.keys(): if current_workspace in work_desktops.keys():
pass work_states = state.retrieve_work_state()
current_work_task = work_states[work_desktops[current_workspace]]
logger.debug(f"current_work_task: {current_work_task}")
if current_task != current_work_task:
state.save("current", task=current_work_task)
task.db_to_file_as_is(None)
current_task = current_work_task
# regular flow # regular flow
if ( if (

View File

@@ -45,3 +45,7 @@ def init_work_state(wd: dict):
}, },
} }
) )
def retrieve_work_state():
return states.find_one({"_id": "work"})

View File

@@ -83,6 +83,9 @@ def format_task_line(
def db_to_file_as_is(filepath: str): def db_to_file_as_is(filepath: str):
"""Write tasks from MongoDB to file exactly as they were read.""" """Write tasks from MongoDB to file exactly as they were read."""
if filepath is None:
filepath = task_file
current_task = state.retrieve("current").get("task") current_task = state.retrieve("current").get("task")
all_tasks = list(tasks.find()) all_tasks = list(tasks.find())
@@ -141,12 +144,12 @@ def extract(line: str) -> Optional[str]:
return None return None
def read_and_extract(file_path: str) -> Optional[str]: def read_and_extract(filepath: str) -> Optional[str]:
"""Read file and update state if current task is found.""" """Read file and update state if current task is found."""
if file_path is None: if filepath is None:
file_path = task_file filepath = task_file
with open(file_path, "r") as file: with open(filepath, "r") as file:
for line in file: for line in file:
task_id = extract(line) task_id = extract(line)
if task_id: if task_id: