diff options
| author | Alon Levy <alon@pobox.com> | 2015-02-05 15:40:44 +0200 |
|---|---|---|
| committer | Alon Levy <alon@pobox.com> | 2015-02-05 15:40:44 +0200 |
| commit | c6082885373acee08ecd746ddfa3b8dce1a0f8da (patch) | |
| tree | 95c12191c6ba5c2bea131b9e8f6df276dcf654c9 /tools/neo4j-cypher | |
| parent | 88b69cc593a1b8d265c133bbf71d4c8ce25dc4e3 (diff) | |
tools: split neo4j-cypher in preparation to make it reuse core server library
Diffstat (limited to 'tools/neo4j-cypher')
| -rwxr-xr-x | tools/neo4j-cypher | 40 |
1 files changed, 3 insertions, 37 deletions
diff --git a/tools/neo4j-cypher b/tools/neo4j-cypher index 86baea87..c2aee707 100755 --- a/tools/neo4j-cypher +++ b/tools/neo4j-cypher @@ -1,8 +1,5 @@ #!/usr/bin/python -import os -import subprocess -import re import json import sys import time @@ -14,32 +11,7 @@ line or standard in without using neo4j-shell since that doesn't work on all mac It relies on curl right now although this could be replaced with straight python. """ -verbose = False -BASE="http://rhizi.local:7474/db/data" - -def c(cmd, incoming=None): - if verbose: - print("executing %r" % cmd) - print(incoming) - p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - if incoming: - p.stdin.write(incoming) - if p.stdin: - p.stdin.close() - p.wait() - ret = p.stdout.read() - return ret - -def curl(path, incoming): - return c(["curl", "-H", 'Accept: application/json', "-H", 'Content-Type: application/json', '-XPOST', '-d@-', path], - incoming=incoming) - -def transact(datum): - transaction_output = curl(BASE + "/transaction/", '{"statements": [ ] }') - commit = re.search("http://.*commit", transaction_output).group() - ret = curl(commit, json.dumps(datum)) - obj = json.loads(ret) - return obj +import rhizi_tools_neo4j def main(statements): one_at_a_time = False @@ -49,14 +21,8 @@ def main(statements): print("----------------------------------------------------------------------") print "\n".join(statements) print("----------------------------------------------------------------------") - def single_request_data(statements): - return {'statements': [{'statement': s} for s in statements]} - if one_at_a_time: - data = [single_request_data([statement]) for statement in statements] - else: - data = [single_request_data(statements)] - for datum in data: - result = transact(datum) + results = rhizi_tools_neo4j.run(statements=statements, one_at_a_time=one_at_a_time) + for result in results: json.dump(result, sys.stdout, sort_keys=True, indent=4, separators=(',', ': ')) print() |
