Skip to content

Commit a584cde

Browse files
committed
ran all the examples through flake8
1 parent c330a01 commit a584cde

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+399
-359
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ target/
6868
# Eclipse/PyDev
6969
/.project
7070
/.pydevproject
71+
/.settings
7172

7273
# Credential files
7374
.carbonblack/

examples/defense/cblr/jobrunner.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22

3-
from cbapi.defense import *
3+
from cbapi.defense import Device
44
from cbapi.example_helpers import build_cli_parser, get_cb_defense_object
55
from concurrent.futures import as_completed
66
import sys
@@ -60,12 +60,11 @@ def main():
6060
print("Sensor {0} had error:".format(futures[f]))
6161
print(f.exception())
6262

63-
6463
still_to_do = set([s.deviceId for s in online_sensors]) - set(completed_sensors)
6564
print("The following sensors were attempted but not completed or errored out:")
6665
for sensor in still_to_do:
6766
print(" {0}".format(still_to_do))
68-
67+
6968

7069
if __name__ == '__main__':
7170
sys.exit(main())

examples/defense/cblr_cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def main():
3030
parser.add_argument("--log", help="Log activity to a file", default='')
3131
args = parser.parse_args()
3232
cb = get_cb_defense_object(args)
33-
33+
3434
if args.log:
3535
file_handler = logging.FileHandler(args.log)
3636
file_handler.setLevel(logging.DEBUG)

examples/defense/list_devices.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ def main():
2424

2525
print("{0:9} {1:40}{2:18}{3}".format("ID", "Hostname", "IP Address", "Last Checkin Time"))
2626
for device in devices:
27-
print("{0:9} {1:40s}{2:18s}{3}".format(device.deviceId, device.name or "None", device.lastInternalIpAddress or "Unknown", device.lastContact))
27+
print("{0:9} {1:40s}{2:18s}{3}".format(device.deviceId, device.name or "None",
28+
device.lastInternalIpAddress or "Unknown", device.lastContact))
2829

2930

3031
if __name__ == "__main__":

examples/defense/list_events.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ def main():
4242
if args.hostname:
4343
events = list(cb.select(Event).where("hostNameExact:{0}".format(args.hostname)))
4444
elif args.start and args.end:
45-
# flipped the start and end arguments around so script can be called with the start date being the earliest date.
46-
# it's just easier on the eyes for most folks.
45+
# flipped the start and end arguments around so script can be called with the start date being
46+
# the earliest date. it's just easier on the eyes for most folks.
4747

4848
events = list(cb.select(Event).where("startTime:{0}".format(args.end))) and (
4949
cb.select(Event).where("endTime:{0}".format(args.start)))

examples/defense/list_events_with_cmdline_csv.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88

99
# Notes on this script:
10-
# - based on https://github.com/carbonblack/cbapi-python/blob/master/examples/defense/list_events.py with 2 primary changes
10+
# - based on https://github.com/carbonblack/cbapi-python/blob/master/examples/defense/list_events.py
11+
# with 2 primary changes
1112
# 1. this script outputs the command line of the main process process
1213
# 2. this script places a '|' delimiter between fields so it can be read into a spreadsheet
1314
# - can only pull up to 2 weeks of events at one time ( this is an API limitation)
@@ -48,8 +49,8 @@ def main():
4849
if args.hostname:
4950
events = list(cb.select(Event).where("hostNameExact:{0}".format(args.hostname)))
5051
elif args.start and args.end:
51-
# flipped the start and end arguments around so script can be called with the start date being the earliest date.
52-
# it's just easier on the eyes for most folks.
52+
# flipped the start and end arguments around so script can be called with the start date
53+
# being the earliest date. it's just easier on the eyes for most folks.
5354

5455
events = list(cb.select(Event).where("startTime:{0}".format(args.end))) and (
5556
cb.select(Event).where("endTime:{0}".format(args.start)))
@@ -65,21 +66,20 @@ def main():
6566
create_time = str(convert_time(event.eventTime))
6667

6768
# stripping HTML tags out of the long description
68-
long_description = unicodedata.normalize('NFD',strip_html(event.longDescription))
69+
long_description = unicodedata.normalize('NFD', strip_html(event.longDescription))
6970

7071
if event.processDetails:
7172
# stripping out the command line arguments from the processDetails field
7273
processDetails = str(event.processDetails)
7374
start_cmdline = processDetails.find("u'commandLine'")
7475
end_cmdline = processDetails.find(", u'parentName'")
75-
commandline = processDetails[start_cmdline + 18: end_cmdline -1]
76-
print("{0}|{1}|{2}|{3}|{4}|{5}".format(event_time, event.eventId, create_time, event.eventType, long_description, commandline))
76+
commandline = processDetails[start_cmdline + 18: end_cmdline - 1]
77+
print("{0}|{1}|{2}|{3}|{4}|{5}".format(event_time, event.eventId, create_time, event.eventType,
78+
long_description, commandline))
7779
else:
78-
print("{0}|{1}|{2}|{3}|{4}".format(event_time, event.eventId, create_time, event.eventType, long_description))
80+
print("{0}|{1}|{2}|{3}|{4}".format(event_time, event.eventId, create_time, event.eventType,
81+
long_description))
7982
# format and print out the event time, Event ID, Creation time, Event type and Description
80-
81-
82-
8383

