def handle_input(self, event):
     """
     Checks if the event is a QUIT or a K_ESCAPE.
     Then, requests the engine to exit.
     :param event: The event to parse.
     """
     if event.type == QUIT:
         Engine.request_exit()
     if event.type == KEYDOWN:
         if event.key == K_ESCAPE:
             Engine.request_exit()
 def retrieveStatus(self):
     logging.debug("watchRetrieveStatus(): instantiated")
     self.statusLabel.set_text("Querying VirtualBox Service...")
     e = Engine.getInstance()
     #execute refresh command
     logging.debug("watchRetrieveStatus(): running: vm-manage refresh")
     e.execute("vm-manage refresh")
     #will check status every 1 second until refresh command is finished
     while (True):
         self.status = e.execute("vm-manage mgrstatus")
         logging.debug("watchRetrieveStatus(): result: " + str(self.status))
         if self.status["mgrStatus"][
                 "readStatus"] != VMManage.MANAGER_IDLE or (
                     self.status["mgrStatus"]["writeStatus"] !=
                     VMManage.MANAGER_IDLE
                     and self.status["mgrStatus"]["writeStatus"] !=
                     VMManage.MANAGER_UNKNOWN):
             GLib.idle_add(self.setGUIStatus, "Reading VM Status", None,
                           None)
         else:
             GLib.idle_add(self.setGUIStatus, "Retrieval Complete", False,
                           True)
             break
         sleep(1)
     logging.debug("watchRetrieveStatus(): thread ending")
Example #3
0
 def configureStatus(self):
     logging.debug("configureStatus(): instantiated")
     self.statusLabel.set_text("Configuring through VirtualBox service...")
     e = Engine.getInstance()
     #execute refresh command
     logging.debug("configureStatus(): running: vm-manage config " +
                   self.vmName + " " + self.localIP + " " + self.remoteIP +
                   " " + self.octetLocal + " " + self.octetLocal + " " +
                   self.adaptorNum + " " + self.connectionName)
     e.execute("vm-manage config " + self.vmName + " " + self.localIP +
               " " + self.remoteIP + " " + self.octetLocal + " " +
               self.octetLocal + " " + self.adaptorNum + " " +
               self.connectionName)
     #will check status every 1 second until refresh command is finished
     while (True):
         self.status = e.execute("vm-manage mgrstatus")
         logging.debug("configureStatus(): result: " + str(self.status))
         if self.status["mgrStatus"][
                 "readStatus"] != VMManage.MANAGER_IDLE or (
                     self.status["mgrStatus"]["writeStatus"] !=
                     VMManage.MANAGER_IDLE
                     and self.status["mgrStatus"]["writeStatus"] !=
                     VMManage.MANAGER_UNKNOWN):
             GLib.idle_add(self.setGUIStatus, "Configuring VM...", None,
                           None)
         else:
             GLib.idle_add(self.setGUIStatus, "Configuration Complete",
                           False, True)
             break
         sleep(1)
     logging.debug("configureStatus(): thread ending")
    def watchStatus(self, control):
        logging.debug("watchDisconnStatus(): instantiated")
        #self.statusLabel.set_text("Checking connection")
        e = Engine.getInstance()
        #will check status every 1 second and will either display stopped or ongoing or connected
        #while(self.QUIT_SIGNAL == False):
        while not control.is_set():
            logging.debug("watchDisconnStatus(): running: pptp status " + ConnectionBox.CONNECTION_NAME)
            self.status = e.execute("pptp status " + ConnectionBox.CONNECTION_NAME)
            #connStatus" : self.connStatus, "disConnStatus" : self.disConnStatus, "refreshConnStatus
            if self.status != -1 and self.status["connStatus"] != Connection.CONNECTING and self.status["disConnStatus"] != Connection.DISCONNECTING and self.status["refreshConnStatus"] != Connection.REFRESHING:
                logging.debug("watchDisconnStatus(): running: pptp forcerefreshconnstatus  " + ConnectionBox.CONNECTION_NAME)
                self.status = e.execute("pptp forcerefreshconnstatus " + ConnectionBox.CONNECTION_NAME)
                #wait until it's done refreshing
                self.status = e.execute("pptp status " + ConnectionBox.CONNECTION_NAME)
                while self.status["refreshConnStatus"] == Connection.REFRESHING:
                    sleep(2)
                    self.status = e.execute("pptp status " + ConnectionBox.CONNECTION_NAME)
                #read the new state
                logging.debug("watchDisconnStatus(): running: pptp status " + ConnectionBox.CONNECTION_NAME)
                self.status = e.execute("pptp status " + ConnectionBox.CONNECTION_NAME)

                logging.debug("watchStatus(): result: " + str(self.status))
                if self.status["connStatus"] == Connection.NOT_CONNECTED or self.status["connStatus"] == Connection.CONNECTED:
                    GLib.idle_add(self.setGUIStatus, self.status)
                    #break
                else:
                    logging.debug("watchStatus(): Could not get status: " + str(self.status))
                #break
            sleep(5)
    def vmActionStatus(self):
        logging.debug("vmActionStatus(): instantiated")

        self.statusLabel.set_text("Executing " + self.vmAction + " on VM: " +
                                  self.vmName + "...")
        e = Engine.getInstance()
        #execute refresh command
        logging.debug("vmActionStatus(): running: vm-manage " + self.vmAction +
                      " " + self.vmName)
        e.execute("vm-manage " + self.vmAction + " " + self.vmName)
        #will check status every 1 second until refresh command is finished
        while (True):
            self.status = e.execute("vm-manage mgrstatus")
            logging.debug("vmActionStatus(): result: " + str(self.status))
            if self.status["mgrStatus"][
                    "readStatus"] != VMManage.MANAGER_IDLE or (
                        self.status["mgrStatus"]["writeStatus"] !=
                        VMManage.MANAGER_IDLE
                        and self.status["mgrStatus"]["writeStatus"] !=
                        VMManage.MANAGER_UNKNOWN):
                GLib.idle_add(self.setGUIStatus,
                              "Executing VM " + self.vmAction + "...", None,
                              None)
            else:
                GLib.idle_add(self.setGUIStatus, "Complete", False, True)
                break
            sleep(1)
        logging.debug("configureStatus(): thread ending")
