Created
December 27, 2019 16:33
-
-
Save iddan/4caf5b89984407d6e775454001654bef to your computer and use it in GitHub Desktop.
Refactor Cayley LinkedQL steps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
directory = "query/linkedql/" | |
with open(directory + "steps.go") as file: | |
content = file.read() | |
def convert(name): | |
s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name) | |
return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower() | |
separator = "var _ IteratorStep = (*" | |
for part in content.split(separator): | |
step_name = part.split("\n")[0].replace(")(nil)", "") | |
if step_name == "package linkedql": | |
continue | |
header = """ | |
package linkedql | |
import ( | |
"github.com/cayleygraph/cayley/graph" | |
"github.com/cayleygraph/cayley/graph/iterator" | |
"github.com/cayleygraph/cayley/query" | |
"github.com/cayleygraph/cayley/query/path" | |
"github.com/cayleygraph/quad" | |
"github.com/cayleygraph/quad/voc" | |
) | |
func init() { | |
Register(&%s{}) | |
} | |
""" % (step_name) | |
step_code = header + separator + part | |
path = directory + "steps/" + convert(step_name) + ".go" | |
with open(path, 'w+') as file: | |
file.write(step_code) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment