-
Notifications
You must be signed in to change notification settings - Fork 0
finish example file_transfer #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| target | ||
| target | ||
| example/*/run |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import json | ||
| import base64 | ||
|
|
||
| with open("param.json",'r') as f: | ||
| param = json.load(f) | ||
| file_name = base64.b64decode(param["param"]) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ? |
||
| with open("file_name",'w') as f: | ||
| f.write(file_name.decode()) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| hello, world! |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| [file_transfer] | ||
| workdir = "$PLAYBOOK_TRANSFER/run" | ||
| name = "file_transfer" | ||
|
|
||
| [file_transfer.roles] | ||
| [file_transfer.roles.sender] | ||
| max_num = 1 | ||
| [file_transfer.roles.sender.playbook] | ||
| workdir = "$PLAYBOOK_TRANSFER/run/{{user_id[..8]}}/{{task_id[..8]}}" | ||
|
|
||
| [[file_transfer.roles.sender.playbook.steps]] | ||
| step_name = "convert_param" | ||
| process = "python3 $PLAYBOOK_TRANSFER/convert_param.py" | ||
| process_wait = "convert_param" | ||
| check_exit_code = 0 | ||
|
|
||
| [[file_transfer.roles.sender.playbook.steps]] | ||
| step_name = "load_file" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reorganize? ln? |
||
| process = "cp $PLAYBOOK_TRANSFER/$(cat file_name) send_file" | ||
| process_wait = "load_file" | ||
| check_exit_code = 0 | ||
|
|
||
| [[file_transfer.roles.sender.playbook.steps]] | ||
| send_variable = "file_content" | ||
| file = "send_file" | ||
| to_role = "receiver" | ||
|
|
||
| [[file_transfer.roles.sender.playbook.steps]] | ||
| step_name = "remove_tmp" | ||
| process = "rm send_file file_name" | ||
| process_wait = "remove_tmp" | ||
| check_exit_code = 0 | ||
|
|
||
| [file_transfer.roles.receiver] | ||
| [file_transfer.roles.receiver.playbook] | ||
| workdir = "$PLAYBOOK_TRANSFER/run/{{user_id[..8]}}/{{task_id[..8]}}" | ||
|
|
||
| [[file_transfer.roles.receiver.playbook.steps]] | ||
| step_name = "convert_param" | ||
| process = "python3 $PLAYBOOK_TRANSFER/convert_param.py" | ||
| process_wait = "convert_param" | ||
| check_exit_code = 0 | ||
|
|
||
| [[file_transfer.roles.receiver.playbook.steps]] | ||
| recv_variable = "file_content" | ||
| from_role = "sender" | ||
| file = "receive_file" | ||
| index = 0 | ||
|
|
||
| [[file_transfer.roles.receiver.playbook.steps]] | ||
| step_name = "store_file" | ||
| process = "cp receive_file $(cat file_name)" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mv |
||
| process_wait = "store_file" | ||
| check_exit_code = 0 | ||
|
|
||
| [[file_transfer.roles.receiver.playbook.steps]] | ||
| create_entry = "example:file_transfer:receive_file_content" | ||
| file = "receive_file" | ||
|
|
||
| [[file_transfer.roles.receiver.playbook.steps]] | ||
| step_name = "remove_tmp" | ||
| process = "rm receive_file file_name" | ||
| process_wait = "remove_tmp" | ||
| check_exit_code = 0 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import colink as CL | ||
| import subprocess | ||
| from typing import List | ||
| import os | ||
|
|
||
| if __name__ == "__main__": | ||
| colink_home = os.environ["COLINK_HOME"] | ||
| assert colink_home != None, "Please set COLINK_HOME environment variable" | ||
| ir = CL.InstantRegistry() | ||
| cls:List[CL.CoLink] = [] | ||
| roles = ["sender", "receiver"] | ||
| participants = [] | ||
| threads = [] | ||
| for i in range(2): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ? |
||
| cl:CL.CoLink = CL.InstantServer().get_colink().switch_to_generated_user() | ||
| threads.append(subprocess.Popen( | ||
| [f"{colink_home}/colink-playbook","--addr",cl.core_addr,"--jwt",cl.jwt], | ||
| env={ | ||
| "PLAYBOOK_TRANSFER": os.path.abspath("./example/file_transfer"), | ||
| "COLINK_PLAYBOOK_CONFIG": os.path.abspath("./example/file_transfer/playbook.toml")}, | ||
| )) | ||
| participants.append(CL.Participant(user_id=cl.get_user_id(), role=roles[i])) | ||
| cls.append(cl) | ||
| task_id = cls[0].run_task("file_transfer", "example.txt", participants, True) | ||
| cls[1].wait_task(task_id) | ||
| recv_file = cls[1].read_entry("example:file_transfer:receive_file_content") | ||
| print("Received file: ", recv_file) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. review naming? |
||
| for t in threads: | ||
| t:subprocess.Popen | ||
| t.terminate() | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
python -c ?