Example #6
0
 def catchClosing(self, widget, event):
     logging.debug("delete_event(): instantiated")
     e = Engine.getInstance()
     res = e.execute("pptp status " + ConnectionBox.CONNECTION_NAME)
     logging.debug("delete_event(): result: " + str(res))
     if res == -1:
         self.destroy()
         #continue with any other destruction
         logging.debug("catchClosing(): returning False")
         return False
     result = res["connStatus"]
     if result == Connection.NOT_CONNECTED:
         self.destroy()
         #continue with any other destruction
         logging.debug("catchClosing(): returning False")
         return False
     if result == Connection.CONNECTING:
         closingDialog = Gtk.MessageDialog(
             self, 0, Gtk.MessageType.WARNING, Gtk.ButtonsType.OK,
             "Cannot quit, connection is busy...")
         closingDialog.run()
         closingDialog.destroy()
     elif result == Connection.CONNECTED:
         closingDialog = Gtk.MessageDialog(self, 0, Gtk.MessageType.WARNING,
                                           Gtk.ButtonsType.OK_CANCEL,
                                           "Quit and close connection?")
         response = closingDialog.run()
         closingDialog.destroy()
         if response == Gtk.ResponseType.OK:
             logging.debug("delete_event(): opening disconnect dialog")
             #need to create a thread (probably a dialog box with disabled ok button until connection either times out (5 seconds), connection good
             e = Engine.getInstance()
             e.execute("pptp stop " + ConnectionBox.CONNECTION_NAME)
             disconnectingDialog = DisconnectingDialog(
                 self, ConnectionBox.CONNECTION_NAME)
             disconnectingDialog.run()
             s = disconnectingDialog.getFinalStatus()
             disconnectingDialog.destroy()
             if s["connStatus"] == Connection.NOT_CONNECTED:
                 self.destroy()
             else:
                 cannotCloseDialog = Gtk.MessageDialog(
                     self, 0, Gtk.MessageType.WARNING,
                     Gtk.ButtonsType.OK_CANCEL,
                     "Could not close connection, try again later.")
     logging.debug("catchClosing(): returning True")
     return True
 def attemptDisconnect(self):
     logging.debug("attemptDisconnect(): initiated")
     #need to create a thread (probably a dialog box with disabled ok button until connection either times out (5 seconds), connection good
     e = Engine.getInstance()
     e.execute("pptp stop " + ConnectionBox.CONNECTION_NAME)
     disconnectingDialog = DisconnectingDialog(self.parent, ConnectionBox.CONNECTION_NAME)
     disconnectingDialog.run()
     s = disconnectingDialog.getFinalStatus()
     disconnectingDialog.destroy()
     return s
 def attemptLogin(self, serverIP, username, password):
     logging.debug("attemptLogin(): initiated")
     #need to create a thread (probably a dialog box with disabled ok button until connection either times out (5 seconds), connection good
     e = Engine.getInstance()
     e.execute("pptp start " + ConnectionBox.CONNECTION_NAME + " " + serverIP + " " + username + " " + password)
     loginConnectingDialog = LoginConnectingDialog(self.parent, ConnectionBox.CONNECTION_NAME)
     loginConnectingDialog.run()
     s = loginConnectingDialog.getFinalStatus()
     loginConnectingDialog.destroy()
     return s
 def run(self):
     logging.debug("WatchRetrieveThread(): instantiated")
     self.watchsignal.emit("Querying Broker Service...", None, None)
     try:
         e = Engine.getInstance()
         logging.debug("watchRetrieveStatus(): running: conns refresh")
         #e.execute("conns refresh")
         if len(self.args) != 5:
             logging.error(
                 "WatchActioningThread(): invalid number of args for create connections. Skipping..."
             )
             self.watchsignal.emit(
                 "Invalid number of args for create connections. Skipping...",
                 self.status, True)
             self.status = -1
             return None
         #format: "conns refresh <ip> <user> <pass> <path> <method>"
         cmd = "conns " + " refresh " + str(self.args[0]) + " " + str(
             self.args[1]) + " " + str(self.args[2]) + " " + str(
                 self.args[3]) + " " + str(self.args[4])
         e.execute(cmd)
         #will check status every 0.5 second and will either display stopped or ongoing or connected
         dots = 1
         while (True):
             logging.debug("watchRetrieveStatus(): running: conns refresh")
             self.status = e.execute("conns status")
             logging.debug("watchRetrieveStatus(): result: " +
                           str(self.status))
             if self.status[
                     "writeStatus"] != ConnectionManage.CONNECTION_MANAGE_IDLE:
                 dotstring = ""
                 for i in range(1, dots):
                     dotstring = dotstring + "."
                 self.watchsignal.emit("Reading Conn Status" + dotstring,
                                       self.status, None)
                 dots = dots + 1
                 if dots > 4:
                     dots = 1
             else:
                 break
             time.sleep(0.5)
         logging.debug("WatchRetrieveThread(): thread ending")
         self.watchsignal.emit("Retrieval Complete", self.status, True)
         return
     except:
         logging.error("Error in WatchRetrieveThread(): An error occured ")
         exc_type, exc_value, exc_traceback = sys.exc_info()
         traceback.print_exception(exc_type, exc_value, exc_traceback)
         self.watchsignal.emit("Error retrieving Conns.", None, True)
         self.status = -1
         return None
     finally:
         return None
