Exemple #1
0
 def __init__(self):
     
     ###################################################################################
     # Looping construct
     # After that is done, we can enter our wait state for the arrival of new files.
     ###################################################################################
     
     # Display banner if in TEST Mode
     if settings.MODE == 'TEST':
         warningTxt = 'CAUTION: TEST MODE - This wipes DB Clean'
         fileutils.makeBlock(warningTxt)
         warningTxt = "CTRL-C or CTRL-Break to Stop - (waiting before startup, in case you don't want to wipe your existing db)"
         fileutils.makeBlock(warningTxt)
         # sleep for 10 seconds
         fileutils.sleep(1)
             
     # test if we are in debug and TEST Mode.  If so we clear out the DB every processing run, PROD mode need should never do this.
     if settings.DEBUG and settings.MODE == 'TEST':								# Only reset the DB in Test mode
         import postgresutils
         utils = postgresutils.Utils()
         utils.blank_database()    
     
     # setup logging
     if not os.path.exists(settings.LOGS):
         os.mkdir(settings.LOGS)
     else:
         if settings.DEBUG:
             print "Logs Directory exists:", settings.LOGS
     
     # command argument set's log level or Settings.py
     # ECJ20111117: removed command argument option and now only uses conf/settings.py
     #if len(sys.argv) > 1:
     #    level = sys.argv[1]
     
     debugMessages = Logger(settings.LOGGING_INI, settings.logging_level)
     if settings.DEBUG:
         debugMessages.log("Logging System Online", 0)
         
     try:
         if settings.DEBUG:
             print "Now instantiating FileHandler"
         FileHandler() 
         print "calling sys.exit"
         sys.exit
     
     except KeyboardInterrupt:
         print 'Stopping: KeyboardInterrupt at MainProcessor.py'
         # need to shutdown the logging system prior to program termination.  This is to flush buffers, send messages etc.	
         debugMessages.__quit__()
         sys.exit()
Exemple #2
0
 def ftp(self, pFiles):
     #processor = fileutils.FileUtilities(debug=debug, debugMessages=debugMessages)
     #processor = fileutils.FileUtilities()
     outputDir = self.settings['filelocations.outputlocation']#IGNORE:@UnusedVariable
     
     # login to FTP
     url = self.settings['%s_options.ftpxmlupload' % (self.systemMode)]
     uname = self.settings['%s_options.ftpuname' % (self.systemMode)]
     passwd = self.settings['%s_options.ftppwd' % (self.systemMode)]
     destdir = self.settings['%s_options.ftpdestdir' % (self.systemMode)]
     
     # SBB20071012 adding sleep and retries to the process
     ftpsleep = self.settings['options.ftpsleep']
     ftpretries = self.settings['options.ftpretries']
     ftpinitialsleep = self.settings['options.ftpinitialsleep']
     
     if self.debug:
         self.debugMessages.log('url: %s\n' % url, 1)
         self.debugMessages.log('uname: %s\n' % uname, 1)
         self.debugMessages.log('passwd: %s\n' % passwd, 1)
         self.debugMessages.log('destdir: %s\n' % destdir, 1)
     
     # connect to the server (Loop (ftpUploaded = True) until )
     attempt = 0
     ftpUploaded = False
     
     # SBB20100210 Adding an initial sleep (maybe the vpn is taking a while to establish the tunnel)
     fileutils.sleep(int(ftpinitialsleep))
     
     while not ftpUploaded:
         print "Connecting to: %s" % url
         attempt =+ 1
         print "Attempting FTP Process: %s" % (attempt)
         
         # check the number of retries, we can't do this all day. retries out
         if attempt > ftpretries:
             theError = (1090, 'FTP Process failed to upload file: %s.  Process timeout parm: %s and sleep parm: %s.  Please check the VPN Connection or the FTP Server at: %s' % (str(pFiles), ftpretries, ftpsleep, url), 'ftp(self)')
             raise FTPUploadFailureError, theError
         
         try:        
             f=ftplib.FTP(url, uname, passwd)
         except ftplib.all_errors:
             # sleep the process.  VPN/FTP happening too quickly
             self.debugMessages.log("General FTP Error.  Possibly process is happening too quickly.  Sleeping for %s seconds and trying again." % ftpsleep, 1)
             fileutils.sleep(int(ftpsleep))
             continue
         
         print "Connected"
         
         print 'Changing Directories to: %s' % destdir
         print f.cwd(destdir)
         
         if len(pFiles) > 0:
             for file in pFiles:
                 print 'Uploading file: %s' % file
                 fo = open(file, 'r')
                 fname = os.path.basename(file)
                 rc = f.storlines('STOR '+fname, fo)
         
                 if rc == '226 Transfer complete.':
                     # rename the file
                     self.renameFile(file, True)
                 else:
                     badFile = self.renameFile(file, False)
                     theError = (1080, 'FTP Error during upload of file: %s.  FTP Server returned: %s.  Stopping the upload process.  Please investigate and start the process again to complete the upload.  File was renamed to: %s' % (fname, rc, badFile), 'ftp(self)')
                     raise FTPUploadFailureError, rc    
                     print 'Done uploading files'
                     
                     fo.close()
         
         ftpUploaded = True
         
         
         break
         
     # Close FTP connection
     # Echo the result of the close command
     print f.close()
     print 'FTP Processing Completed, disconnected'
     return 0