コード例 #1
0
ファイル: shake_data.py プロジェクト: essc/inasafe
    def get_latest_event_id(self):
        """Query the ftp server and determine the latest event id.

        :return: A string containing a valid event id.

        :raises: NetworkError
        """
        ftp_client = FtpClient()
        try:
            ftp_client_list = ftp_client.get_listing()
            ftp_client_list.sort(key=lambda x: x.lower())
        except NetworkError:
            raise
        now = datetime.now()
        now = int(
            '%04d%02d%02d%02d%02d%02d' % (
                now.year, now.month, now.day, now.hour, now.minute, now.second
            ))
        event_id = now + 1
        while int(event_id) > now:
            if len(ftp_client_list) < 1:
                raise EventIdError('Latest Event Id could not be obtained')
            event_id = ftp_client_list.pop().split('/')[-1].split('.')[0]

        if event_id is None:
            raise EventIdError('Latest Event Id could not be obtained')
        self.event_id = event_id
コード例 #2
0
    def get_latest_event_id(self):
        """Query the ftp server and determine the latest event id.

        :return: A string containing a valid event id.

        :raises: NetworkError
        """
        ftp_client = FtpClient()
        try:
            ftp_client_list = ftp_client.get_listing()
            ftp_client_list.sort(key=lambda x: x.lower())
        except NetworkError:
            raise
        now = datetime.now()
        now = int(
            '%04d%02d%02d%02d%02d%02d' %
            (now.year, now.month, now.day, now.hour, now.minute, now.second))
        event_id = now + 1
        while int(event_id) > now:
            if len(ftp_client_list) < 1:
                raise EventIdError('Latest Event Id could not be obtained')
            event_id = ftp_client_list.pop().split('/')[-1].split('.')[0]

        if event_id is None:
            raise EventIdError('Latest Event Id could not be obtained')
        self.event_id = event_id
コード例 #3
0
ファイル: test_ftp_client.py プロジェクト: borysiasty/inasafe
 def test_get_file(self):
     """Test that the ftp client can fetch a file ok"""
     client = FtpClient()
     file_list = client.get_listing()
     #Make it a single string
     file_list = '\n'.join(file_list)
     message = ('Expected outcome:\n%s\nActual outcome:\n%s' %
                (file_list, self._expectedMatches))
     for expected_file in self._expectedMatches:
         assert re.search(expected_file, file_list), message
コード例 #4
0
ファイル: test_ftp_client.py プロジェクト: borysiasty/inasafe
 def test_get_directory_listing(self):
     """Check if we can get a nice directory listing"""
     client = FtpClient()
     file_list = client.get_listing()
     #Make it a single string
     file_list = '\n'.join(file_list)
     message = ('Expected this list:\n%s\nTo contain these items:\n%s' %
                (file_list, self._expectedMatches))
     for expected_file in self._expectedMatches:
         assert re.search(expected_file, file_list), message
コード例 #5
0
 def test_get_directory_listing(self):
     """Check if we can get a nice directory listing"""
     client = FtpClient()
     file_list = client.get_listing()
     # Make it a single string
     file_list = '\n'.join(file_list)
     expected_output = ['20120726022003.inp.zip', '20120726022003.out.zip']
     message = ('Expected this list:\n%s\nTo contain these items:\n%s' %
                (file_list, expected_output))
     for expected_file in expected_output:
         assert re.search(expected_file, file_list), message
コード例 #6
0
 def test_get_file(self):
     """Test that the ftp client can fetch a file ok"""
     client = FtpClient()
     file_list = client.get_listing()
     #Make it a single string
     file_list = '\n'.join(file_list)
     message = (
         'Expected outcome:\n%s\nActual outcome:\n%s' %
         (file_list, self._expectedMatches))
     for expected_file in self._expectedMatches:
         assert re.search(expected_file, file_list), message
コード例 #7
0
 def test_get_directory_listing(self):
     """Check if we can get a nice directory listing"""
     client = FtpClient()
     file_list = client.get_listing()
     #Make it a single string
     file_list = '\n'.join(file_list)
     message = (
         'Expected this list:\n%s\nTo contain these items:\n%s' %
         (file_list, self._expectedMatches))
     for expected_file in self._expectedMatches:
         assert re.search(expected_file, file_list), message
コード例 #8
0
ファイル: test_ftp_client.py プロジェクト: cccs-ip/inasafe
 def test_get_directory_listing(self):
     """Check if we can get a nice directory listing"""
     client = FtpClient()
     file_list = client.get_listing()
     # Make it a single string
     file_list = '\n'.join(file_list)
     expected_output = ['20120726022003.inp.zip', '20120726022003.out.zip']
     message = (
         'Expected this list:\n%s\nTo contain these items:\n%s' %
         (file_list, expected_output))
     for expected_file in expected_output:
         assert re.search(expected_file, file_list), message