Example #10
0
 def run(self):
     logging.debug("WatchRetrieveThread(): instantiated")
     self.watchsignal.emit("Querying VirtualBox Service...", None, None)
     try:
         e = Engine.getInstance()
         logging.debug("watchRetrieveStatus(): running: vm-manage refresh")
         e.execute("vm-manage refresh")
         #will check status every 0.5 second and will either display stopped or ongoing or connected
         dots = 1
         while (True):
             logging.debug(
                 "watchRetrieveStatus(): running: vm-manage refresh")
             self.status = e.execute("vm-manage mgrstatus")
             logging.debug("watchRetrieveStatus(): result: " +
                           str(self.status))
             if self.status["writeStatus"] != VMManage.MANAGER_IDLE:
                 dotstring = ""
                 for i in range(1, dots):
                     dotstring = dotstring + "."
                 self.watchsignal.emit("Reading VM Status" + dotstring,
                                       self.status, None)
                 dots = dots + 1
                 if dots > 4:
                     dots = 1
             else:
                 break
             time.sleep(0.5)
         logging.debug("WatchRetrieveThread(): thread ending")
         self.watchsignal.emit("Retrieval Complete", self.status, True)
         return
     except FileNotFoundError:
         logging.error("Error in ExperimentRemoveThread(): File not found")
         exc_type, exc_value, exc_traceback = sys.exc_info()
         traceback.print_exception(exc_type, exc_value, exc_traceback)
         self.watchsignal.emit(
             "Error retrieving VMs. Check your paths and permissions.",
             None, True)
         self.status = -1
         return None
     except:
         logging.error(
             "Error in ExperimentRemoveThread(): An error occured ")
         exc_type, exc_value, exc_traceback = sys.exc_info()
         traceback.print_exception(exc_type, exc_value, exc_traceback)
         self.watchsignal.emit(
             "Error retrieving VMs. Check your paths and permissions.",
             None, True)
         self.status = -1
         return None
     finally:
         return None
 def watchDisconnStatus(self):
     logging.debug("watchDisconnStatus(): instantiated")
     self.statusLabel.set_text("Checking connection")
     e = Engine.getInstance()
     #will check status every 1 second and will either display stopped or ongoing or connected
     while(True):
         logging.debug("watchDisconnStatus(): running: pptp status " + self.connName)
         self.status = e.execute("pptp status " + self.connName)
         logging.debug("watchConnStatus(): result: " + str(self.status))
         if self.status["connStatus"] == Connection.DISCONNECTING:
             GLib.idle_add(self.setGUIStatus, "Disconnecting...", None, None)
         elif self.status["connStatus"] == Connection.NOT_CONNECTED:
             GLib.idle_add(self.setGUIStatus, "Connection Disconnected.", False, True)
             break
         else:
             GLib.idle_add(self.setGUIStatus, "Could not disconnect", False, True)
             break
         sleep(1)