8484

8585
if __name__ == "__main__":

examples/defense/policy_operations.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,12 @@ def replace_rule(cb, parser, args):
134134
print("Replaced rule id {0} from policy {1} with rule from file {2}.".format(args.ruleid, policy.name,
135135
args.rulefile))
136136

137+
137138
def main():
138139
parser = build_cli_parser("Policy operations")
139140
commands = parser.add_subparsers(help="Policy commands", dest="command_name")
140141

141-
list_command = commands.add_parser("list", help="List all configured policies")
142+
commands.add_parser("list", help="List all configured policies")
142143

143144
import_policy_command = commands.add_parser("import", help="Import policy from JSON file")
144145
import_policy_command.add_argument("-N", "--name", help="Name of new policy", required=True)
@@ -157,7 +158,7 @@ def main():
157158
del_policy_specifier = del_command.add_mutually_exclusive_group(required=True)
158159
del_policy_specifier.add_argument("-i", "--id", type=int, help="ID of policy to delete")
159160
del_policy_specifier.add_argument("-N", "--name", help="Name of policy to delete. Specify --force to delete"
160-
" multiple policies that have the same name")
161+
" multiple policies that have the same name")
161162
del_command.add_argument("--force", help="If NAME matches multiple policies, delete all matching policies",
162163
action="store_true", default=False)
163164

examples/livequery/manage_run.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,33 +25,32 @@ def create_run(cb, args):
2525
def run_status(cb, args):
2626
run = cb.select(Run, args.id)
2727
print(run)
28-
29-
28+
29+
3030
def run_stop(cb, args):
3131
run = cb.select(Run, args.id)
3232
if run.stop():
3333
print("Run {} has been stopped.".format(run.id))
3434
print(run)
3535
else:
3636
print("Unable to stop run {}".format(run.id))
37-
38-
37+
38+
3939
def run_delete(cb, args):
4040
run = cb.select(Run, args.id)
4141
if run.delete():
4242
print("Run {} has been deleted.".format(run.id))
4343
else:
4444
print("Unable to delete run {}".format(run.id))
45-
46-
45+
46+
4747
def run_history(cb, args):
4848
results = cb.query_history(args.query)
4949
if args.sort_by:
5050
dir = "DESC" if args.descending_results else "ASC"
5151
results.sort_by(args.sort_by, direction=dir)
5252
for result in results:
5353
print(result)
54-
5554

5655

5756
def main():
@@ -99,21 +98,21 @@ def main():
9998
status_command.add_argument(
10099
"-i", "--id", type=str, required=True, help="The run ID"
101100
)
102-
101+
103102
stop_command = commands.add_parser(
104103
"stop", help="Stops/cancels a current run"
105104
)
106105
stop_command.add_argument(
107106
"-i", "--id", type=str, required=True, help="The run ID"
108107
)
109-
108+
110109
delete_command = commands.add_parser(
111110
"delete", help="Permanently delete a run"
112111
)
113112
delete_command.add_argument(
114113
"-i", "--id", type=str, required=True, help="The run ID"
115114
)
116-
115+
117116
history_command = commands.add_parser(
118117
"history", help="List history of all runs"
119118
)
@@ -145,5 +144,6 @@ def main():
145144
elif args.command_name == "history":
146145
return run_history(cb, args)
147146

147+
148148
if __name__ == "__main__":
149149
sys.exit(main())

examples/livequery/run_device_summary.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ def main():
5656

5757
args = parser.parse_args()
5858
cb = get_cb_livequery_object(args)
59-
59+
6060
results = cb.select(Result).run_id(args.id)
6161
result = results.first()
6262
if result is None:
6363
print("ERROR: No results.")
6464
return 1
65-
65+
6666
summaries = result.query_device_summaries()
6767
if args.query:
6868
summaries.where(args.query)
@@ -79,7 +79,7 @@ def main():
7979
if args.sort_by:
8080
dir = "DESC" if args.descending_results else "ASC"
8181
summaries.sort_by(args.sort_by, direction=dir)
82-
82+
8383
for summary in summaries:
8484
print(summary)
8585

examples/livequery/run_facets.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def main():
2525
required=False,
2626
help="Fields to be displayed in results",
2727
)
28-
28+
2929
parser.add_argument("-q", "--query", type=str, required=False, help="Search query")
3030
parser.add_argument(
3131
"--device_ids",
@@ -70,15 +70,15 @@ def main():
7070
if args.result and args.device_summary:
7171
print("ERROR: --result and --device_summary cannot both be specified")
7272
return 1
73-
73+
7474
cb = get_cb_livequery_object(args)
75-
75+
7676
results = cb.select(Result).run_id(args.id)
7777
result = results.first()
7878
if result is None:
7979
print("ERROR: No results.")
8080
return 1
81-
81+
8282
if args.result:
8383
facets = result.query_result_facets()
8484
elif args.device_summary:
@@ -97,11 +97,10 @@ def main():
9797
facets.criteria(policy_name=args.policy_names)
9898
if args.statuses:
9999
facets.criteria(status=args.statuses)
100-
100+
101101
for facet in facets:
102102
print(facet)
103-
104-
103+
104+
105105
if __name__ == "__main__":
106106
sys.exit(main())
107-

0 commit comments

Comments
 (0)