mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-02 20:15:34 +00:00
sharing namespace_dir and the namespace string methods
This commit is contained in:
@@ -642,26 +642,19 @@ class PythonGenerator : public BaseGenerator {
|
||||
bool needs_imports) {
|
||||
if (!classcode.length()) return true;
|
||||
|
||||
std::string namespace_name;
|
||||
std::string namespace_dir = path_;
|
||||
auto &namespaces = parser_.namespaces_.back()->components;
|
||||
for (auto it = namespaces.begin(); it != namespaces.end(); ++it) {
|
||||
if (namespace_name.length()) {
|
||||
namespace_name += ".";
|
||||
namespace_dir += kPathSeparator;
|
||||
}
|
||||
namespace_name = *it;
|
||||
if (it != namespaces.begin()) namespace_dir += kPathSeparator;
|
||||
namespace_dir += *it;
|
||||
EnsureDirExists(namespace_dir.c_str());
|
||||
|
||||
std::string init_py_filename = namespace_dir + "/__init__.py";
|
||||
SaveFile(init_py_filename.c_str(), "", false);
|
||||
}
|
||||
|
||||
std::string code = "";
|
||||
BeginFile(namespace_name, needs_imports, &code);
|
||||
BeginFile(LastNamespacePart(), needs_imports, &code);
|
||||
code += classcode;
|
||||
std::string filename = namespace_dir + kPathSeparator + def.name + ".py";
|
||||
std::string filename = namespace_dir_ + kPathSeparator + def.name + ".py";
|
||||
return SaveFile(filename.c_str(), code, false);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user