Skip to content

Commit

Permalink
remove __main__ construct
Browse files Browse the repository at this point in the history
  • Loading branch information
tahmed-dev committed Aug 14, 2020
1 parent 40d3e52 commit 6d507f5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
23 changes: 6 additions & 17 deletions fdb_utils/filter_fdb_entries.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env python

import json
import sys
import os
Expand Down Expand Up @@ -130,38 +128,29 @@ def main(argv):
parser.add_argument('-a', '--arp', type=str, default='/tmp/arp.json', help='arp file name')
parser.add_argument('-c', '--config_db', type=str, default='/tmp/config_db.json', help='config db file name')
parser.add_argument('-b', '--backup_file', type=bool, default=True, help='Back up old fdb entries file')
args = parser.parse_args(argv)
args = parser.parse_args(argv[1:])

fdb_filename = args.fdb
arp_filename = args.arp
config_db_filename = args.config_db
backup_file = args.backup_file

try:
syslog.openlog('filter_fdb_entries')
file_exists_or_raise(fdb_filename)
file_exists_or_raise(arp_filename)
file_exists_or_raise(config_db_filename)
except Exception as e:
syslog.syslog(syslog.LOG_ERR, "Got an exception %s: Traceback: %s" % (str(e), traceback.format_exc()))
else:
filter_fdb_entries(fdb_filename, arp_filename, config_db_filename, backup_file)

return 0

if __name__ == '__main__':
res = 0
try:
syslog.openlog('filter_fdb_entries')
res = main(sys.argv[1:])
except KeyboardInterrupt:
syslog.syslog(syslog.LOG_NOTICE, "SIGINT received. Quitting")
res = 1
except Exception as e:
syslog.syslog(syslog.LOG_ERR, "Got an exception %s: Traceback: %s" % (str(e), traceback.format_exc()))
res = 2
else:
filter_fdb_entries(fdb_filename, arp_filename, config_db_filename, backup_file)
finally:
syslog.closelog()
try:
sys.exit(res)
except SystemExit:
os._exit(res)

return 0
1 change: 1 addition & 0 deletions tests/filter_fdb_entries_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ def testFilterFdbEntries(self, testData):
try:
self.__setUp(testData)
argv = [
"filter_fdb_entries",
"-a",
self.ARP_FILENAME,
"-f",
Expand Down

0 comments on commit 6d507f5

Please sign in to comment.