Skip to content

Commit c7fee43

Browse files
comparing to None in a pythonic way
1 parent 7e4cf60 commit c7fee43

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

package-dsdlsupport/src/dsdlsupport/SplunkSearch.py

+19-17
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import os
22
import time
3-
import pandas as pd
3+
44
import ipywidgets as widgets
5-
from IPython.display import display
6-
import splunklib.results as splunk_results
5+
import pandas as pd
76
import splunklib.client as splunk_client
7+
import splunklib.results as splunk_results
8+
from IPython.display import display
9+
810

911
class SplunkSearch(object):
1012
def __init__(self,
@@ -21,7 +23,7 @@ def __init__(self,
2123
self.host = host
2224
self.port = port
2325
self.token = token
24-
26+
2527
if "splunk_access_enabled" in os.environ:
2628
access_enabled = os.environ["splunk_access_enabled"]
2729
if access_enabled=="1":
@@ -70,22 +72,22 @@ def __init__(self,
7072
layout=widgets.Layout(width='100%'),
7173
disabled=True
7274
)
73-
75+
7476
# generate the widgets in a box layout
7577
self.widgets = widgets.VBox([
7678
widgets.HBox([ui['spl'], widgets.VBox([ui['button'], ui['earliest'], ui['latest']], layout=widgets.Layout(width='20%'))]),
77-
ui['progress1'],
79+
ui['progress1'],
7880
ui['progress2'],
7981
ui['resultinfo']
8082
])
8183

82-
# keep the reference to the UI widgets
84+
# keep the reference to the UI widgets
8385
self.ui = ui
8486

8587
# display the UI
8688
display(self.widgets)
87-
88-
89+
90+
8991
def search_button_clicked(self, button_event):
9092
self.ui['button'].disabled = True
9193
self.ui['progress1'].description = "search"
@@ -99,10 +101,10 @@ def search_button_clicked(self, button_event):
99101
)
100102
self.ui['button'].disabled = False
101103
self._results = resultset
102-
104+
103105
@property
104106
def service(self):
105-
if self._service != None:
107+
if self._service is not None:
106108
return self._service
107109
self._service = splunk_client.connect(host=self.host, port=self.port, token=self.token)
108110
return self._service
@@ -116,7 +118,7 @@ def search(self, query, earliest="-15m@m", latest="now"):
116118
elif query_cleaned[0]=='|':
117119
# assume a generating search command and do nothing
118120
pass
119-
elif query_cleaned.startswith("search "):
121+
elif query_cleaned.startswith("search ") or query_cleaned.startswith("search\n"):
120122
# assume the search keyword is already there
121123
pass
122124
else:
@@ -128,9 +130,9 @@ def search(self, query, earliest="-15m@m", latest="now"):
128130
try:
129131
# create a search job in splunk
130132
job = self.service.jobs.create(
131-
query_cleaned,
132-
earliest_time=earliest,
133-
latest_time=latest,
133+
query_cleaned,
134+
earliest_time=earliest,
135+
latest_time=latest,
134136
adhoc_search_level="smart",
135137
search_mode="normal")
136138
self._job = job
@@ -162,7 +164,7 @@ def search(self, query, earliest="-15m@m", latest="now"):
162164
#print(result)
163165
processed += 1
164166
self.ui['progress2'].value = float(processed)
165-
offset = processed
167+
offset = processed
166168
self.ui['progress2'].value = self.ui['progress2'].max
167169
self.ui['progress2'].description = "loading done"
168170

@@ -179,7 +181,7 @@ def search(self, query, earliest="-15m@m", latest="now"):
179181
return resultset
180182

181183
def search_logs(self):
182-
if self._job != None:
184+
if self._job is not None:
183185
for line in self._job.searchlog():
184186
print(str(line))
185187

0 commit comments

Comments
 (0)