Пример #1
0
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))
Пример #2
0
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
    )
Пример #3
0
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)
Пример #4
0
def add_config(*, path, key, login, password, url):
    """
    Adds the given configuration information to the secrets file in the config
    directory specified by the path.
    """
    makedirectory(path)
    file_path = config_file_path(path)
    config = get_config(file_path)

    config['instances'][key] = {
        'login': login,
        'password': password,
        'aquarium_url': url
    }

    with open(file_path, 'w') as file:
        file.write(json.dumps(config, indent=2))

    logging.info("New Configuration Added. Current Configuations:")
    show_config(path=path)
Пример #5
0
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))