Ejemplo n.º 1
0
 def run(self):
     status = Utility.readMessageQueue(self.orders)
     if status == Utility.QMSG_HANDLE:
         oldList = []
         # pull the old list from disk, if it exists
         if os.path.isfile(self.listFileName):
             f = open(self.listFileName, 'r')
             for line in f:
                 oldList.append(line[:-1]) #ignore '/n' when read in
             f.close()
         # compare to current directory
         currentList = self.getDirectoryList(self.directoryName)
         listToUpload = self.getListDifference(oldList, currentList)
         renamedList = []
         for element in listToUpload:
             renamedList.append(self.renameWithTimestamp(element))
         if len(listToUpload) != 0:
             self.exitMessage = Utility.QMSG_UPLOAD_DONE
             f = open(self.listFileName, 'a')
             for element in renamedList:  
                 self.enqueue(element) # rename and submit the renamed image name
                 f.write(element + '\n')
             f.close()
             uploaderProcess = Process(target = self.startUploader)
             self.uploadOrders.put(Utility.QMSG_UPLOAD)
             uploaderProcess.start()
             
             self.orders.put(Utility.QMSG_UPLOAD)
             # then enqueued, wait for uploader to finish
             uploaderProcess.join()
         else:
             self.exitMessage = Utility.QMSG_HANDLE_NONE
         
     # once uploader done, exit/send a message to supervisor "done" and then exit
     self.orders.put(self.exitMessage)
Ejemplo n.º 2
0
 def __init__(self, orderQueue):
     config = Utility.getProjectConfig()
     # Extract relevant config data
     self.directoryName = config.get('directories', 'imagedirectory')
     self.orders = orderQueue
     self.uploadOrders = Queue()
     self.queue = Queue()
     self.listFileName = Utility.UPLOADS_FILE_NAME
     self.exitMessage = ""
Ejemplo n.º 3
0
 def __init__(self, orderQueue):
     config = Utility.getProjectConfig()
     # Extract relevant config data
     self.directoryName = config.get('directories', 'imagedirectory')
     self.orders = orderQueue
     self.uploadOrders = Queue()
     self.queue = Queue()
     self.listFileName = Utility.UPLOADS_FILE_NAME
     self.exitMessage = ""
Ejemplo n.º 4
0
 def run(self):
     print "Hi, I'm an Uploader!"
     print "Uploader, checking in! pid:", os.getpid()
     #         while self.orders.empty(): # wait for an order from Handler to start
     #             time.sleep(1)
     #         # require that Handler tell uploader to QMSG_UPLOAD
     #         handlerMsg = self.orders.get()
     status = Utility.readMessageQueue(self.orders)
     if status == Utility.QMSG_UPLOAD:
         self.uploadBatch()
     self.orders.put(Utility.QMSG_UPLOAD_DONE)  # tell Handler we're done
     print "Uploader is exiting."
     # Put actual cleanup/saving code here!
     print "Uploader successfully exited."
Ejemplo n.º 5
0
    def run(self):
        print "Hi, I'm an Uploader!"
        print "Uploader, checking in! pid:", os.getpid()
#         while self.orders.empty(): # wait for an order from Handler to start
#             time.sleep(1)
#         # require that Handler tell uploader to QMSG_UPLOAD
#         handlerMsg = self.orders.get()     
        status = Utility.readMessageQueue(self.orders)
        if status == Utility.QMSG_UPLOAD:
            self.uploadBatch() 
        self.orders.put(Utility.QMSG_UPLOAD_DONE) # tell Handler we're done
        print "Uploader is exiting."
        # Put actual cleanup/saving code here!
        print "Uploader successfully exited."
Ejemplo n.º 6
0
 def run(self):
     print "Hi, I'm a Reader!"
     status = Utility.readMessageQueue(self.myOrders)
     print "READER DEBUG:", status
     try:
         if status == Utility.QMSG_SCAN:
             camera_filenames_to_file(Utility.NEW_PICS_FILE_NAME)
             downloadNewImages(fileNameOld=Utility.OLD_PICS_FILE_NAME, fileNameNew=Utility.NEW_PICS_FILE_NAME)
             os.rename(Utility.NEW_PICS_FILE_NAME, Utility.OLD_PICS_FILE_NAME)
             self.myOrders.put(Utility.QMSG_SCAN_DONE)
     except Exception as e:
         print e
         self.myOrders.put(Utility.QMSG_SCAN_FAIL)
     print "Reader is exiting."
     print "Reader successfully exited."
