def cache_paths(self): """Return the paths to the inp and out files as expected locally. :return: Tuple consisting of inp and out local cache paths. :rtype: tuple (str, str) :raises: None """ input_file_name, output_file_name = self.file_names() input_file_path = os.path.join(shakemap_zip_dir(), input_file_name) output_file_path = os.path.join(shakemap_zip_dir(), output_file_name) return input_file_path, output_file_path
def _fetch_file(self, event_file, retries=3): """Private helper to fetch a file from the ftp site. e.g. for event 20110413170148 this file would be fetched:: ftp://118.97.83.243/20110413170148.inp.zip and this local file created:: /tmp/realtime/20110413170148.inp.zip .. note:: If a cached copy of the file exits, the path to the cache copy will simply be returned without invoking any network requests. :param event_file: Filename on server e.g.20110413170148.inp.zip :type event_file: str :param retries: Number of reattempts that should be made in in case of network error etc. :type retries: int :return: A string for the dataset path on the local storage system. :rtype: str :raises: EventUndefinedError, NetworkError """ # Return the cache copy if it exists local_path = os.path.join(shakemap_zip_dir(), event_file) if os.path.exists(local_path): return local_path #Otherwise try to fetch it using ftp for counter in range(retries): last_error = None try: client = FtpClient() client.get_file(event_file, local_path) except NetworkError, e: last_error = e except: