def walk_directory(path): for dir_name in os.listdir(path): dir_name_path = os.path.join(path, dir_name) if os.path.isdir(dir_name_path): package = get_package(dir_name_path) if package is not None: if lang == "go": file_name = go_helper.convert_to_go_package(package) package_mappings.append( [file_name, (file_name + ".proto")]) else: file_name = package package_mappings.append( [file_name, (file_name + ".proto")]) package_file_path = os.path.join(tmp_path, file_name + ".proto") if lang == "go": package_directory = os.path.dirname(package_file_path) compile_helper.mkdir_p(package_directory) with open(package_file_path, 'a') as package_file: walk_files(package_file, dir_name_path, package) created_packages.append(package) walk_directory(dir_name_path)
def walk_directory(path): for dir_name in os.listdir(path): dir_name_path = os.path.join(path, dir_name) if os.path.isdir(dir_name_path): package = get_package(dir_name_path) if package is not None: if lang == "go": file_name = go_helper.convert_to_go_package(package) package_mappings.append([file_name, (file_name + ".proto")]) else: file_name = package package_mappings.append([file_name, (file_name + ".proto")]) package_file_path = os.path.join(tmp_path, file_name + ".proto") if lang == "go": package_directory = os.path.dirname(package_file_path) compile_helper.mkdir_p(package_directory) with open(package_file_path, 'a') as package_file: walk_files(package_file, dir_name_path, package) created_packages.append(package) walk_directory(dir_name_path)
def walk_files(main_file, path, package, imports=None): if imports is None: imports = [] if not desc_file and package == "POGOProtos": print("Can't compile..") print("File: '%s'" % path) print("Please place the file in 'src/POGOProtos/' in a sub-directory.") exit() main_file.write('syntax = "proto3";\n') short_package_name = str.split(package, '.')[-1].lower() main_file.write('package %s;\n\n' % package) if lang == "go": package = go_helper.convert_to_go_package(package) main_file.write('option go_package = "%s";\n' % go_package) if java_multiple_files: main_file.write('option java_multiple_files = true;\n') messages = "" for file_name in os.listdir(path): file_name_path = os.path.join(path, file_name) if file_name_path.endswith(".proto") and os.path.isfile(file_name_path): with open(file_name_path, 'r') as proto_file: is_header = True for proto_line in proto_file.readlines(): if proto_line.startswith("message") or proto_line.startswith("enum"): is_header = False if is_header: if proto_line.startswith("import"): import_from_package_re = re.search('import (public )?"(.*?)(\/)?([a-zA-Z0-9]+\.proto)";', proto_line) if import_from_package_re is None: print("Can't compile..") print("File: '%s'" % file_name_path) print("Bad import line: '%s'" % proto_line) exit() import_from_package = import_from_package_re.group(2).replace("/", ".") if lang == "go": import_from_package = go_helper.convert_to_go_package(import_from_package) if import_from_package not in imports: imports.append(import_from_package) if not is_header: messages += proto_line if proto_line == "}": messages += "\n" for package_import in imports: if package_import != package: main_file.write('import public "%s.proto";\n' % package_import) if len(imports) is not 0: main_file.write('\n') main_file.writelines(messages)