Esempio n. 1
0
    def fetch_file(self, retries=3):
        """Private helper to fetch a file from the sftp site.

        :param retries: int - number of reattempts that should be made in
                in case of network error etc.
          e.g. for event 20110413170148 this file would be fetched::
                20110413170148 directory

        .. note:: If a cached copy of the file exits, the path to the cache
           copy will simply be returned without invoking any network requests.

        :return: A string for the dataset path on the local storage system.
        :rtype: str

        :raises: EventUndefinedError, NetworkError
        """
        local_path = os.path.join(shakemap_cache_dir(), self.event_id)
        local_parent_path = os.path.join(local_path, "output")
        xml_file = os.path.join(local_parent_path, self.file_name())
        if os.path.exists(xml_file):
            return local_path

        # fetch from sftp
        trials = [i + 1 for i in xrange(retries)]
        remote_path = os.path.join(self.sftpclient.workdir_path, self.event_id)
        xml_remote_path = os.path.join(remote_path, "output", self.file_name())
        for counter in trials:
            last_error = None
            try:
                mk_dir(local_path)
                mk_dir(os.path.join(local_path, "output"))
                self.sftpclient.download_path(xml_remote_path, local_parent_path)
            except NetworkError, e:
                last_error = e
            except:
Esempio n. 2
0
    def cache_paths(self):
        """Return the paths to the inp and out files as expected locally.

        :return: grid.xml local cache paths.
        :rtype: str
        """

        xml_file_name = self.file_name()
        xml_file_path = os.path.join(shakemap_cache_dir(), self.event_id, xml_file_name)
        return xml_file_path
Esempio n. 3
0
    def cache_paths(self):
        """Return the paths to the inp and out files as expected locally.

        :return: grid.xml local cache paths.
        :rtype: str
        """

        xml_file_name = self.file_name()
        xml_file_path = os.path.join(shakemap_cache_dir(), self.event_id,
                                     xml_file_name)
        return xml_file_path
Esempio n. 4
0
    def fetch_file(self, retries=3):
        """Private helper to fetch a file from the sftp site.

        :param retries: int - number of reattempts that should be made in
                in case of network error etc.
          e.g. for event 20110413170148 this file would be fetched::
                20110413170148 directory

        .. note:: If a cached copy of the file exits, the path to the cache
           copy will simply be returned without invoking any network requests.

        :return: A string for the dataset path on the local storage system.
        :rtype: str

        :raises: EventUndefinedError, NetworkError
        """
        local_path = os.path.join(shakemap_cache_dir(), self.event_id)
        local_parent_path = os.path.join(local_path, 'output')
        xml_file = os.path.join(local_parent_path, self.file_name())
        if os.path.exists(xml_file):
            return local_path

        # fetch from sftp
        trials = [i + 1 for i in xrange(retries)]
        remote_path = os.path.join(self.sftpclient.workdir_path, self.event_id)
        xml_remote_path = os.path.join(remote_path, 'output', self.file_name())
        for counter in trials:
            last_error = None
            try:
                mk_dir(local_path)
                mk_dir(os.path.join(local_path, 'output'))
                self.sftpclient.download_path(xml_remote_path,
                                              local_parent_path)
            except NetworkError, e:
                last_error = e
            except: