コード例 #1
0
    def test_get_file(self):
        """Test that the ftp client can fetch a file ok"""
        client = FtpClient()

        local_path = os.path.join(temp_dir('realtime-test'),
                                  '20120726022003.inp.zip')
        client.get_file('20120726022003.inp.zip', local_path)
        message = 'Function get_file is not working correctly.'
        self.assertTrue(os.path.exists(local_path), message)
コード例 #2
0
ファイル: test_ftp_client.py プロジェクト: cccs-ip/inasafe
    def test_get_file(self):
        """Test that the ftp client can fetch a file ok"""
        client = FtpClient()

        local_path = os.path.join(
            temp_dir('realtime-test'),
            '20120726022003.inp.zip')
        client.get_file('20120726022003.inp.zip', local_path)
        message = 'Function get_file is not working correctly.'
        self.assertTrue(os.path.exists(local_path), message)
コード例 #3
0
ファイル: shake_data.py プロジェクト: essc/inasafe
    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:
コード例 #4
0
    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: