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

          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.

        Args:
            * theEventFile: str - filename on server e.g.20110413170148.inp.zip
            * theRetries: int - number of reattempts that should be made in
                in case of network error etc.

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

        Raises:
            EventUndefinedError, NetworkError
        """
        myLocalPath = os.path.join(shakemapCacheDir(), self.eventId)
        myXMLFile = os.path.join(myLocalPath, 'output', self.fileName())
        if os.path.exists(myXMLFile):
            return myLocalPath

        # fetch from sftp
        trials = [i + 1 for i in xrange(theRetries)]
        remote_path = os.path.join(self.sftpclient.workdir_path, self.eventId)
        for my_counter in trials:
            myLastError = None
            try:
                self.sftpclient.download_path(remote_path, shakemapCacheDir())
            except NetworkError, e:
                myLastError = e
            except:
Esempio n. 2
0
    def cachePaths(self):
        """Return the paths to the inp and out files as expected locally.

        Args: None

        Returns:
            str: grid.xml local cache paths.

        Raises:
            None
        """

        myXMLFileName = self.fileName()
        myXMLFilePath = os.path.join(shakemapCacheDir(), self.eventId,
                                     myXMLFileName)
        return myXMLFilePath
Esempio n. 3
0
    def cachePaths(self):
        """Return the paths to the inp and out files as expected locally.

        Args: None

        Returns:
            str: grid.xml local cache paths.

        Raises:
            None
        """

        myXMLFileName = self.fileName()
        myXMLFilePath = os.path.join(
            shakemapCacheDir(), self.eventId, myXMLFileName)
        return myXMLFilePath
Esempio n. 4
0
    def fetchFile(self, theRetries=3):
        """Private helper to fetch a file from the sftp site.

          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.

        Args:
            * theEventFile: str - filename on server e.g.20110413170148.inp.zip
            * theRetries: int - number of reattempts that should be made in
                in case of network error etc.

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

        Raises:
            EventUndefinedError, NetworkError
        """
        myLocalPath = os.path.join(shakemapCacheDir(), self.eventId)
        myLocalParentPath = os.path.join(myLocalPath, 'output')
        myXMLFile = os.path.join(myLocalParentPath, self.fileName())
        if os.path.exists(myXMLFile):
            return myLocalPath

        # fetch from sftp
        trials = [i + 1 for i in xrange(theRetries)]
        remote_path = os.path.join(self.sftpclient.workdir_path, self.eventId)
        myXMLRemotePath = os.path.join(remote_path, 'output', self.fileName())
        for my_counter in trials:
            myLastError = None
            try:
                mkDir(myLocalPath)
                mkDir(os.path.join(myLocalPath, 'output'))
                self.sftpclient.download_path(myXMLRemotePath,
                                              myLocalParentPath)
            except NetworkError, e:
                myLastError = e
            except: