def run(which, expect): v = False cur_dir = os.getcwd() dest = os.path.join(cur_dir, f"out/regression-output/{which}") cwd = dtu.get_output_dir_for_test() if not os.path.exists(cwd): dtu.mkdirs_thread_safe(cwd) try: cmd = [ "rosrun", "easy_regression", "run", "--expect", expect, "--test", which, "-o", dest, "-c", "rmake", ] dtu.system_cmd_result(cwd, cmd, display_stdout=v, display_stderr=v, raise_on_error=True) finally: if False: shutil.rmtree(cwd)
def run_one(cmd): v = False cwd = dtu.get_output_dir_for_test() if not os.path.exists(cwd): dtu.mkdirs_thread_safe(cwd) dtu.write_str_to_file("config echo 1", os.path.join(cwd, ".compmake.rc")) try: dtu.system_cmd_result(cwd, cmd, display_stdout=v, display_stderr=v, raise_on_error=True) finally: pass
def go(self): extra = self.options.get_extra() if not extra: query = "*" else: if len(extra) > 1: msg = "Expected only one extra argument." raise dtu.DTUserError(msg) query = extra[0] db = self.get_easy_logs_db() logs = db.query(query) self.info(f"Found {len(logs)} logs.") outdir = self.options["outdir"] if outdir is None: outdir = "." msg = 'Option "--outdir" not passed. Will copy to current directory.' self.warn(msg) if not os.path.exists(outdir): dtu.mkdirs_thread_safe(outdir) for id_log, log in list(logs.items()): log = download_if_necessary(log) out = os.path.join(outdir, id_log + ".bag") if os.path.exists(out): print(out) continue try: filename = get_local_bag_file(log) shutil.copy(filename, out) print(out) except NotAvailableLocally: dtu.logger.error(f"No local file for {id_log}")
def d8n_make_video_from_bag( bag_filename: str, topic: str, out: str, t0: Optional[float] = None, t1: Optional[float] = None, ): """ Creates a video out of the topic in the bag. topic: the topic name (any image-like topic) out: an .mp4 file. Returns the name of the created file. raises NotEnoughFramesInSlice if there are less than 3 frames in slice Note that needs a bunch more dependencies to be installed. Until we fix the dependencies: sudo pip install SystemCmd==1.2 ros_node_utils==1.0 ConfTools==1.8 QuickApp==1.2.2 sudo apt-get install -y mplayer mencoder sudo add-apt-repository ppa:mc3man/trusty-media sudo apt-get update sudo apt-get install -y ffmpeg """ try: import procgraph_ros from procgraph import pg except ImportError: raise # pg -m procgraph_ros bag2mp4 --bag $bag --topic $topic --out $out stop_at = 10 min_messages = 5 actual_count, count, stopped_early = count_messages_in_slice( bag_filename, topic, t0, t1, stop_at=stop_at) msg = "Creating video for topic %r, which has %d messages " "in the entire log." % ( topic, count, ) logger.info(msg) if not stopped_early and (actual_count != count): msg = "However, the actual count in [%s, %s] is %s" % (t0, t1, actual_count) logger.info(msg) if actual_count < min_messages: msg = ("Topic %r has only %d messages in slice (%d total), too few" " to make a video (min: %s).\nFile: %s" % (topic, actual_count, count, min_messages, bag_filename)) msg += "\nt0: %s" % t0 msg += "\nt1: %s" % t1 bag = rosbag.Bag(bag_filename) msg += "\nstart: %s" % bag.get_start_time() msg += "\nend: %s" % bag.get_end_time() if actual_count == count: msg += "\n" + dtu.indent(get_summary_of_bag_messages(bag), " info: ") bag.close() raise NotEnoughFramesInSlice(msg) model = "bag2mp4_fixfps_limit" tmpdir = dtu.create_tmpdir() out_tmp = os.path.join(tmpdir, os.path.basename(out)) try: logger.debug("Writing temp file to %s" % out_tmp) logger.debug("(You can use mplayer to follow along.)") pg(model, config=dict(bag=bag_filename, topic=topic, out=out_tmp, t0=t0, t1=t1)) md = out_tmp + ".metadata.yaml" if os.path.exists(md): os.unlink(md) dn = os.path.dirname(out) if not os.path.exists(dn): dtu.mkdirs_thread_safe(dn) shutil.copyfile(out_tmp, out) logger.info("Created: %s" % out) info = out_tmp + ".info.yaml" if os.path.exists(info): os.unlink(info) return out finally: if os.path.exists(out_tmp): os.unlink(out_tmp) if os.path.exists(tmpdir): shutil.rmtree(tmpdir)
def _cwd(): cwd = dtu.get_output_dir_for_test() if not os.path.exists(cwd): dtu.mkdirs_thread_safe(cwd) return cwd