This repository was archived by the owner on Apr 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
51 lines (48 loc) · 1.46 KB
/
__init__.py
File metadata and controls
51 lines (48 loc) · 1.46 KB
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
import sys, subprocess, platform
class InfraQL:
def __init__(self, **kwargs):
plat = platform.system()
defaultbin = r'infraql'
if plat == 'Windows':
defaultbin = r'infraql.exe'
# infraql binary
self.exe = kwargs.get('exe')
if self.exe is not None:
self.exe = kwargs.get('exe')
else:
self.exe = defaultbin
self.params = ['exec', '--output', 'json']
# authentication method
self.keyfilepath = kwargs.get('keyfilepath')
if self.keyfilepath is not None:
self.params.append('--keyfilepath')
self.params.append(self.keyfilepath)
# specify dbfilepath
self.dbfilepath = kwargs.get('dbfilepath')
if self.dbfilepath is not None:
self.params.append('--dbfilepath')
self.params.append(self.dbfilepath)
def execute(self, query):
local_params = self.params
local_params.insert(1, query)
try:
iqlPopen = subprocess.Popen([self.exe] + local_params,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output = iqlPopen.stdout.read()
iqlPopen.terminate()
except:
e = sys.exc_info()[0]
print("ERROR %s %s" % (str(e), e.__doc__))
output = None
return output
def version(self):
try:
iqlPopen = subprocess.Popen([self.exe] + ["--version"],
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output = iqlPopen.stdout.read()
iqlPopen.terminate()
except:
e = sys.exc_info()[0]
print("ERROR %s %s" % (str(e), e.__doc__))
output = None
return output