Ejemplo n.º 7
0
    def __init__(self, q=None, orderQueue=None):
        if q is None:
            raise Exception('Uploader.__init__():  missing parameter')
        if not isinstance(q, multiprocessing.queues.Queue):
            raise Exception('Uploader.__init__():  parameter not of type ""')

        self.queue = q
        self.orders = orderQueue
        config = Utility.getProjectConfig()
        # Extract relevant config data
        inputKey = config.get("dropboxinfo", "key")
        inputSecret = config.get("dropboxinfo", "secret")
        inputAccessToken = config.get("dropboxinfo", "accesstoken")
        self.directoryName = config.get('directories', 'imagedirectory')
        os.chdir(self.directoryName)
        # INSERT DROPBOX DATA FROM CONFIG HERE
        self.myKey = inputKey
        self.mySecret = inputSecret
        self.myAccessToken = inputAccessToken
        self.myClient = None
        self.clientAccountInfo = None
        self.setApp(inputKey, inputSecret)
        self.setAccessToken(inputAccessToken)
        self.setClient()
Ejemplo n.º 8
0
    def run(self):
        status = Utility.readMessageQueue(self.orders)
        if status == Utility.QMSG_HANDLE:
            oldList = []
            # pull the old list from disk, if it exists
            if os.path.isfile(self.listFileName):
                f = open(self.listFileName, 'r')
                for line in f:
                    oldList.append(line[:-1])  #ignore '/n' when read in
                f.close()
            # compare to current directory
            currentList = self.getDirectoryList(self.directoryName)
            listToUpload = self.getListDifference(oldList, currentList)
            renamedList = []
            for element in listToUpload:
                renamedList.append(self.renameWithTimestamp(element))
            if len(listToUpload) != 0:
                self.exitMessage = Utility.QMSG_UPLOAD_DONE
                f = open(self.listFileName, 'a')
                for element in renamedList:
                    self.enqueue(
                        element)  # rename and submit the renamed image name
                    f.write(element + '\n')
                f.close()
                uploaderProcess = Process(target=self.startUploader)
                self.uploadOrders.put(Utility.QMSG_UPLOAD)
                uploaderProcess.start()

                self.orders.put(Utility.QMSG_UPLOAD)
                # then enqueued, wait for uploader to finish
                uploaderProcess.join()
            else:
                self.exitMessage = Utility.QMSG_HANDLE_NONE

        # once uploader done, exit/send a message to supervisor "done" and then exit
        self.orders.put(self.exitMessage)
Ejemplo n.º 9
0
 def __init__(self, q=None, orderQueue = None):
     if q is None:
         raise Exception('Uploader.__init__():  missing parameter')
     if not isinstance(q, multiprocessing.queues.Queue):
         raise Exception('Uploader.__init__():  parameter not of type ""')
 
     self.queue = q
     self.orders = orderQueue
     config = Utility.getProjectConfig()
     # Extract relevant config data
     inputKey = config.get("dropboxinfo", "key")
     inputSecret = config.get("dropboxinfo", "secret")
     inputAccessToken = config.get("dropboxinfo", "accesstoken")
     self.directoryName = config.get('directories', 'imagedirectory')
     os.chdir(self.directoryName)
     # INSERT DROPBOX DATA FROM CONFIG HERE
     self.myKey = inputKey
     self.mySecret = inputSecret
     self.myAccessToken = inputAccessToken
     self.myClient = None
     self.clientAccountInfo = None
     self.setApp(inputKey, inputSecret)
     self.setAccessToken(inputAccessToken)
     self.setClient()
