|
@@ -0,0 +1,172 @@
|
|
|
+
|
|
|
+import os
|
|
|
+import time
|
|
|
+import oss2
|
|
|
+import xml.etree.ElementTree as ET
|
|
|
+import shutil
|
|
|
+import docker
|
|
|
+import logging
|
|
|
+
|
|
|
+key1 = 'pjibot_delivery/'
|
|
|
+path1 = '/scenarios3/'
|
|
|
+path2 = '/mnt/disk001/dcl_data_process/src/python2/pjibot_delivery/'
|
|
|
+path3 = '/mnt/disk001/dcl_data_process/src/python2/pjibot_delivery/resource/'
|
|
|
+
|
|
|
+logging.basicConfig(filename=path2 + 'log/simulation.log', level=logging.INFO,
|
|
|
+ format='%(asctime)s - %(levelname)s - %(message)s')
|
|
|
+
|
|
|
+sleep_time = 60
|
|
|
+
|
|
|
+
|
|
|
+def move_xosc_before_simulation(root_path):
|
|
|
+ try:
|
|
|
+
|
|
|
+ xodr = 'thq_1116.xodr'
|
|
|
+ osgb = 'thq_1116.opt.osgb'
|
|
|
+
|
|
|
+ tree1 = ET.parse(root_path + 'scenario_orig.xosc')
|
|
|
+ root1 = tree1.getroot()
|
|
|
+ for node0 in root1:
|
|
|
+ if node0.tag == 'RoadNetwork':
|
|
|
+ for node1 in node0:
|
|
|
+
|
|
|
+ src_file_prefix = path3
|
|
|
+ if 'LogicFile' == node1.tag:
|
|
|
+ if xodr in node1.get('filepath'):
|
|
|
+ dst_file = root_path + xodr
|
|
|
+ shutil.copy(src_file_prefix + xodr, dst_file)
|
|
|
+ node1.set('filepath', dst_file)
|
|
|
+ if xodr in node1.get('filepath'):
|
|
|
+ dst_file = root_path + xodr
|
|
|
+ shutil.copy(src_file_prefix + xodr, dst_file)
|
|
|
+ node1.set('filepath', dst_file)
|
|
|
+ if xodr in node1.get('filepath'):
|
|
|
+ dst_file = root_path + xodr
|
|
|
+ shutil.copy(src_file_prefix + xodr, dst_file)
|
|
|
+ node1.set('filepath', dst_file)
|
|
|
+ if 'SceneGraphFile' == node1.tag:
|
|
|
+ if osgb in node1.get('filepath'):
|
|
|
+ dst_file = root_path + osgb
|
|
|
+ shutil.copy(src_file_prefix + osgb, dst_file)
|
|
|
+ node1.set('filepath', dst_file)
|
|
|
+ if osgb in node1.get('filepath'):
|
|
|
+ dst_file = root_path + osgb
|
|
|
+ shutil.copy(src_file_prefix + osgb, dst_file)
|
|
|
+ node1.set('filepath', dst_file)
|
|
|
+ if osgb in node1.get('filepath'):
|
|
|
+ dst_file = root_path + osgb
|
|
|
+ shutil.copy(src_file_prefix + osgb, dst_file)
|
|
|
+ node1.set('filepath', dst_file)
|
|
|
+ if node0.tag == 'Entities':
|
|
|
+ for node1 in node0:
|
|
|
+ if node1.get("name") == 'Ego':
|
|
|
+ for node2 in node1:
|
|
|
+ if node2.tag == 'Vehicle':
|
|
|
+ node2.set('name', 'Pji_Utility_Vehicle')
|
|
|
+ tree1.write(root_path + 'openx0.xosc')
|
|
|
+
|
|
|
+ except Exception as e:
|
|
|
+ logging.exception("修改xosc报错: %s" % str(e))
|
|
|
+
|
|
|
+
|
|
|
+def upload_simulation(parse_prefix, mp41):
|
|
|
+ try:
|
|
|
+ bucket.put_object_from_file(parse_prefix + 'scenario_orig.mp4', mp41)
|
|
|
+ logging.info('上传仿真视频到 %s' % parse_prefix + 'scenario_orig.mp4')
|
|
|
+ shutil.rmtree(path1)
|
|
|
+ except Exception as e:
|
|
|
+ logging.exception("上传视频报错 %s" % str(e))
|
|
|
+
|
|
|
+
|
|
|
+def simulation(parse_prefix, mp41):
|
|
|
+ try:
|
|
|
+ os.system("docker start vtd3")
|
|
|
+
|
|
|
+ client = docker.from_env()
|
|
|
+ while True:
|
|
|
+ time.sleep(5)
|
|
|
+
|
|
|
+ containers = client.containers.list()
|
|
|
+ run = False
|
|
|
+
|
|
|
+ for container in containers:
|
|
|
+ if 'vtd3' == container.name:
|
|
|
+ run = True
|
|
|
+ break
|
|
|
+ if not run:
|
|
|
+ break
|
|
|
+ time.sleep(5)
|
|
|
+ upload_simulation(parse_prefix, mp41)
|
|
|
+ except Exception as e:
|
|
|
+ logging.exception("生成仿真视频报错 %s" % str(e))
|
|
|
+
|
|
|
+
|
|
|
+def is_upload_completed(bucket, prefix):
|
|
|
+ target_number = str(prefix).split('_')[-1][:-1]
|
|
|
+ count = 0
|
|
|
+ for obj in oss2.ObjectIterator(bucket, prefix=prefix):
|
|
|
+ if obj.key != prefix:
|
|
|
+ count += 1
|
|
|
+ return int(count) == int(target_number)
|
|
|
+
|
|
|
+
|
|
|
+'''
|
|
|
+cname:http://open-bucket.oss.icvdc.com
|
|
|
+keyid:n8glvFGS25MrLY7j
|
|
|
+secret:xZ2Fozoarpfw0z28FUhtg8cu0yDc5d
|
|
|
+oss桶名: oss://open-bucket
|
|
|
+
|
|
|
+oss桶名: open-bucket
|
|
|
+内网endpoint: oss-cn-beijing-gqzl-d01-a.ops.gqzl-cloud.com
|
|
|
+'''
|
|
|
+
|
|
|
+if __name__ == '__main__':
|
|
|
+
|
|
|
+ auth = oss2.Auth('n8glvFGS25MrLY7j', 'xZ2Fozoarpfw0z28FUhtg8cu0yDc5d')
|
|
|
+ endpoint = 'oss-cn-beijing-gqzl-d01-a.ops.gqzl-cloud.com'
|
|
|
+ bucket = oss2.Bucket(auth, endpoint, 'open-bucket')
|
|
|
+ while True:
|
|
|
+ logging.info("开始新一轮扫描")
|
|
|
+ local_delete_list = []
|
|
|
+ oss_delete_list = []
|
|
|
+ prefix_list = []
|
|
|
+
|
|
|
+ all_prefix_set = set()
|
|
|
+ for obj1 in oss2.ObjectIterator(bucket, prefix=key1):
|
|
|
+
|
|
|
+ if 'data_parse' in str(obj1.key) and str(obj1.key).count('/') == 4:
|
|
|
+ all_prefix_set.add('/'.join(str(obj1.key).split('/')[:-1]) + '/')
|
|
|
+ for obj2_key in all_prefix_set:
|
|
|
+ xosc_done = False
|
|
|
+ mp4_done = False
|
|
|
+ for obj3 in oss2.ObjectIterator(bucket, prefix=obj2_key):
|
|
|
+ if '/scenario.xosc' in str(obj3.key):
|
|
|
+ xosc_done = True
|
|
|
+ if '/scenario_orig.mp4' in str(obj3.key):
|
|
|
+ mp4_done = True
|
|
|
+ if not xosc_done or mp4_done:
|
|
|
+ continue
|
|
|
+
|
|
|
+ logging.info("需要生成仿真视频: %s" % obj2_key)
|
|
|
+ parse_prefix_full = obj2_key
|
|
|
+ local_dir_full = path1 + parse_prefix_full
|
|
|
+ if not os.path.exists(local_dir_full):
|
|
|
+ os.makedirs(local_dir_full)
|
|
|
+
|
|
|
+ root_path1 = local_dir_full + 'orig/'
|
|
|
+ if not os.path.exists(root_path1):
|
|
|
+ os.makedirs(root_path1)
|
|
|
+
|
|
|
+ bucket.get_object_to_file(parse_prefix_full + 'simulation.xosc', root_path1 + 'scenario_orig.xosc')
|
|
|
+ local_delete_list.append(root_path1 + 'scenario_orig.xosc')
|
|
|
+ move_xosc_before_simulation(root_path1)
|
|
|
+ simulation(parse_prefix_full, root_path1 + 'simulation.mp4')
|
|
|
+
|
|
|
+
|
|
|
+ if len(local_delete_list) > 0:
|
|
|
+ for local_delete in local_delete_list:
|
|
|
+ try:
|
|
|
+ os.remove(local_delete)
|
|
|
+ except Exception as e:
|
|
|
+ logging.exception("删除本地临时文件报错: %s" % str(e))
|
|
|
+ time.sleep(sleep_time)
|