Beispiel #1
0
    def getLatestEventId(self):
        """Query the ftp server and determine the latest event id.

        Args: None

        Returns: A string containing a valid event id.

        Raises: NetworkError
        """
        myFtpClient = FtpClient()
        try:
            myList = myFtpClient.getListing()
            myList.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
            ))
        myEventId = now + 1
        while int(myEventId) > now:
            if len(myList) < 1:
                raise EventIdError('Latest Event Id could not be obtained')
            myEventId = myList.pop().split('/')[-1].split('.')[0]

        if myEventId is None:
            raise EventIdError('Latest Event Id could not be obtained')
        self.eventId = myEventId
Beispiel #2
0
 def testGetFile(self):
     """Test that the ftp client can fetch a file ok"""
     myClient = FtpClient()
     myListing = myClient.getListing()
     #Make it a single string
     myListing = '\n'.join(myListing)
     myMessage = ('Expected outcome:\n%s\nActual outcome:\n%s' %
                   (myListing, self._expectedMatches))
     for myExpectedFile in self._expectedMatches:
         assert re.search(myExpectedFile, myListing), myMessage
Beispiel #3
0
 def testGetDirectoryListing(self):
     """Check if we can get a nice directory listing"""
     myClient = FtpClient()
     myListing = myClient.getListing()
     #Make it a single string
     myListing = '\n'.join(myListing)
     myMessage = ('Expected this list:\n%s\nTo contain these items:\n%s' %
                   (myListing, self._expectedMatches))
     for myExpectedFile in self._expectedMatches:
         assert re.search(myExpectedFile, myListing), myMessage
Beispiel #4
0
 def testGetFile(self):
     """Test that the ftp client can fetch a file ok"""
     myClient = FtpClient()
     myListing = myClient.getListing()
     #Make it a single string
     myListing = '\n'.join(myListing)
     myMessage = ('Expected outcome:\n%s\nActual outcome:\n%s' %
                  (myListing, self._expectedMatches))
     for myExpectedFile in self._expectedMatches:
         assert re.search(myExpectedFile, myListing), myMessage
Beispiel #5
0
 def testGetDirectoryListing(self):
     """Check if we can get a nice directory listing"""
     myClient = FtpClient()
     myListing = myClient.getListing()
     #Make it a single string
     myListing = '\n'.join(myListing)
     myMessage = ('Expected this list:\n%s\nTo contain these items:\n%s' %
                  (myListing, self._expectedMatches))
     for myExpectedFile in self._expectedMatches:
         assert re.search(myExpectedFile, myListing), myMessage
Beispiel #6
0
    def getLatestEventId(self):
        """Query the ftp server and determine the latest event id.

        Args: None

        Returns: A string containing a valid event id.

        Raises: NetworkError
        """
        myFtpClient = FtpClient()
        try:
            myList = myFtpClient.getListing()
        except NetworkError:
            raise
        myEventId = myList[-1].split('/')[-1].split('.')[0]
        if myEventId is None:
            raise EventIdError('Latest Event Id could not be obtained')
        self.eventId = myEventId
Beispiel #7
0
    def getLatestEventId(self):
        """Query the ftp server and determine the latest event id.

        Args: None

        Returns: A string containing a valid event id.

        Raises: NetworkError
        """
        myFtpClient = FtpClient()
        try:
            myList = myFtpClient.getListing()
        except NetworkError:
            raise
        myEventId = myList[-1].split('/')[-1].split('.')[0]
        if myEventId is None:
            raise EventIdError('Latest Event Id could not be obtained')
        self.eventId = myEventId
Beispiel #8
0
    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
            myEvent = myEvent.replace('ftp://118.97.83.243/', '')
            myEvent = myEvent.replace('.out.zip', '')
            print 'Processing %s' % myEvent
            try:
                processEvent(myEvent, myLocale)
            except:  # pylint: disable=W0702
                LOGGER.exception('Failed to process %s' % myEvent)
        sys.exit(0)
    else:
        processEvent(myEventId, myLocale)

else:
Beispiel #9
0
    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
            myEvent = myEvent.replace('ftp://118.97.83.243/', '')
            myEvent = myEvent.replace('.out.zip', '')
            print 'Processing %s' % myEvent
            # noinspection PyBroadException
            try:
                processEvent(myEvent, myLocale)
            except:  # pylint: disable=W0702
                LOGGER.exception('Failed to process %s' % myEvent)
        sys.exit(0)
    else:
        processEvent(myEventId, myLocale)