Ejemplo n.º 10
0
 def run(self):
     print "Supervisor, checking in! pid:", os.getpid()
     # If image directory does not exist yet, create it!
     config = Utility.getProjectConfig()
     imgdir = config.get('directories','imagedirectory')
     print imgdir
     if not os.path.isdir(imgdir):
         try:
             os.makedirs(imgdir)
         except OSError as exception:
             if exception.errno != errno.EEXIST:
                 raise
     guiProcess = Process(target = self.startGUI)
     guiProcess.start()
     # Establish whether we have stable internet
     stableInternetCounter = 0
     stableInternet = False  
     for i in range(Utility.STABLE_INTERNET_COUNT):
         if Utility.checkInternetConnection():
             stableInternetCounter += 1
     if (stableInternetCounter >= Utility.STABLE_INTERNET_COUNT):
         self.statusQueue.put(Utility.QMSG_IDLE)
         stableInternet = True
     else:
         self.statusQueue.put(Utility.QMSG_INTERNET_NO)
         stableInternet = False
     # Initialize with all images currently on camera
     self.statusQueue.put(Utility.QMSG_SCAN)
     initialScanFail = True
     try:
         Reader.camera_filenames_to_file(Utility.OLD_PICS_FILE_NAME)
         self.statusQueue.put(Utility.QMSG_SCAN_DONE)
         initialScanFail = False
     except:
         self.statusQueue.put(Utility.QMSG_SCAN_FAIL)
         initialScanFail = True
     time.sleep(Utility.POLL_TIME)
     handlerProcess = None
     handlerDelayed = False
     readerProcess = None
     while True:
         if not self.guiQueue.empty():
             job = self.guiQueue.get()
             if job == Utility.QMSG_START:
                 if initialScanFail:
                     try: # OH GOD PLEASE REFACTOR THIS DUPLICATED CODE !!!!!!!!!!!!!!
                         Reader.camera_filenames_to_file(Utility.OLD_PICS_FILE_NAME)
                         self.statusQueue.put(Utility.QMSG_SCAN_DONE)
                         initialScanFail = False
                     except:
                         self.statusQueue.put(Utility.QMSG_SCAN_FAIL)
                         initialScanFail = True
                     continue # cannot complete job as normal if no baseline scan
                     # REFACTOR THIS CODE, DON'T FORGET! try Supervisor.initialScan()
                 print "Supervisor handles Upload job here"
                 readerProcess = Process(target = self.startReader)
                 self.readerQueue.put(Utility.QMSG_SCAN)
                 self.statusQueue.put(Utility.QMSG_SCAN)
                 readerProcess.start()
                 # wait for reader to finish scanning
                 readerProcess.join()
                 scanMsg = Utility.readMessageQueue(self.readerQueue)
                 if scanMsg == Utility.QMSG_SCAN_FAIL:
                     self.statusQueue.put(Utility.QMSG_SCAN_FAIL)
                     scanMsg = 0 
                     continue # failed, tell GUI but ignore the rest of this job
                 elif scanMsg == Utility.QMSG_SCAN_DONE:
                     self.statusQueue.put(Utility.QMSG_SCAN_DONE)
                     scanMsg = 0
                 else:
                     print "Something went wrong with the ReaderMsgQueue!"
                 if stableInternet: # only start Handler if stable connection
                     handlerProcess = Process(target = self.startHandler)
                     self.handlerQueue.put(Utility.QMSG_HANDLE)
                     handlerProcess.start()
                     handlerDelayed = False
                 else:
                     time.sleep(Utility.POLL_TIME)
                     self.statusQueue.put(Utility.QMSG_INTERNET_NO)
                     handlerDelayed = True
             elif job == Utility.QMSG_SETTINGS:
                 print "Supervisor handles Settings job here if needed"
             else:
                 raise Exception('Supervisor.run:  unexpected object in queue')
         # endif self.guiQueue.empty()
         
         # Start upload if delayed and internet is now stable
         if handlerDelayed and stableInternet:
             handlerProcess = Process(target = self.startHandler)
             self.handlerQueue.put(Utility.QMSG_HANDLE)
             handlerProcess.start()
             handlerDelayed = False   
         
         time.sleep(Utility.POLL_TIME) # wait for handlerProcess to actually start
         if not self.handlerQueue.empty():
             handlerMsg = Utility.readMessageQueue(self.handlerQueue) 
             if handlerMsg == Utility.QMSG_UPLOAD:
                 self.statusQueue.put(Utility.QMSG_UPLOAD) 
             elif handlerMsg == Utility.QMSG_UPLOAD_DONE:
                 self.statusQueue.put(Utility.QMSG_UPLOAD_DONE)
             elif handlerMsg == Utility.QMSG_HANDLE_NONE:
                 self.statusQueue.put(Utility.QMSG_HANDLE_NONE)
             else:
                 self.statusQueue.put("Unknown Message from handlerQueue")
         
         # Check current internet connection, allowing for some fluctuation in results
         if Utility.checkInternetConnection():
             if stableInternetCounter < Utility.STABLE_INTERNET_COUNT:
                 stableInternetCounter += 1
             else:
                 stableInternet = True
                 self.statusQueue.put(Utility.QMSG_INTERNET_YES)
             #print 'DEBUG: checkInternetConnection() == True'
         else:
             if (stableInternetCounter > 0): # only count down to 0
                 stableInternetCounter -= 1 
             if stableInternetCounter < Utility.STABLE_INTERNET_COUNT/2:
                 stableInternet = False
                 self.statusQueue.put(Utility.QMSG_INTERNET_NO)
             #print 'DEBUG: checkInternetConnection() == False'
         print 'DEBUG: stableInternet:', stableInternet, 'stableInternetCounter:', stableInternetCounter    
     
         time.sleep(Utility.POLL_TIME)
Ejemplo n.º 11
0
 def __init__(self, orders):
     config = Utility.getProjectConfig()
     self.myOrders = orders
     # Extract relevant config data
     self.directoryName = config.get('directories', 'imagedirectory')
     os.chdir(self.directoryName)