def load_data(self, file=None): '''loads all the files listed in "source_data:" from metadata.yaml''' if self.data_loaded == True: return #don't do it again if not file: catalog = getattr(self, 'source_data') else: catalog = [file] for x in catalog: if isinstance(x, File): self.overlay(x.load()) else: self.overlay(load(open(os.path.join(self.path(), x)))) #merge data from entire catalog into package self.data_loaded = True
def load_metadata(name): '''returns a package loaded from the filesystem input should be something like "f-16" or "human-exoskeleton-1.0" this only loads the metadata and is safe if you haven't actually downloaded the entire package''' if not check_unix_name(name): return None __lame_asserts__() assert os.access(settings.paths['package_dir'], os.F_OK), str(package_path)+": skdb package not found or unreadable" #must have the required files assert package_file(name, "metadata.yaml") loaded_package = load(package_file(name, "metadata.yaml")) return loaded_package
def load_metadata(name): '''returns a package loaded from the filesystem input should be something like "f-16" or "human-exoskeleton-1.0" this only loads the metadata and is safe if you haven't actually downloaded the entire package''' if not check_unix_name(name): return None __lame_asserts__() assert os.access( settings.paths['package_dir'], os.F_OK), str(package_path) + ": skdb package not found or unreadable" #must have the required files assert package_file(name, "metadata.yaml") loaded_package = load(package_file(name, "metadata.yaml")) return loaded_package
def load_data(self, file=None): '''loads all the files listed in "source_data:" from metadata.yaml''' if self.data_loaded == True: return #don't do it again if not file: catalog = getattr(self, 'source_data') else: catalog = [file] for x in catalog: if isinstance(x, File): self.overlay(x.load()) else: self.overlay(load(open(os.path.join( self.path(), x)))) #merge data from entire catalog into package self.data_loaded = True
def __load_package__(package_name, data=True): '''loads a package. call the constructor instead.''' __lame_asserts__() package_path = os.path.join(settings.paths["package_dir"],package_name) assert os.access(settings.paths['package_dir'], os.F_OK), str(package_path)+": skdb package not found or unreadable" #must have the required files required_files = ["metadata.yaml"] if data: required_files.append("data.yaml") for file in required_files: assert os.access(os.path.join(settings.package_path(package_name), file), os.F_OK) #check if present loaded_package = load(open(os.path.join(settings.package_path(package_name), "metadata.yaml"),"r")) loaded_package.package_path = package_path loaded_package.import_package_classes() if data: loaded_package.load_data() return loaded_package
def load_package(name): '''returns a package loaded from the filesystem input should be something like "f-16" or "human-exoskeleton-1.0" see settings.paths['package_dir']''' if not check_unix_name(name): #fail even if asserts are turned off return None __lame_asserts__() package_path = os.path.join(settings.paths["package_dir"],name) assert os.access(settings.paths['package_dir'], os.F_OK), str(package_path)+": skdb package not found or unreadable" #must have the required files required_files = ["metadata.yaml", "data.yaml"] for file in required_files: assert package_file(name, file) #just check if present loaded_package = load(package_file(name, 'metadata.yaml')) loaded_package.package_path = package_path loaded_package.import_package_classes() #import_package_classes(loaded_package, package_path) return loaded_package
def load_package(name): '''returns a package loaded from the filesystem input should be something like "f-16" or "human-exoskeleton-1.0" see settings.paths['package_dir']''' if not check_unix_name(name): #fail even if asserts are turned off return None __lame_asserts__() package_path = os.path.join(settings.paths["package_dir"], name) assert os.access( settings.paths['package_dir'], os.F_OK), str(package_path) + ": skdb package not found or unreadable" #must have the required files required_files = ["metadata.yaml", "data.yaml"] for file in required_files: assert package_file(name, file) #just check if present loaded_package = load(package_file(name, 'metadata.yaml')) loaded_package.package_path = package_path loaded_package.import_package_classes() #import_package_classes(loaded_package, package_path) return loaded_package
def __load_package__(package_name, data=True): '''loads a package. call the constructor instead.''' __lame_asserts__() package_path = os.path.join(settings.paths["package_dir"], package_name) assert os.access( settings.paths['package_dir'], os.F_OK ), str(package_path) + ": skdb package not found or unreadable" #must have the required files required_files = ["metadata.yaml"] if data: required_files.append("data.yaml") for file in required_files: assert os.access( os.path.join(settings.package_path(package_name), file), os.F_OK) #check if present loaded_package = load( open( os.path.join(settings.package_path(package_name), "metadata.yaml"), "r")) loaded_package.package_path = package_path loaded_package.import_package_classes() if data: loaded_package.load_data() return loaded_package
def main(): #basic self-test demo load_package('screw') package = load(open('tags.yaml')) print dump(package)