Skip to content

Commit

Permalink
Dont bother to continue the process if the sftp contains no shakemaps.
Browse files Browse the repository at this point in the history
  • Loading branch information
akbargumbira committed Aug 15, 2014
1 parent 9c07a0e commit 0dfe625
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 15 deletions.
5 changes: 5 additions & 0 deletions realtime/exceptions.py
Expand Up @@ -103,3 +103,8 @@ class MapComposerError(Exception):
class CopyError(Exception):
"""Raised if a problem occurs copying a file"""
pass


class SFTPEmptyError(Exception):
"""Raised if the SFTP remote directory does not contain any shakemaps."""
pass
4 changes: 4 additions & 0 deletions realtime/make_map.py
Expand Up @@ -27,6 +27,7 @@
from realtime.sftp_client import SFtpClient
from realtime.utilities import data_dir, is_event_id, realtime_logger_name
from realtime.shake_event import ShakeEvent
from realtime.exceptions import SFTPEmptyError

# Initialised in realtime.__init__
LOGGER = logging.getLogger(realtime_logger_name())
Expand Down Expand Up @@ -90,6 +91,9 @@ def process_event(event_id=None, locale='en'):
event_id=event_id,
locale=locale,
force_flag=True)
except SFTPEmptyError as ex:
LOGGER.info(ex)
return
except:
LOGGER.exception('An error occurred setting up the shake event.')
return
Expand Down
26 changes: 16 additions & 10 deletions realtime/sftp_shake_data.py
Expand Up @@ -34,7 +34,8 @@
EventIdError,
NetworkError,
EventValidationError,
CopyError)
CopyError,
SFTPEmptyError)
from realtime.sftp_configuration.configuration import (
get_sftp_base_url,
get_sftp_port,
Expand Down Expand Up @@ -115,7 +116,7 @@ def __init__(self,
if self.event_id is None:
try:
self.get_latest_event_id()
except NetworkError:
except (SFTPEmptyError, NetworkError, EventIdError):
raise
else:
# If we fetched it above using get_latest_event_id we assume it is
Expand All @@ -137,10 +138,12 @@ def reconnect_sftp(self):
self.host, self.username, self.password, self.working_dir)

def validate_event(self):
"""Check that the event associated with this instance exists either
in the local event cache or on the remote ftp site.
"""Check that the event associated with this instance exists.
:return: True if valid, False if not
This will check either in the local event cache or on the remote ftp
site.
:return: True if valid, False if not.
:rtype: bool
:raises: NetworkError
Expand Down Expand Up @@ -181,7 +184,7 @@ def cache_paths(self):
def is_on_server(self):
"""Check the event associated with this instance exists on the server.
:return: True if valid, False if not
:return: True if valid, False if not.
:raises: NetworkError
"""
Expand All @@ -190,16 +193,19 @@ def is_on_server(self):
return self.sftp_client.path_exists(remote_xml_path)

def get_list_event_ids(self):
"""Get all event id indicated by folder in remote_path
"""
"""Get all event id indicated by folder in remote_path."""
dirs = self.sftp_client.get_listing(function=is_event_id)
if len(dirs) == 0:
raise Exception('List event is empty')
raise SFTPEmptyError(
'The SFTP directory does not contain any shakemaps.')
return dirs

def get_latest_event_id(self):
"""Return latest event id."""
event_ids = self.get_list_event_ids()
try:
event_ids = self.get_list_event_ids()
except SFTPEmptyError:
raise

now = datetime.now()
now = int(
Expand Down
16 changes: 11 additions & 5 deletions realtime/shake_event.py
Expand Up @@ -99,7 +99,10 @@
ShapefileCreationError,
CityMemoryLayerCreationError,
FileNotFoundError,
MapComposerError)
MapComposerError,
SFTPEmptyError,
NetworkError,
EventIdError)

LOGGER = logging.getLogger(realtime_logger_name())
QGIS_APP, CANVAS, IFACE, PARENT = get_qgis_app()
Expand Down Expand Up @@ -153,7 +156,7 @@ def __init__(self,
:return: Instance
:raises: EventXmlParseError
:raises: SFTPEmptyError, NetworkError, EventIdError, EventXmlParseError
"""
# We inherit from QObject for translation support
QObject.__init__(self)
Expand All @@ -165,9 +168,12 @@ def __init__(self,
else:
# fetch the data from (s)ftp
#self.data = ShakeData(event_id, force_flag)
self.data = SftpShakeData(
event=event_id,
force_flag=force_flag)
try:
self.data = SftpShakeData(
event=event_id,
force_flag=force_flag)
except (SFTPEmptyError, NetworkError, EventIdError):
raise
self.data.extract()
self.event_id = self.data.event_id

Expand Down

0 comments on commit 0dfe625

Please sign in to comment.