Пример #1
0
    def test_download_path(self):
        """Test to download all directories and files under a path
        """
        my_ssh_client = SFtpClient(the_working_dir='shakemaps')
        assert (my_ssh_client is not None)

        remote_path = os.path.join(my_ssh_client.sftp.getcwd(),
                                   '20130113003746/output/grid.xml')
        local_path = '/tmp/inasafe/'
        print local_path
        my_ssh_client.download_path(remote_path, local_path)
Пример #2
0
    def __init__(self,
                 theEvent=None,
                 theHost=defaultHost,
                 theUserName=defUserName,
                 thePassword=defPassword,
                 theWorkingDir=defWorkDir,
                 theForceFlag=False):
        """Constructor for the SftpShakeData class
            Args:
                * theEvent - (Optional) a string representing the event id
                  that this raster is associated with. e.g. 20110413170148.
                  **If no event id is supplied, a query will be made to the
                  ftp server, and the latest event id assigned.**
                * theHost - (Optional) a string representing the ip address
                  or host name of the server from which the data should be
                  retrieved. It assumes that the data is in the root directory.

            Returns:
                None

            Raises:
                None

        """
        self.eventId = theEvent
        self.host = theHost
        self.username = theUserName
        self.password = thePassword
        self.workdir = theWorkingDir
        self.forceFlag = theForceFlag
        self.sftpclient = SFtpClient(self.host, self.username, self.password,
                                     self.workdir)

        if self.eventId is None:
            try:
                self.getLatestEventId()
            except NetworkError:
                raise
        else:
            # If we fetched it above using getLatestEventId we assume it is
            # already validated.
            try:
                self.validateEvent()
            except EventValidationError:
                raise
            # If eventId is still None after all the above, moan....
        if self.eventId is None:
            myMessage = ('No id was passed to the constructor and the '
                         'latest id could not be retrieved from the'
                         'server.')
            LOGGER.exception('ShakeData initialisation failed')
            raise EventIdError(myMessage)
Пример #3
0
    def __init__(self,
                 event=None,
                 host=default_host,
                 user_name=def_user_name,
                 password=def_password,
                 working_dir=def_work_dir,
                 force_flag=False):
        """Constructor for the SftpShakeData class
        :param event: (Optional) a string representing the event id
                  that this raster is associated with. e.g. 20110413170148.
                  **If no event id is supplied, a query will be made to the
                  ftp server, and the latest event id assigned.**
        :param host: (Optional) a string representing the ip address
                  or host name of the server from which the data should be
                  retrieved. It assumes that the data is in the root directory.
        """
        self.event_id = event
        self.host = host
        self.username = user_name
        self.password = password
        self.workdir = working_dir
        self.force_flag = force_flag
        self.sftpclient = SFtpClient(self.host, self.username, self.password,
                                     self.workdir)

        if self.event_id is None:
            try:
                self.get_latest_event_id()
            except NetworkError:
                raise
        else:
            # If we fetched it above using get_latest_event_id we assume it is
            # already validated.
            try:
                self.validate_event()
            except EventValidationError:
                raise
            # If event_id is still None after all the above, moan....
        if self.event_id is None:
            message = ('No id was passed to the constructor and the '
                       'latest id could not be retrieved from the'
                       'server.')
            LOGGER.exception('ShakeData initialisation failed')
            raise EventIdError(message)
Пример #4
0
 def reconnectSFTP(self):
     """Reconnect to the server
     """
     self.sftpclient = SFtpClient(self.host, self.username, self.password,
                                  self.workdir)
Пример #5
0
if 'INASAFE_LOCALE' in os.environ:
    myLocale = os.environ['INASAFE_LOCALE']
else:
    myLocale = 'en'

if len(sys.argv) > 2:
    sys.exit('Usage:\n%s [optional shakeid]\nor\n%s --list' % (
        sys.argv[0], sys.argv[0]))
elif len(sys.argv) == 2:
    print('Processing shakemap %s' % sys.argv[1])

    myEventId = sys.argv[1]
    if myEventId in '--list':
#        myFtpClient = FtpClient()
        mySftpClient = SFtpClient()
#        myListing = myFtpClient.getListing()
        myListing = mySftpClient.getListing(my_func=is_event_id)
        for myEvent in myListing:
            print myEvent
        sys.exit(0)
    elif myEventId in '--run-all':
        #
        # Caution, this code path gets memory leaks, use the
        # batch file approach rather!
        #
        myFtpClient = FtpClient()
        myListing = myFtpClient.getListing()
        for myEvent in myListing:
            if 'out' not in myEvent:
                continue
Пример #6
0
 def test_get_list_events(self):
     """Test to get all event ids
     """
     my_ssh_client = SFtpClient()
     assert (my_ssh_client is not None)
Пример #7
0
if 'INASAFE_LOCALE' in os.environ:
    my_locale = os.environ['INASAFE_LOCALE']
else:
    my_locale = 'en'

if len(sys.argv) > 2:
    sys.exit('Usage:\n%s [optional shakeid]\nor\n%s --list' %
             (sys.argv[0], sys.argv[0]))
elif len(sys.argv) == 2:
    print('Processing shakemap %s' % sys.argv[1])

    my_event_id = sys.argv[1]
    if my_event_id in '--list':
        #        ftp_client = FtpClient()
        sftp_client = SFtpClient()
        #        myListing = ftp_client.get_listing()
        dir_listing = sftp_client.get_listing(my_func=is_event_id)
        for event in dir_listing:
            print event
        sys.exit(0)
    elif my_event_id in '--run-all':
        #
        # Caution, this code path gets memory leaks, use the
        # batch file approach rather!
        #
        ftp_client = FtpClient()
        dir_listing = ftp_client.get_listing()
        for event in dir_listing:
            if 'out' not in event:
                continue