Example #12
0
class IntelligentCamera:
    def __init__(self, options):
        self.options = options
        self.engine = Engine()

    def run(self):
        images = self.findImages()

        self.classifyImages(images)

    def findImages(self):
        images = []
        for directoryName, subdirectoryList, fileList in os.walk(self.options['input']):
            for fileName in fileList:
                path = os.path.join(directoryName, fileName)
                if isValidImage(path):
                    logger.info("Found image to process '" + path + "'")
                    images.append(path)

        return images

    def classifyImages(self, imagePaths):
        images = [Image.open(imagePath) for imagePath in imagePaths]

        results = self.engine.run(images)

        index = 0
        for resultImage, resultLabel in results:
            label = resultLabel['label']
            self.saveImage(resultImage, label, imagePaths[index])
            index += 1

    def saveImage(self, resultImage, label, inputImagePath):

        fileName = os.path.split(inputImagePath)[1]
        outputPath = os.path.join(self.options['output'], label, fileName)

        if not os.path.exists(os.path.dirname(outputPath)):
            os.makedirs(os.path.dirname(outputPath))
        
        resultImage.save(outputPath)
Example #13
0
from engine.Engine import Engine
from engine.GUI import GUI

pygame.init()
pygame.font.init()

# -------editables-------
FPS = 30
# MAP = "layout3_dev.txt"
DEFAULT_MAP_SIZE = 15  # in tiles
WINDOW_SIZE = (DEFAULT_MAP_SIZE * 33 + 450, DEFAULT_MAP_SIZE * 33 + 300)
# -----------------------

# screen handle
engine = Engine(WINDOW_SIZE)
# engine = Engine(MAP, WINDOW_SIZE)
# hScreen = pygame.display.set_mode(WINDOW_SIZE)

pygame.display.set_caption('Czerwony ciÄ…gnik')

fpsClock = pygame.time.Clock()

# create and init game engine
# engine.set_hScreen(hScreen)

