def write_files(*, session, path, operation_type): """ Writes the files associated with the operation_type to the path. Arguments: session (Session Object): Aquarium Session object path (String): the path to where the files will be written operation_type (OperationType): the operation type being written """ logging.info('Writing operation type %s', operation_type.name) get_associated_types(path=path, operation_type=operation_type) category_path = create_named_path(path, operation_type.category) makedirectory(category_path) path = create_named_path( category_path, operation_type.name, subdirectory='operation_types') makedirectory(path) code_names = all_component_names() for name in code_names: code_object = operation_type.code(name) if not code_object: logging.warning( 'Missing %s code for operation type %s -- creating file', operation_type.name, name) create_code_object( session=session, name=name, operation_type=operation_type ) code_object = operation_type.code(name) file_name = "{}.rb".format(name) try: code_component.write( path=path, file_name=file_name, code_object=code_object ) except OSError as error: logging.warning( 'Error %s writing file %s for operation type %s', error, file_name, operation_type.name) continue except UnicodeError as error: logging.warning( 'Encoding error %s writing file %s for operation type %s', error, file_name, operation_type.name) continue write_definition_json( os.path.join(path, 'definition.json'), operation_type )
def write_files(*, path, sample_type): """ Writes the files associated with the sample_type to the path. Arguments: path (String): the path to where the files will be written sample_type (ObjectType): the object type being written """ logging.info('writing sample type %s', sample_type.name) path = create_named_path(path, 'sample_types') makedirectory(path) sample_type_ser = { 'name': sample_type.name, 'description': sample_type.description, 'field_types': definition.field_type_list(sample_type.field_types) } name = simplename(sample_type_ser['name']) file_path = (os.path.join(path, "{}.json".format(name))) with open(file_path, 'w') as file: file.write(json.dumps(sample_type_ser, indent=2))
def create(*, session, object_type, path): """ Creates a new Object Type Type in Aquarium """ path = pathlib.PurePath(path).parts[0] path = create_named_path(path, 'object_types') try: data_dict = read(path=path, object_type=object_type) except FileNotFoundError: return # TODO: try except for File not Found Error obj_type = session.ObjectType.new( name=data_dict['name'], description=data_dict['description'], min=data_dict['min'], max=data_dict['max'], handler=data_dict['handler'], safety=data_dict['safety'], clean_up=data_dict['clean up'], data=data_dict['data'], vendor=data_dict['vendor'], unit=data_dict['unit'], cost=data_dict['cost'], release_method=data_dict['release method'], release_description=data_dict['release description'], image=data_dict['image'], prefix=data_dict['prefix'], rows=data_dict['rows'], columns=data_dict['columns'] ) obj_type.save() return obj_type
def write_files(*, path, library): """ Writes the files for the library to the path. Arguments: path (string): the path of the file to write library (Library): the library whose definition will be written """ logging.info('writing library %s', library.name) category_path = create_named_path(path, library.category) makedirectory(category_path) library_path = create_named_path( category_path, library.name, subdirectory="libraries") makedirectory(library_path) code_object = library.code("source") if not code_object: logging.warning( 'Ignored library %s missing library code', library.name) file_name = 'source.rb' try: code_component.write( path=library_path, file_name=file_name, code_object=code_object ) except OSError as error: logging.warning('Error %s writing file %s for library %s', error, file_name, library.name) except UnicodeError as error: logging.warning( 'Encoding error %s writing file %s for library %s', error, file_name, library.name) write_library_definition_json( os.path.join( library_path, 'definition.json' ), library)
def do_test(args): session = create_session(path=config_path(), name=args.name) path = os.path.normpath(args.directory) # have category, check for a library or operation type if args.category: category_path = create_named_path(path, args.category) if args.library: library.run_test(session=session, path=create_named_path(category_path, args.operation_type, subdirectory="libraries"), category=args.category, name=args.library, timeout=args.timeout) return if args.operation_type: operation_type.run_test(session=session, path=create_named_path( category_path, args.operation_type, subdirectory="operation_types"), category=args.category, name=args.operation_type, timeout=args.timeout) return category.run_tests(session=session, path=category_path, name=args.category, timeout=args.timeout) return if args.library or args.operation_type: logging.error( "To test a single operation type or library, you must enter a category" ) return instance.run_tests(session=session, path=path, timeout=args.timeout)
def create(*, session, sample_type, path): """ Creates a new Sample Type in Aquarium """ path = pathlib.PurePath(path).parts[0] path = create_named_path(path, 'sample_types') try: data_dict = read(path=path, sample_type=sample_type) except FileNotFoundError: return smpl_type = session.SampleType.new(name=data_dict['name'], description=data_dict['description']) smpl_type.save() return smpl_type
def do_push(args): session = create_session(path=config_path(), name=args.name) path = os.path.normpath(args.directory) if args.force and not args.operation_type: logging.warning( 'Force Flag only operates with a single Operation Type') return # TODO: get category from the definition file if args.category: category_path = create_named_path(path, args.category) if args.library: library.push(session=session, path=create_named_path(category_path, args.library, subdirectory='libraries')) return if args.operation_type: operation_type.push(session=session, path=create_named_path( category_path, args.operation_type, subdirectory='operation_types'), force=args.force) return category.push(session=session, path=category_path) return if args.library or args.operation_type: logging.error( 'To push a single operation type or library, you must enter a category' ) return instance.push(session=session, path=path)
def write_files(*, path, object_type): """ Writes the files associated with the object_type to the path. Arguments: path (String): the path to where the files will be written object_type (ObjectType): the object type being written """ logging.info('writing object type %s', object_type.name) path = create_named_path(path, 'object_types') makedirectory(path) object_type_ser = { "name": object_type.name, "description": object_type.description, "min": object_type.min, "max": object_type.max, "handler": object_type.handler, "safety": object_type.safety, "clean up": object_type.cleanup, "data": object_type.data, "vendor": object_type.vendor, "unit": object_type.unit, "cost": object_type.cost, "release method": object_type.release_method, "release description": object_type.release_description, "image": object_type.image, "prefix": object_type.prefix, "rows": object_type.rows, "columns": object_type.columns } name = simplename(object_type_ser['name']) file_path = (os.path.join(path, "{}.json".format(name))) with open(file_path, 'w') as file: file.write(json.dumps(object_type_ser, indent=2))