-
Notifications
You must be signed in to change notification settings - Fork 0
/
terminus-cli.py
163 lines (141 loc) · 6.38 KB
/
terminus-cli.py
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/env/python3
import terminusdb_client
import sys
import copy
import argparse
def add_database_notify_user(string):
print(string)
def add_database_terminus_execute(kwargs):
# Functional Programming stuffs
kwargs = copy.copy(kwargs)
# Query Database and Add New Database
client=terminusdb_client.WOQLClient(server_url = kwargs['url'])
client.connect(
account = kwargs['accountid'],
key = kwargs['pass'],
user = kwargs['accountid'])
client.create_database(
kwargs['dbid'],
kwargs['accountid'],
label = kwargs['label'], # label require otherwise will fail to add DB
description = kwargs['desc'],
prefixes = kwargs['prefix'],
include_schema = kwargs['schema'])
return 0
#fed
def add_database_parse_args(options):
#// Oh how I love my curly braces,
#// and C syntax
kwargs = \
{
"url":options.url,
'accountid':options.account,
"dbid":options.dbid,
"desc":None,
"pass":options.password,
"prefix":None,
"label":options.label,
"schema":options.no_schema
}
# Allow the user to spread their description over multiple
# options.
if options.description != None:
kwargs['desc'] = " ".join(options.description);
#fi
# this is placeholder until I figure out how prefixes work
if options.prefix != None:
kwargs['prefix'] = " ".join(options.prefix);
#fi
return kwargs;
#fed
def add_database_action(options):
kwargs = add_database_parse_args(options);
add_database_terminus_execute(kwargs);
return 0
#fed
def list_database_action(options):
# Instantiate Objects
client = terminusdb_client.WOQLClient(options.url);
WOQLLib_obj = terminusdb_client.WOQLLib();
# Generate query for database
query_macro = WOQLLib_obj.dbs(None,None);
# Execute Query
client.connect(
account = options.account,
key = options.password
);
db_list = client.query(query_macro);
print(db_list)
#fed
def rm_database_parse_args(options):
kwargs = \
{
"url":options.url,
"accountid":options.account,
"dbid":options.dbid,
"pass":options.password
}
return kwargs;
#fed
def rm_database_terminus_execute(kwargs):
# Functional Programming stuffs
kwargs = copy.copy(kwargs);
client=terminusdb_client.WOQLClient(server_url = kwargs['url']);
client.connect(
account = kwargs['accountid'],
key = kwargs['pass'],
user = kwargs['accountid']);
client.delete_database(kwargs['dbid']);
#fed
def rm_database_action(options):
kwargs = rm_database_parse_args(options);
rm_database_terminus_execute(kwargs);
return 0;
#fed
def main():
parser=argparse.ArgumentParser();
subparsers = parser.add_subparsers();
add_database_parser=subparsers.add_parser('add-database', help="Action to create database within specified TerminusDB instance");
add_database_parser.add_argument("url",help="The base url for the TerminusDB instance");
add_database_parser.add_argument("dbid",help="The ID for the new databaase");
add_database_parser.add_argument("-u","--account",help="The username/account to login with",
required=True);
add_database_parser.add_argument("-d","--description",
help="The description for the new database",
action="append");
add_database_parser.add_argument("-j","--prefix",
help="The prefixes for the new database",
action="append");
add_database_parser.add_argument("-p","--password",
help="Password to login with",
required=True);
add_database_parser.add_argument("-l","--label",
help="The label for the database(no spaces allowed)",
required=True);
add_database_parser.add_argument("-n","--no-schema",
help="Disable schema for the new database");
add_database_parser.set_defaults(func=add_database_action);
rm_database_parser=subparsers.add_parser('rm-database', help="Action to delete database within specified TerminusDB instance");
rm_database_parser.add_argument("url",help="The base url for the TerminusDB instance");
rm_database_parser.add_argument("dbid",help="The ID for the soon to be deleted databaase");
rm_database_parser.add_argument("-u","--account",help="The username/account to login with",
required=True);
rm_database_parser.add_argument("-p","--password",
help="Password to login with",
required=True);
rm_database_parser.set_defaults(func=rm_database_action);
list_database_parser=subparsers.add_parser('list-database', help="Action to list databases within specified TerminusDB instance");
list_database_parser.add_argument("url",help="The base url for the TerminusDB instance");
list_database_parser.add_argument("-p","--password",
help="Password to login with",
required=True)
list_database_parser.add_argument("-u","--account",help="The username/account to login with",
required=True);
list_database_parser.set_defaults(func=list_database_action);
options = parser.parse_args();
options.func(options);
return 0;
#fed
if __name__ == "__main__":
main()
#fi