# plants_update_thread = threading.start_new_thread(self.__update_plants, (0, 0))
# render_thread = threading.start_new_thread(render, (0, 0))
# todo add update thread asap

while True:
 def run(self):
     logging.debug("ExperimentActionThread(): instantiated")
     self.watchsignal.emit("Running " + str(self.actionname) + "...", None,
                           None)
     try:
         e = Engine.getInstance()
         if self.actionname == "Create Experiment":
             e.execute("experiment create " + str(self.configname) + " " +
                       str(self.itype) + " " + str(self.name))
         elif self.actionname == "Start Experiment":
             e.execute("experiment start " + str(self.configname) + " " +
                       str(self.itype) + " " + str(self.name))
         elif self.actionname == "Stop Experiment":
             e.execute("experiment stop " + str(self.configname) + " " +
                       str(self.itype) + " " + str(self.name))
         elif self.actionname == "Suspend Experiment":
             e.execute("experiment suspend " + str(self.configname) + " " +
                       str(self.itype) + " " + str(self.name))
         elif self.actionname == "Pause Experiment":
             e.execute("experiment pause " + str(self.configname) + " " +
                       str(self.itype) + " " + str(self.name))
         elif self.actionname == "Snapshot Experiment":
             e.execute("experiment snapshot " + str(self.configname) + " " +
                       str(self.itype) + " " + str(self.name))
         elif self.actionname == "Restore Experiment":
             e.execute("experiment restore " + str(self.configname) + " " +
                       str(self.itype) + " " + str(self.name))
         elif self.actionname == "Remove Experiment":
             e.execute("experiment remove " + str(self.configname) + " " +
                       str(self.itype) + " " + str(self.name))
         #will check status every 0.5 second and will either display stopped or ongoing or connected
         dots = 1
         while (True):
             logging.debug(
                 "ExperimentActionThread(): running: experiment status")
             self.status = e.execute("experiment status")
             logging.debug("ExperimentActionThread(): result: " +
                           str(self.status))
             if self.status[
                     "writeStatus"] != ExperimentManage.EXPERIMENT_MANAGE_COMPLETE:
                 dotstring = ""
                 for i in range(1, dots):
                     dotstring = dotstring + "."
                 self.watchsignal.emit(
                     " Running " + str(self.actionname) + dotstring,
                     self.status, None)
                 dots = dots + 1
                 if dots > 4:
                     dots = 1
             else:
                 break
             time.sleep(0.5)
         logging.debug("WatchRetrieveThread(): thread ending")
         self.watchsignal.emit(
             "Action " + str(self.actionname) + " Complete", self.status,
             True)
         return
     except:
         logging.error(
             "Error in ExperimentActionThread(): An error occured ")
         exc_type, exc_value, exc_traceback = sys.exc_info()
         traceback.print_exception(exc_type, exc_value, exc_traceback)
         #self.watchsignal.emit("Error executing action: " + str(self.actionname), None, True)
         self.watchsignal.emit("Error executing action: " + str(exc_value),
                               None, True)
         self.status = -1
         return None
     finally:
         return None
 def run(self):
     logging.debug("WatchActioningThread(): instantiated")
     self.watchsignal.emit(
         "Processing Connection " + str(self.actionname) + "...", None,
         None)
     try:
         e = Engine.getInstance()
         creds_file = " None "
         if self.actionname == "Add":
             if len(self.args) != 13:
                 logging.error(
                     "WatchActioningThread(): invalid number of args for create connections. Skipping..."
                 )
                 self.watchsignal.emit(
                     "Invalid number of args for create connections. Skipping...",
                     self.status, True)
                 self.status = -1
                 return None
             #10 is the users_file
             if str(self.args[10]).strip() != "":
                 creds_file = " " + str(self.args[10])
             cmd = "conns " + " create " + self.configname + " " + str(
                 self.args[0]) + " " + str(self.args[1]) + " " + str(
                     self.args[2]) + " " + str(self.args[3]) + " " + str(
                         self.args[4]) + " " + str(
                             self.args[5]) + " " + str(
                                 self.args[6]) + " " + str(
                                     self.args[7]) + " " + str(
                                         self.args[8]) + " " + str(
                                             self.args[9]
                                         ) + " " + creds_file + " " + str(
                                             self.args[11]) + " " + str(
                                                 self.args[12])
         if self.actionname == "Remove":
             if len(self.args) != 8:
                 logging.error(
                     "WatchActioningThread(): invalid number of args for remove connections. Skipping..."
                 )
                 self.watchsignal.emit(
                     "Invalid number of args for remove connections. Skipping...",
                     self.status, True)
                 self.status = -1
                 return None
             if str(self.args[5]).strip() != "":
                 creds_file = " " + str(self.args[5])
             cmd = "conns " + " remove " + self.configname + " " + str(
                 self.args[0]) + " " + str(self.args[1]) + " " + str(
                     self.args[2]) + " " + str(self.args[3]) + " " + str(
                         self.args[4]) + creds_file + " " + str(
                             self.args[6]) + " " + str(self.args[7])
         if self.actionname == "Clear":
             if len(self.args) != 5:
                 logging.error(
                     "WatchActioningThread(): invalid number of args for clear connections. Skipping..."
                 )
                 self.watchsignal.emit(
                     "Invalid number of args for clear connections. Skipping...",
                     self.status, True)
                 self.status = -1
                 return None
             cmd = "conns " + " clear " + str(self.args[0]) + " " + str(
                 self.args[1]) + " " + str(self.args[2]) + " " + str(
                     self.args[3]) + " " + str(self.args[4])
         logging.debug("WatchActioningThread(): running: " + cmd)
         e.execute(cmd)
         #will check status every 0.5 second and will either display stopped or ongoing or connected
         dots = 1
         while (True):
             logging.debug("WatchActioningThread(): running: " + cmd)
             self.status = e.execute("conns status")
             logging.debug("WatchActioningThread(): result: " +
                           str(self.status))
             if self.status[
                     "writeStatus"] != ConnectionManage.CONNECTION_MANAGE_COMPLETE:
                 dotstring = ""
                 for i in range(1, dots):
                     dotstring = dotstring + "."
                 self.watchsignal.emit(
                     "Processing " + str(self.actionname) + dotstring,
                     self.status, None)
                 dots = dots + 1
                 if dots > 4:
                     dots = 1
             else:
                 break
             time.sleep(0.5)
         logging.debug("WatchActioningThread(): thread ending")
         self.watchsignal.emit(
             str(self.actionname) + " Complete", self.status, True)
         return
     except:
         logging.error("Error in WatchActioningThread(): An error occured ")
         exc_type, exc_value, exc_traceback = sys.exc_info()
         traceback.print_exception(exc_type, exc_value, exc_traceback)
         self.watchsignal.emit("Error while completing connection action.",
                               None, True)
         self.status = -1
         return None
     finally:
         return None
