-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8f1d6c1
commit 099abb4
Showing
7 changed files
with
88 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# @package handlers.preprocess.workspace_ticket | ||
|
||
_target_: moai.serve.handlers.workspace_ticket.WorkSpaceTicketHandler | ||
working_dir: ??? | ||
json_key: 'workspace_run' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# @package handlers.postprocess._name_ | ||
_target_: moai.serve.handlers.CleanUp | ||
dirs: ??? | ||
# @package handlers.postprocess.cleanup | ||
_target_: moai.serve.handlers.cleanup.CleanUp | ||
dirs: null | ||
json_key: 'workspace_run' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import logging | ||
import os | ||
import typing | ||
from collections.abc import Callable | ||
|
||
log = logging.getLogger(__name__) | ||
log.setLevel(logging.DEBUG) | ||
|
||
import tempfile | ||
|
||
|
||
class WorkSpaceTicketHandler(Callable): | ||
def __init__( | ||
self, | ||
working_dir: str, # aboslute path to working dir | ||
json_key: str = "workspace_run", | ||
): | ||
""" | ||
Responsible for creating a working dir and adding its corresponfing path to json data | ||
""" | ||
self.working_dir = working_dir | ||
self.json_key = json_key | ||
|
||
if not os.path.isabs(working_dir): | ||
log.error(f"working_dir ({working_dir}) is not absolute") | ||
os.makedirs(self.working_dir, exist_ok=True) | ||
|
||
def __call__( | ||
self, json: typing.Mapping[str, typing.Any], void: typing.Any | ||
) -> typing.Any: | ||
generated_dir_path = tempfile.mkdtemp(dir=self.working_dir) | ||
json[self.json_key] = generated_dir_path | ||
return {} # generated_dir_path | ||
|
||
|
||
if __name__ == "__main__": | ||
import os | ||
import platform | ||
|
||
if platform.system() == "Windows": | ||
working_dir = f"C:/Users/{os.environ['USERNAME']}/AppData/Local/Temp" | ||
assert os.path.isabs(working_dir) | ||
print(working_dir) | ||
|
||
data = {} | ||
ticket_call = WorkSpaceTicketHandler(working_dir) | ||
tmp_path = ticket_call(data, None) | ||
print(tmp_path) | ||
print(data) |