fix: [perms] Added try/except for various permission conditions, also create the output dir if not exist

fix: [try/except] Catch Ctrl-c keyboard interrupt
fix: [style] isort imports
pull/402/head
Steve Clement 2019-06-03 14:06:19 +09:00
parent 16f403e31d
commit 54a2e8657a
No known key found for this signature in database
GPG Key ID: 69A20F509BE4AEE9
2 changed files with 27 additions and 9 deletions

View File

@ -1,15 +1,15 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
import json
import argparse
import datetime
import json
import sys
import time
import redis
import settings
from generator import FeedGenerator
@ -60,7 +60,10 @@ class RedisToMISPFeed:
except Exception as error:
self.save_error_to_redis(error, data)
beautyful_sleep(5, self.format_last_action())
try:
beautyful_sleep(5, self.format_last_action())
except KeyboardInterrupt:
sys.exit(130)
def pop(self, key):
popped = self.serv.rpop(key)

View File

@ -1,10 +1,10 @@
#!/usr/bin/env python3
import sys
import datetime
import hashlib
import json
import os
import hashlib
import datetime
import sys
import time
import uuid
@ -142,9 +142,24 @@ class FeedGenerator:
# Manifest
def _init_manifest(self):
# check if outputdir exists and try to create it if not
if not os.path.exists(settings.outputdir):
try:
os.makedirs(settings.outputdir)
except PermissionError as error:
print(error)
print("Please fix the above error and try again.")
sys.exit(126)
# create an empty manifest
with open(os.path.join(settings.outputdir, 'manifest.json'), 'w'):
pass
try:
with open(os.path.join(settings.outputdir, 'manifest.json'), 'w'):
pass
except PermissionError as error:
print(error)
print("Please fix the above error and try again.")
sys.exit(126)
# create new event and save manifest
self.create_daily_event()