Example #16
0
 def inCom(self, message):
     engine = Engine(self)
     engine.start(message)
Example #17
0
 def __init__(self, options):
     self.options = options
     self.engine = Engine()
Example #18
0
import sys
import time
from engine.Manager.VMManage.VMManage import VMManage
from engine.Manager.ConnectionManage.ConnectionManageGuacRDP import ConnectionManageGuacRDP
from engine.Manager.PackageManage.PackageManageVBox import PackageManageVBox
from engine.Manager.ExperimentManage.ExperimentManageVBox import ExperimentManageVBox
from engine.Engine import Engine
import threading

if __name__ == "__main__":
    logging.getLogger().setLevel(logging.DEBUG)
    #logging.basicConfig(filename='example.log',level=logging.DEBUG)
    logging.debug("Starting Program")
###Base Engine tests
    logging.debug("Instantiating Engine")
    e = Engine()
    logging.debug("engine object: " + str(e))

    logging.debug("Calling Engine.getInstance()")
    e = Engine.getInstance()
    logging.debug("engine object: " + str(e))

###Engine tests
    res = e.execute("engine status ")

###VMManage tests
    #Check status without refresh
    logging.debug("VM-Manage Status of defaulta without refresh" + str(res))
    res = e.execute("vm-manage vmstatus defaulta")
    res = e.execute("vm-manage mgrstatus")
    logging.debug("Returned: " + str(res))