def resolve_scenario_yaml(scenario_file): """If the file doesn't exist, checks if it exists relative to the package.'""" # Get the package path pkg_root = get_package_root() scenario_file = pathlib.Path(scenario_file) if not scenario_file.exists() or not scenario_file.is_file(): if not scenario_file.is_absolute(): scenario_folder = pkg_root / "scenarios" possible_paths = [ pkg_root / scenario_file, # only scenarios/filename.yaml is passed scenario_folder / scenario_file, # only filename.yaml is passed ] valid_paths = [p for p in possible_paths if p.is_file()] if valid_paths: if len(valid_paths) > 1: raise IOError( "Could not automatically resolve path '{}'. Multiple paths available: {}" .format( scenario_file, " ".join( map(lambda x: "\n\t- " + str(x), valid_paths)))) return valid_paths[0].resolve( ) # if only one of the paths is valid elif scenario_folder.exists(): raise IOError( "Scenario '{}' does not exist please provide a correct path, example paths: {}" .format( scenario_file, " ".join( map(lambda x: "\n\t- " + str(x), scenario_folder.glob("*.yaml"))))) return scenario_file # could not get a valid path and scenario folder not found
def __init__(self, config=None, collection="default", uri=None, db_name="topic_store", verbose=False): """ Args: config: Path to MongoDB config file that a URI can be inferred from collection: The collection to manage uri: URI overload, if passed will attempt to connect directly and config not used """ self.verbose = verbose self.uri = uri if self.uri is None: if config in ["topic_store", "auto", "default"] or config is None: config = get_package_root( ) / "config" / "default_db_config.yaml" self.uri = self.uri_from_mongo_config(config) self._log("Setting URI to '{}'".format(self.uri)) self.parser = MongoDBParser( ) # Adds support for unicode to python str etc self.reverse_parser = MongoDBReverseParser( ) # Adds support for unicode to python str etc self.name = db_name self.collection_name = collection self.client = pymongo.MongoClient(self.uri) self._db = self.client[self.name] self._fs = gridfs.GridFS(self._db, collection=self.collection_name) self.collection = self._db[self.collection_name] self._log("DB name: '{}', Collection name: '{}'".format( self.name, self.collection_name))
def test_scenarios(self): if not rospy.get_node_uri(): rospy.init_node("topic_store_tests") scenario_file = get_package_root( ) / "scenarios" / "default_config.yaml" scenario = ScenarioFileParser(scenario_file) print("All scenario parser tests passed!")
def run_scenario(): rospy.init_node("scenario_runner_node", anonymous=True) # Get the package path pkg_root = get_package_root() # Get parameters stabilise_time = rospy.get_param('~stabilise_time', 0) scenario_file = rospy.get_param('~scenario_file', str(pathlib.Path(pkg_root) / "scenarios/default_config.yaml")) data_logger = ScenarioRunner(scenario_file, stabilise_time)
def __init__(self, debug=False): if not debug: raise NotImplementedError("Server is not yet implemented. Please call start_database.launch.") import subprocess import pathlib import rospy import os pkg_root = get_package_root() script_path = pkg_root / "docker/docker_compose_up_safe.sh" db_default = pathlib.Path(os.path.expanduser("~/.ros/topic_store/database")) rospy.on_shutdown(self._on_shutdown) self.process = subprocess.Popen(['bash', script_path], env={"MONGO_DB_PATH": db_default})
def __init__(self, config=None, collection="default", uri=None, db_name=None, verbose=False, chunk_size=None, use_grid_fs=False): """ Args: config: Path to MongoDB config file that a URI can be inferred from collection: The collection to manage uri: URI overload, if passed will attempt to connect directly and config not used """ if db_name is None: db_name = "topic_store" self.verbose = verbose self.uri = uri if self.uri is None: if config in ["topic_store", "auto", "default"] or config is None: config = get_package_root( ) / "config" / "default_db_config.yaml" self.uri = self.uri_from_mongo_config(config) self._log("Setting URI to '{}'".format(self.uri)) self.parser = MongoDBParser( ) # Adds support for unicode to python str etc self.reverse_parser = MongoDBReverseParser( ) # Adds support for unicode to python str etc self.name = db_name self.collection_name = collection self.client = pymongo.MongoClient(self.uri) self._db = self.client[self.name] self._use_grid_fs = use_grid_fs if self._use_grid_fs: self._fs = gridfs.GridFS(self._db, collection=self.collection_name) self._db[self.collection_name + "." + "chunks"].create_index( [('files_id', pymongo.ASCENDING), ('n', pymongo.ASCENDING)], unique=True) self._db[self.collection_name + "." + "files"].create_index([ ('filename', pymongo.ASCENDING), ('uploadDate', pymongo.ASCENDING) ]) self.chunk_size = 16000 * 1024 if chunk_size is None else chunk_size self.collection = self._db[self.collection_name] self._log("DB name: '{}', Collection name: '{}'".format( self.name, self.collection_name))