Eason Lu commited on
Commit
317ffc4
·
1 Parent(s): 00ca03a

modify local entry

Browse files

Former-commit-id: a70affcb0bbc40e19d012e7d1103e438bf0e6d3b

Files changed (1) hide show
  1. entries/run.py +10 -16
entries/run.py CHANGED
@@ -8,6 +8,7 @@ import os
8
  from pathlib import Path
9
  from datetime import datetime
10
  import shutil
 
11
 
12
  def parse_args():
13
  parser = argparse.ArgumentParser()
@@ -17,44 +18,40 @@ def parse_args():
17
  parser.add_argument("--srt_file", help="srt file input path here", default=None, type=str, required=False)
18
  parser.add_argument("--continue", help="task_id that need to continue", default=None, type=str, required=False) # need implement
19
  parser.add_argument("--launch_cfg", help="launch config path", default='./configs/local_launch.yaml', type=str, required=False)
 
20
  args = parser.parse_args()
21
 
22
  return args
23
 
24
  if __name__ == "__main__":
 
25
  args = parse_args()
26
  launch_cfg = load(open(args.launch_cfg), Loader=Loader)
 
27
 
28
  # initialize dir
29
  local_dir = Path(launch_cfg['local_dump'])
30
-
31
- # initialize task queue
32
  if not local_dir.exists():
33
  local_dir.mkdir(parents=False, exist_ok=False)
34
- f = open(local_dir.joinpath("task_queue.yaml"), "w")
35
- f.write("Task Queue: []\n")
36
- f.close()
37
 
38
  # get task id
39
- tasks_queue = load(open(local_dir.joinpath("task_queue.yaml")), Loader = Loader)
40
- task_list = tasks_queue['Task Queue']
41
- task_id = len(task_list)
42
 
43
  # create locak dir for the task
44
  task_dir = local_dir.joinpath(f"task_{task_id}")
45
  task_dir.mkdir(parents=False, exist_ok=False)
46
  task_dir.joinpath("results").mkdir(parents=False, exist_ok=False)
47
  task_dir.joinpath("logs").mkdir(parents=False, exist_ok=False)
48
- f = open(task_dir.joinpath("task_info.yaml"), "w")
49
- f.write(f"task_id: {task_id}")
50
- f.close()
51
 
 
52
  logging.basicConfig(level=logging.INFO, handlers=[
53
  logging.FileHandler(
54
- "{}/{}_{}.log".format(task_dir.joinpath("logs"), f"task_{task_id}", datetime.now().strftime("%m%d%Y_%H%M%S")),
55
  'w', encoding='utf-8')])
56
 
57
- # task create
 
 
58
  if args.link is not None:
59
  try:
60
  task = Task.fromYoutubeLink(args.link, task_id, launch_cfg)
@@ -63,9 +60,6 @@ if __name__ == "__main__":
63
  raise RuntimeError("failed to create task from youtube link")
64
 
65
  # add task to the status queue
66
- task_list.append({"id": task_id, "status": "created", "resource_status:": "local"})
67
- stream = open(local_dir.joinpath("task_queue.yaml"), "w")
68
- dump(tasks_queue, stream)
69
  task.run_pipeline()
70
 
71
 
 
8
  from pathlib import Path
9
  from datetime import datetime
10
  import shutil
11
+ from uuid import uuid4
12
 
13
  def parse_args():
14
  parser = argparse.ArgumentParser()
 
18
  parser.add_argument("--srt_file", help="srt file input path here", default=None, type=str, required=False)
19
  parser.add_argument("--continue", help="task_id that need to continue", default=None, type=str, required=False) # need implement
20
  parser.add_argument("--launch_cfg", help="launch config path", default='./configs/local_launch.yaml', type=str, required=False)
21
+ # task config
22
  args = parser.parse_args()
23
 
24
  return args
25
 
26
  if __name__ == "__main__":
27
+ # read args and configs
28
  args = parse_args()
29
  launch_cfg = load(open(args.launch_cfg), Loader=Loader)
30
+ # TODO: task config
31
 
32
  # initialize dir
33
  local_dir = Path(launch_cfg['local_dump'])
 
 
34
  if not local_dir.exists():
35
  local_dir.mkdir(parents=False, exist_ok=False)
 
 
 
36
 
37
  # get task id
38
+ task_id = str(uuid4())
 
 
39
 
40
  # create locak dir for the task
41
  task_dir = local_dir.joinpath(f"task_{task_id}")
42
  task_dir.mkdir(parents=False, exist_ok=False)
43
  task_dir.joinpath("results").mkdir(parents=False, exist_ok=False)
44
  task_dir.joinpath("logs").mkdir(parents=False, exist_ok=False)
 
 
 
45
 
46
+ # logging
47
  logging.basicConfig(level=logging.INFO, handlers=[
48
  logging.FileHandler(
49
+ "{}/{}_{}.log".format(task_dir, f"task_{task_id}", datetime.now().strftime("%m%d%Y_%H%M%S")),
50
  'w', encoding='utf-8')])
51
 
52
+ # TODO: write task info into log
53
+
54
+ # Task create
55
  if args.link is not None:
56
  try:
57
  task = Task.fromYoutubeLink(args.link, task_id, launch_cfg)
 
60
  raise RuntimeError("failed to create task from youtube link")
61
 
62
  # add task to the status queue
 
 
 
63
  task.run_pipeline()
64
 
65