def proto_refactor(proto_filename, namespace, namespace_path):
    """This method refactors a Protobuf file to import from a namespace
    that will map to the desired python package structure. It also ensures
    that the syntax is set to "proto2", since protoc complains without it.

    Args:
        proto_filename (str): the protobuf filename to be refactored
        namespace (str): the desired package name (i.e. "dropsonde.py2")
        namespace_path (str): the desired path corresponding to the package
                              name (i.e. "dropsonde/py2")
    """
    with open(proto_filename) as f:
        data = f.read()
        if not re.search('syntax = "proto2"', data):
            insert_syntax = 'syntax = "proto2";\n'
            data = insert_syntax + data
        substitution = 'import "{}/\\1";'.format(namespace_path)
        data = re.sub('import\s+"([^"]+\.proto)"\s*;', substitution, data)
        return data
This method refactors a Protobuf file to import from a namespace
    that will map to the desired python package structure. It also ensures
    that the syntax is set to "proto2", since protoc complains without it.

    Args:
        proto_filename (str): the protobuf filename to be refactored
        namespace (str): the desired package name (i.e. "dropsonde.py2")
        namespace_path (str): the desired path corresponding to the package
                              name (i.e. "dropsonde/py2")