blob: 0ef3065ee5d04650bd0f5553c0dfe0fcdea7d95b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
#!/usr/bin/python
import json
import sys
import time
import argparse
import os
import logging
root = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..'))
sys.path.append(os.path.join(root, 'src/server'))
import db_controller as dbc
from db_op import DBO_cypher_query
from rz_server import Config
rhizi_server_conf_filename = os.path.join(root, 'res', 'etc', 'rhizi-server.conf')
class Server(object):
def __init__(self):
cfg = Config.init_from_file(rhizi_server_conf_filename)
self.db_ctl = dbc.DB_Controller(cfg)
self.log = logging.getLogger('rhizi')
self.log.addHandler(logging.StreamHandler())
def run(self, statements):
for statement in statements:
print(repr(list(DBO_cypher_query([statement]))))
help = """Welcome to neo4j-cypher, a tool to submit cypher queries to neo4j
This tool follows the neo4j REST API and allows submitting queries from command
line or standard in without using neo4j-shell since that doesn't work on all machines.
It relies on curl right now although this could be replaced with straight python.
"""
def main(statements):
server = Server()
if len(statements) == 0:
statements = [l.strip() for l in sys.stdin.readlines() if l.strip()[:2] != '//' and l.strip() != ""]
print("----------------------------------------------------------------------")
print "\n".join(statements)
print("----------------------------------------------------------------------")
results = server.run(statements)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description=help, add_help=True)
parser.add_argument('--verbose', action='store_true', default=False)
args, statements = parser.parse_known_args(sys.argv[1:])
verbose = args.verbose
main(statements)
|