def set_message_receiver(self):
     if not self.messages_thread:
         self.messages_thread = MessageSubsriberThread(1234)
         self.messages_thread.on_message_received.connect(self.on_message_received)
         self.messages_thread.start(QThread.TimeCriticalPriority)
Exemple #2
0
 def set_message_receiver(self):
     if not self.messages_thread:
         self.messages_thread = MessageSubsriberThread(1234)
         self.messages_thread.on_message_received.connect(
             self.on_message_received)
         self.messages_thread.start(QThread.TimeCriticalPriority)
class ConfigWindow(QtGui.QMainWindow, Ui_ConfigWindow):
    def __init__(self, main_window, *args, **kwargs):
        super(ConfigWindow, self).__init__(*args, **kwargs)
        self.viewMode = 'admin'
        self.debug = False
        self.verbose = app_config.is_verbose()
        self.config_path = None
        self.working_dir = None
        self.main_window = main_window or self
        self.working_dir_choser = None
        self.messages_thread = None
        self.cw = None
        self.bundlesModel = QtGui.QStandardItemModel()
        self.set_plugins()
        self.setupUi()
        self.set_message_receiver()
        self.start_last_if_any()
    
    def set_plugins(self):
        self.plugins =[]
        for d in config.plugin_dirs:
            self.plugins.extend(get_plugins(d))

    def setupUi(self):
        super(ConfigWindow, self).setupUi(self)
        title="Configurator Version:%s"%(app_config.get_version())
        self.setWindowTitle(title)
        self.cbChooseWorkingDir.clicked.connect(self.chose_working_dir)
        self.set_menu_bar()
        self.set_recent_config_actions()
        self.tool = None
        self.workspace = app_config.get_current_workspace()
        if not self.workspace:
            self.switch_workspace()
        else:
            self.workspace.set_loger(ZmqChainedLoger(1234))
        self.viewMode = self.workspace.mode
        self.actionViewAsAdmin.setChecked(self.viewMode=='admin')
        self.actionViewAsModerator.setChecked(self.viewMode=='moderator')

    def bindUi(self):
        if self.viewMode != 'admin':
            self.tool = self.detailsContainer
        else:
            self.tool = None
        title = os.path.basename((os.path.dirname(os.path.dirname(self.config_path))))
        title +="         -- Configurator Version:%s" % (app_config.get_version())
        self.setWindowTitle(title)
        self.txtWorkingDir.setText(self.working_dir)

        if self.cw:
            self.ltv_content.removeWidget(self.cw)
            self.cw.close()
        self.cw = ConfigForm(self.loader, parent=self, details_parent = self.tool)
        #self.tool.setModel(ToolsListModel(self.plugins, False))
        self.menubar.setWindowTitle(title)
        self.build_output = None
        self.set_bundles_model()

        self.ltv_content.addWidget(self.cw)
        # if self.viewMode!='admin':
        #     self.cw.tlbx_bundles.hide()
        #     self.widget.hide()
        #     width = self.splitter_2.sizeHint().width()
        #     self.splitter_2.setSizes([width*0.3, width*0.7])
        # else:
        #     width = self.splitter_2.sizeHint().width()
        #     self.splitter_2.setSizes([width, 0])
            
    def start_last_if_any(self):
        try:
            config_history = app_config.get_config_history()
            if config_history:
                self.set_configuration(config_history[-1])
        except Exception as ex:
                print(ex)

    def set_configuration(self, config_path, working_dir=None):
        self.config_path = config_path
        if working_dir:
            self.working_dir = working_dir
        else:
            self.working_dir = app_config.get_working_dir()
        self.loader = FileConfigLoader(self.config_path)
        self.configuration = self.loader.load_config()
        self.bindUi()

    def set_bundles_model(self):
        self.bundlesModel.clear()
        work_mode = Workspace.current.mode
        bundle_filter = ConfigBuildFilter(included=Workspace.registered_bundles)
        d = self.get_mode_config_for_key(work_mode, 'bundles')
        bundle_filter.extend_from_dict(d)
        for bundle in self.configuration['Content']['OperationBundles']:
            dataItem = QtGui.QStandardItem(bundle['Name'])
            dataItem.setCheckable(True)
            check_state = bundle_filter.allowed(bundle['Name']) and QtCore.Qt.CheckState.Checked or QtCore.Qt.CheckState.Unchecked
            dataItem.setCheckState(check_state)
            self.bundlesModel.appendRow(dataItem)
    
    def get_mode_config_for_key(self, work_mode, key):
        if self.configuration.has_key('Builds'):
            if self.configuration['Builds'].has_key(work_mode):
                bc = self.configuration['Builds'][work_mode]
                if bc.has_key(key):
                    return copy.deepcopy(bc[key])
        return {}

    def get_included_bundles(self):
        i = 0
        includedBundles = []
        while self.bundlesModel.item(i):
            dataItem = self.bundlesModel.item(i)
            if dataItem.checkState():
                includedBundles.append(dataItem.text())
            i += 1
        return includedBundles
            
    def chose_working_dir(self):
        """
        Choses the current working directory for the current configuration
        """
        res = QtGui.QFileDialog.getExistingDirectory(caption="Choose working directory")
        if res:
            app_config.set_working_dir(res)
            self.working_dir = res
            self.txtWorkingDir.setText(res)


    def show_bundle_selector(self):
        self.bundleSelectorWidget = BundleSelector(self.bundlesModel)
        self.bundleSelectorWidget.show()


    def validate_configuration(self):
        validator = ConfigurationValidator(self.config_path)
        result = validator.validate(self.configuration)
        title = result.is_valid and 'Valid Configuration' or 'Invalid Configurration'
        message = 'Errors:\n'+'\n'.join(['\t'+x for x in result.errors])
        message+= '\nWarnings:\n'+'\n'.join(['\t'+x for x in result.warnings])
        message+= '\nSuggestions:\n'+'\n'.join(['\t'+x for x in result.suggestions])
        msgBox = QtGui.QMessageBox()
        msgBox.setText(title)
        msgBox.setInformativeText(message)
        msgBox.exec_()

    def open_regex_tool(self):
        self.rtool = RegexTool()
        self.rtool.show()


    def sync_workspace(self):
        self.build_output = ConsoleOutput()
        self.build_output.show()
        class thc(QtCore.QThread):
            def __init__(self, workspace):
                self.workspace = workspace
                super(thc, self).__init__()
            def run(self):
                print "running..."
                self.workspace.sync()
        self.th = thc(self.workspace)
        self.th.start()

    def switch_workspace(self, custom_title = None):
        self.workspacedialog = QtGui.QFileDialog(None, custom_title or 'Choose your Workspace!')
        self.workspacedialog.setFileMode(QtGui.QFileDialog.Directory)
        self.workspacedialog.setOption(QtGui.QFileDialog.ShowDirsOnly)
        res = self.workspacedialog.exec_()
        if res:
            dirpath = self.workspacedialog.selectedFiles()[0]
            app_config.set_current_workspace(dirpath)
        while not app_config.get_current_workspace():
            self.switch_workspace('You must choose a valid workspace in order to open the app')
        self.workspace = app_config.get_current_workspace()
        self.workspace.set_loger(ZmqChainedLoger(1234))
        self.workspacedialog.close()

    def reset_workspace(self):
        self.build_output = ConsoleOutput()
        self.build_output.show()
        class thc(QtCore.QThread):
            def __init__(self, workspace):
                self.workspace = workspace
                super(thc, self).__init__()
            def run(self):
                print "running..."
                self.workspace.reset()
        self.th = thc(self.workspace)
        self.th.start()

    def setViewMode(self, modeUsed=None):
        newViewMode = None
        if modeUsed=='moderator':
            self.actionViewAsAdmin.setChecked(not self.actionViewAsModerator.isChecked())
            newViewMode = self.actionViewAsModerator.isChecked() and 'moderator' or 'admin'
        else:
            self.actionViewAsModerator.setChecked(not self.actionViewAsAdmin.isChecked())
            newViewMode = self.actionViewAsAdmin.isChecked() and 'admin' or 'moderator'

        if newViewMode !=self.viewMode and self.config_path:
            self.viewMode = newViewMode
            self.workspace.mode = newViewMode
            self.set_configuration(self.config_path, self.working_dir)

    def set_menu_bar(self):
        def save(is_new, is_cloning_empty):
            def fn ():
                if self.cw:
                    self.cw.save_config(is_new, is_cloning_empty)
            return fn
        def viewModeSetter(mode):
            def fn ():
                return self.setViewMode(mode)
            return fn
        self.actionRun.triggered.connect(self.on_run_click)
        self.actionClose.triggered.connect(self.close)
        self.actionOpen.triggered.connect(self.open_config)
        self.actionNew.triggered.connect(self.create_new_config)
        self.actionEnable_Disable_Bundles.triggered.connect(self.show_bundle_selector)
        self.actionVallidate.triggered.connect(self.validate_configuration)
        self.actionRegex.triggered.connect(self.open_regex_tool)
        self.actionSync.triggered.connect(self.sync_workspace)
        self.actionSwitch_Workspace.triggered.connect(self.switch_workspace)
        self.actionReset.triggered.connect(self.reset_workspace)
        self.actionSave.triggered.connect(save(False, False))
        self.actionSave_As.triggered.connect(save(True, False))
        self.actionClone.triggered.connect(save(True, True))
        self.actionViewAsAdmin.triggered.connect(viewModeSetter('admin'))
        self.actionViewAsModerator.triggered.connect(viewModeSetter('moderator'))
        self.actionVerbose.triggered.connect(self.setVerbosity)
        self.actionVerbose.setChecked(app_config.is_verbose())
        self.actionDebug_2.triggered.connect(self.debugChanged)

    def debugChanged(self):
        self.debug = self.actionDebug.isChecked()

    def setVerbosity(self):
        app_config.set_verbose(self.actionVerbose.isChecked())
        self.verbose = self.actionVerbose.isChecked()

    def create_new_config(self):
        params = {"caption":"Choose Configuration","filter":"bc.halc"}
        if len(app_config.get_config_history())>0:
            last_config = app_config.get_config_history()[-1]
            last_config = last_config.replace("'", '')
            params["dir"] = os.path.dirname(last_config)
            
        f = QtGui.QFileDialog.getSaveFileName(**params)
        if f[0]:
            self.config_path = f[0]
            FileConfigLoader.new(self.config_path)
            app_config.add_config_to_history(self.config_path)
            self.set_configuration(self.config_path, self.working_dir)

    def set_recent_config_actions(self):
        history = app_config.get_config_history()
        history.reverse()
        self.historyActions = []
        for k in history:
            a = QtGui.QAction(self)
            a.triggered.connect(self.open_recent)
            a.setText(k)
            self.historyActions.append(a)
            self.menuRecent.addAction(a)

    def open_recent(self, *args, **kwargs):
        app_config.add_config_to_history(self.sender().text())
        self.set_configuration(self.sender().text(), self.working_dir)

    def open_config(self):
        cur_dir = None
        if app_config.get_config_history():
            cur_dir = app_config.get_config_history()[-1]

        params = {"caption":"Choose Configuration","filter":"Config Files(bc.json *.halc)"}
        if cur_dir:
            params["dir"] = app_config.get_config_history()[-1]
        f = QtGui.QFileDialog.getOpenFileName(**params)

        if f[0]:
            self.config_path = f[0]
            app_config.add_config_to_history(self.config_path)
            self.set_configuration(self.config_path, self.working_dir)

    def on_run_click(self):
        root_url = os.path.dirname(self.config_path)
        if os.name!='posix':
            root_url = '/'+root_url
        if self.build_output:
            self.build_output.close()
        self.build_output = ConsoleOutput()
        self.build_output.show()
        config_loader = FileConfigLoader(self.config_path)
        builder = AppConfigurator(config_loader, ZmqChainedLoger(1234), verbose=self.verbose)
        builder.set_execution_dir(self.working_dir)
        builder.include_bundles(self.get_included_bundles())
        self.set_message_receiver()
        if self.debug:
            builder.apply()
        else:
            self.worker = ConfigRunnerThread(builder)
            self.worker.start()
            self.worker.finished.connect(self.on_worker_finished)

    def on_worker_finished(self):
        self.worker.builder = None
        del self.worker

    def set_message_receiver(self):
        if not self.messages_thread:
            self.messages_thread = MessageSubsriberThread(1234)
            self.messages_thread.on_message_received.connect(self.on_message_received)
            self.messages_thread.start(QThread.TimeCriticalPriority)

    def on_message_received(self, message):
        if self.build_output:
            self.build_output.txt_output.append("%s" % message)

      
    @QtCore.Slot()
    def showOptionsMenu(self):
        self.prefs = PreferencesWidget()
        self.prefs.show()
Exemple #4
0
class ConfigWindow(QtGui.QMainWindow, Ui_ConfigWindow):
    def __init__(self, main_window, *args, **kwargs):
        super(ConfigWindow, self).__init__(*args, **kwargs)
        self.viewMode = 'admin'
        self.debug = False
        self.verbose = app_config.is_verbose()
        self.config_path = None
        self.working_dir = None
        self.main_window = main_window or self
        self.working_dir_choser = None
        self.messages_thread = None
        self.cw = None
        self.bundlesModel = QtGui.QStandardItemModel()
        self.set_plugins()
        self.setupUi()
        self.set_message_receiver()
        self.start_last_if_any()

    def set_plugins(self):
        self.plugins = []
        for d in config.plugin_dirs:
            self.plugins.extend(get_plugins(d))

    def setupUi(self):
        super(ConfigWindow, self).setupUi(self)
        title = "Configurator Version:%s" % (app_config.get_version())
        self.setWindowTitle(title)
        self.cbChooseWorkingDir.clicked.connect(self.chose_working_dir)
        self.set_menu_bar()
        self.set_recent_config_actions()
        self.tool = None
        self.workspace = app_config.get_current_workspace()
        if not self.workspace:
            self.switch_workspace()
        else:
            self.workspace.set_loger(ZmqChainedLoger(1234))
        self.viewMode = self.workspace.mode
        self.actionViewAsAdmin.setChecked(self.viewMode == 'admin')
        self.actionViewAsModerator.setChecked(self.viewMode == 'moderator')

    def bindUi(self):
        if self.viewMode != 'admin':
            self.tool = self.detailsContainer
        else:
            self.tool = None
        title = os.path.basename(
            (os.path.dirname(os.path.dirname(self.config_path))))
        title += "         -- Configurator Version:%s" % (
            app_config.get_version())
        self.setWindowTitle(title)
        self.txtWorkingDir.setText(self.working_dir)

        if self.cw:
            self.ltv_content.removeWidget(self.cw)
            self.cw.close()
        self.cw = ConfigForm(self.loader,
                             parent=self,
                             details_parent=self.tool)
        #self.tool.setModel(ToolsListModel(self.plugins, False))
        self.menubar.setWindowTitle(title)
        self.build_output = None
        self.set_bundles_model()

        self.ltv_content.addWidget(self.cw)
        # if self.viewMode!='admin':
        #     self.cw.tlbx_bundles.hide()
        #     self.widget.hide()
        #     width = self.splitter_2.sizeHint().width()
        #     self.splitter_2.setSizes([width*0.3, width*0.7])
        # else:
        #     width = self.splitter_2.sizeHint().width()
        #     self.splitter_2.setSizes([width, 0])

    def start_last_if_any(self):
        try:
            config_history = app_config.get_config_history()
            if config_history:
                self.set_configuration(config_history[-1])
        except Exception as ex:
            print(ex)

    def set_configuration(self, config_path, working_dir=None):
        self.config_path = config_path
        if working_dir:
            self.working_dir = working_dir
        else:
            self.working_dir = app_config.get_working_dir()
        self.loader = FileConfigLoader(self.config_path)
        self.configuration = self.loader.load_config()
        self.bindUi()

    def set_bundles_model(self):
        self.bundlesModel.clear()
        work_mode = Workspace.current.mode
        bundle_filter = ConfigBuildFilter(
            included=Workspace.registered_bundles)
        d = self.get_mode_config_for_key(work_mode, 'bundles')
        bundle_filter.extend_from_dict(d)
        for bundle in self.configuration['Content']['OperationBundles']:
            dataItem = QtGui.QStandardItem(bundle['Name'])
            dataItem.setCheckable(True)
            check_state = bundle_filter.allowed(
                bundle['Name']
            ) and QtCore.Qt.CheckState.Checked or QtCore.Qt.CheckState.Unchecked
            dataItem.setCheckState(check_state)
            self.bundlesModel.appendRow(dataItem)

    def get_mode_config_for_key(self, work_mode, key):
        if self.configuration.has_key('Builds'):
            if self.configuration['Builds'].has_key(work_mode):
                bc = self.configuration['Builds'][work_mode]
                if bc.has_key(key):
                    return copy.deepcopy(bc[key])
        return {}

    def get_included_bundles(self):
        i = 0
        includedBundles = []
        while self.bundlesModel.item(i):
            dataItem = self.bundlesModel.item(i)
            if dataItem.checkState():
                includedBundles.append(dataItem.text())
            i += 1
        return includedBundles

    def chose_working_dir(self):
        """
        Choses the current working directory for the current configuration
        """
        res = QtGui.QFileDialog.getExistingDirectory(
            caption="Choose working directory")
        if res:
            app_config.set_working_dir(res)
            self.working_dir = res
            self.txtWorkingDir.setText(res)

    def show_bundle_selector(self):
        self.bundleSelectorWidget = BundleSelector(self.bundlesModel)
        self.bundleSelectorWidget.show()

    def validate_configuration(self):
        validator = ConfigurationValidator(self.config_path)
        result = validator.validate(self.configuration)
        title = result.is_valid and 'Valid Configuration' or 'Invalid Configurration'
        message = 'Errors:\n' + '\n'.join(['\t' + x for x in result.errors])
        message += '\nWarnings:\n' + '\n'.join(
            ['\t' + x for x in result.warnings])
        message += '\nSuggestions:\n' + '\n'.join(
            ['\t' + x for x in result.suggestions])
        msgBox = QtGui.QMessageBox()
        msgBox.setText(title)
        msgBox.setInformativeText(message)
        msgBox.exec_()

    def open_regex_tool(self):
        self.rtool = RegexTool()
        self.rtool.show()

    def sync_workspace(self):
        self.build_output = ConsoleOutput()
        self.build_output.show()

        class thc(QtCore.QThread):
            def __init__(self, workspace):
                self.workspace = workspace
                super(thc, self).__init__()

            def run(self):
                print "running..."
                self.workspace.sync()

        self.th = thc(self.workspace)
        self.th.start()

    def switch_workspace(self, custom_title=None):
        self.workspacedialog = QtGui.QFileDialog(
            None, custom_title or 'Choose your Workspace!')
        self.workspacedialog.setFileMode(QtGui.QFileDialog.Directory)
        self.workspacedialog.setOption(QtGui.QFileDialog.ShowDirsOnly)
        res = self.workspacedialog.exec_()
        if res:
            dirpath = self.workspacedialog.selectedFiles()[0]
            app_config.set_current_workspace(dirpath)
        while not app_config.get_current_workspace():
            self.switch_workspace(
                'You must choose a valid workspace in order to open the app')
        self.workspace = app_config.get_current_workspace()
        self.workspace.set_loger(ZmqChainedLoger(1234))
        self.workspacedialog.close()

    def reset_workspace(self):
        self.build_output = ConsoleOutput()
        self.build_output.show()

        class thc(QtCore.QThread):
            def __init__(self, workspace):
                self.workspace = workspace
                super(thc, self).__init__()

            def run(self):
                print "running..."
                self.workspace.reset()

        self.th = thc(self.workspace)
        self.th.start()

    def setViewMode(self, modeUsed=None):
        newViewMode = None
        if modeUsed == 'moderator':
            self.actionViewAsAdmin.setChecked(
                not self.actionViewAsModerator.isChecked())
            newViewMode = self.actionViewAsModerator.isChecked(
            ) and 'moderator' or 'admin'
        else:
            self.actionViewAsModerator.setChecked(
                not self.actionViewAsAdmin.isChecked())
            newViewMode = self.actionViewAsAdmin.isChecked(
            ) and 'admin' or 'moderator'

        if newViewMode != self.viewMode and self.config_path:
            self.viewMode = newViewMode
            self.workspace.mode = newViewMode
            self.set_configuration(self.config_path, self.working_dir)

    def set_menu_bar(self):
        def save(is_new, is_cloning_empty):
            def fn():
                if self.cw:
                    self.cw.save_config(is_new, is_cloning_empty)

            return fn

        def viewModeSetter(mode):
            def fn():
                return self.setViewMode(mode)

            return fn

        self.actionRun.triggered.connect(self.on_run_click)
        self.actionClose.triggered.connect(self.close)
        self.actionOpen.triggered.connect(self.open_config)
        self.actionNew.triggered.connect(self.create_new_config)
        self.actionEnable_Disable_Bundles.triggered.connect(
            self.show_bundle_selector)
        self.actionVallidate.triggered.connect(self.validate_configuration)
        self.actionRegex.triggered.connect(self.open_regex_tool)
        self.actionSync.triggered.connect(self.sync_workspace)
        self.actionSwitch_Workspace.triggered.connect(self.switch_workspace)
        self.actionReset.triggered.connect(self.reset_workspace)
        self.actionSave.triggered.connect(save(False, False))
        self.actionSave_As.triggered.connect(save(True, False))
        self.actionClone.triggered.connect(save(True, True))
        self.actionViewAsAdmin.triggered.connect(viewModeSetter('admin'))
        self.actionViewAsModerator.triggered.connect(
            viewModeSetter('moderator'))
        self.actionVerbose.triggered.connect(self.setVerbosity)
        self.actionVerbose.setChecked(app_config.is_verbose())
        self.actionDebug_2.triggered.connect(self.debugChanged)

    def debugChanged(self):
        self.debug = self.actionDebug.isChecked()

    def setVerbosity(self):
        app_config.set_verbose(self.actionVerbose.isChecked())
        self.verbose = self.actionVerbose.isChecked()

    def create_new_config(self):
        params = {"caption": "Choose Configuration", "filter": "bc.halc"}
        if len(app_config.get_config_history()) > 0:
            last_config = app_config.get_config_history()[-1]
            last_config = last_config.replace("'", '')
            params["dir"] = os.path.dirname(last_config)

        f = QtGui.QFileDialog.getSaveFileName(**params)
        if f[0]:
            self.config_path = f[0]
            FileConfigLoader.new(self.config_path)
            app_config.add_config_to_history(self.config_path)
            self.set_configuration(self.config_path, self.working_dir)

    def set_recent_config_actions(self):
        history = app_config.get_config_history()
        history.reverse()
        self.historyActions = []
        for k in history:
            a = QtGui.QAction(self)
            a.triggered.connect(self.open_recent)
            a.setText(k)
            self.historyActions.append(a)
            self.menuRecent.addAction(a)

    def open_recent(self, *args, **kwargs):
        app_config.add_config_to_history(self.sender().text())
        self.set_configuration(self.sender().text(), self.working_dir)

    def open_config(self):
        cur_dir = None
        if app_config.get_config_history():
            cur_dir = app_config.get_config_history()[-1]

        params = {
            "caption": "Choose Configuration",
            "filter": "Config Files(bc.json *.halc)"
        }
        if cur_dir:
            params["dir"] = app_config.get_config_history()[-1]
        f = QtGui.QFileDialog.getOpenFileName(**params)

        if f[0]:
            self.config_path = f[0]
            app_config.add_config_to_history(self.config_path)
            self.set_configuration(self.config_path, self.working_dir)

    def on_run_click(self):
        root_url = os.path.dirname(self.config_path)
        if os.name != 'posix':
            root_url = '/' + root_url
        if self.build_output:
            self.build_output.close()
        self.build_output = ConsoleOutput()
        self.build_output.show()
        config_loader = FileConfigLoader(self.config_path)
        builder = AppConfigurator(config_loader,
                                  ZmqChainedLoger(1234),
                                  verbose=self.verbose)
        builder.set_execution_dir(self.working_dir)
        builder.include_bundles(self.get_included_bundles())
        self.set_message_receiver()
        if self.debug:
            builder.apply()
        else:
            self.worker = ConfigRunnerThread(builder)
            self.worker.start()
            self.worker.finished.connect(self.on_worker_finished)

    def on_worker_finished(self):
        self.worker.builder = None
        del self.worker

    def set_message_receiver(self):
        if not self.messages_thread:
            self.messages_thread = MessageSubsriberThread(1234)
            self.messages_thread.on_message_received.connect(
                self.on_message_received)
            self.messages_thread.start(QThread.TimeCriticalPriority)

    def on_message_received(self, message):
        if self.build_output:
            self.build_output.txt_output.append("%s" % message)

    @QtCore.Slot()
    def showOptionsMenu(self):
        self.prefs = PreferencesWidget()
        self.prefs.show()
Exemple #5
0
class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
  def __init__(self, *args, **kwargs):
    self.fullScreen = False
    super(MainWindow, self).__init__(*args, **kwargs)
    self.setupUi(self)
    self.show()
    self.pb_build_progress.setHidden(True)
    self.bind_controls()
    self.building = False
    self.proc = None
    self.build_step = 0
    self.working_dir = None
    self.regex_tool = None
    self.config = None

  def bind_controls(self):
    self.btn_build.clicked.connect(self.on_build_clicked)
    self.cmb_brands.currentIndexChanged.connect(self.on_brand_changed)
    self.brands_model = SimpleStringListModel(self.get_available_brands())
    self.cmb_brands.setModel(self.brands_model)
    
    self.cmb_platforms.setModel(SimpleStringListModel(self.get_platforms_for_brand(None)))
    self.cmb_platforms.currentIndexChanged.connect(self.on_platform_changed)
    self.btn_configure.clicked.connect(self.on_configure_clicked)
    self.btn_show_config.clicked.connect(self.on_show_config_clicked)
    self.btn_install_on_device.clicked.connect(self.on_install_clicked)
    self.btn_reset_scm.clicked.connect(self.on_scm_reset_clicked)
    self.btn_sign.clicked.connect(self.on_sign_app_clicked)
    self.actionRegex_Tool.triggered.connect(self.on_toggle_regex_tool)

  ###### Event Handlers #######

  def on_toggle_regex_tool(self):
    global regex_shown
    if not self.regex_tool:
      self.regex_tool = RegexTool()
    if regex_shown:
      self.regex_tool.hide()
    else:
      self.regex_tool.show()
    regex_shown = not regex_shown

  def on_scm_reset_clicked(self):
    def state_changed(state):
      if state== QtCore.QProcess.ProcessState.NotRunning:
        self.run_external_proc("git clean -f", os.path.dirname(self.working_dir))
    self.run_external_proc("git reset --hard HEAD", os.path.dirname(self.working_dir), state_changed)

  def on_show_config_clicked(self):
    if self.working_dir:
      self.config = FileConfigLoader(self.get_config_path()).load_config()
      self.cfg = ConfigWindow(self)
      self.cfg.set_configuration(self.get_config_path(), self.working_dir)
      self.cfg.cw.set_save_path(self.get_config_path())
      self.cfg.show()

  def on_brand_changed(self):
    brand = self.cmb_brands.currentText()
    self.cmb_platforms.setModel(SimpleStringListModel(self.get_platforms_for_brand(brand)))

  def on_platform_changed(self):
    ind = self.cmb_platforms.currentIndex()
    if ind>0:
      self.working_dir  = solution_dir.replace('{PlatformType}', solution_for_platform[self.cmb_platforms.currentText()])
      self.config = FileConfigLoader(self.get_config_path()).load_config()
    else:
      self.working_dir = None

  def on_configure_clicked(self):
    config_loader = FileConfigLoader(self.get_config_path())
    builder = AppConfigurator(config_loader,
                            ZmqChainedLoger(port),
                            verbose=self.cb_verbose.isChecked(),
                            debug_mode=self.cb_verbose.isChecked())




    builder.set_execution_dir(self.working_dir)
    self.worker = ConfigRunnerThread(builder)
    self.set_message_receiver()
    self.worker.start()
    self.worker.finished.connect(self.on_worker_finished)

  def on_worker_finished(self):
    self.worker.builder = None
    del self.worker
    self.messages_thread.terminate()
    del self.messages_thread

  def set_message_receiver(self):
    self.messages_thread = MessageSubsriberThread(port)
    self.messages_thread.on_message_received.connect(self.on_message_received)
    self.messages_thread.start(QtCore.QThread.TimeCriticalPriority)

  def on_message_received(self, message):
    self.txt_output.append("%s" % message)

  def on_build_clicked(self):
    if self.working_dir:
      if self.is_repo_clean():
        self.building = not self.building
        if self.building:
          self.start_build("make build", os.path.dirname(self.working_dir))
          self.btn_build.setText("Cancel")
          self.freeze_buttons(True)
        else:
          self.cancel_build()
          self.btn_build.setText("Build")
          self.freeze_buttons(False)
      else:
        print "repo is not commited"
    else:
      print "no working dir set"

  def on_sign_app_clicked(self):
    self.run_external_proc("make sign", os.path.dirname(self.working_dir))

  def on_install_clicked(self):
    self.run_external_proc("make install", os.path.dirname(self.working_dir))

  ######End Event Handlers #######

  def get_config_path(self):
    global_vars = GlobalVars.get_instance()
    global_vars.current_config_path=os.path.join(config_path, self.cmb_brands.currentText(), self.cmb_platforms.currentText(),"bc.json")      
    return global_vars.current_config_path
  
    #self.pb_build_progress.setHidden(not self.building)

  def get_available_brands(self):
    brands =  [d for d in os.listdir(config_path) if os.path.isdir(os.path.join(config_path, d))]
    brands.insert(0, "--Select Brand--")
    return brands

  def get_platforms_for_brand(self, brand):
    plats = []
    if brand:
      bpath = os.path.join(config_path, brand)
      if os.path.exists(bpath):
        plats =  [d for d in os.listdir(bpath) if os.path.isdir(os.path.join(bpath, d))]
    plats.insert(0, "--Select Platform--")
    return plats

  def is_repo_clean(self):
    #self.start_build("git status", self.working_dir)
    return True
  
  def start_build(self, comm, working_dir):
    self.build_step+=1
    print working_dir
    print "building"
    self.proc = QtCore.QProcess(self)
    self.proc.setWorkingDirectory(working_dir)
    self.proc.readyReadStandardOutput.connect(self.__show_output__)
    self.proc.readyReadStandardOutput.connect(self.__show_error__)
    self.proc.setProcessChannelMode(QtCore.QProcess.ProcessChannelMode.MergedChannels)
    self.proc.closeWriteChannel()
    self.proc.stateChanged.connect(self.__build_state_changed__)
    #self.proc.setReadChannel(QtCore.QProcess.StandardError)
    self.proc.start(comm)
    
    #self.proc.start("make", "configure brand="++" verbose=-v")

  def run_external_proc(self, cmd,working_dir, state_changed=None):
    self.proc = QtCore.QProcess(self)
    self.proc.setWorkingDirectory(working_dir)
    self.proc.readyReadStandardOutput.connect(self.__show_output__)
    self.proc.readyReadStandardOutput.connect(self.__show_error__)
    self.proc.setProcessChannelMode(QtCore.QProcess.ProcessChannelMode.MergedChannels)
    if state_changed:
      self.proc.stateChanged.connect(state_changed)
    self.proc.closeWriteChannel()
    #self.proc.setReadChannel(QtCore.QProcess.StandardError)
    self.proc.start(cmd)
    #self.proc.start("make", "configure brand="++" verbose=-v")

  def __show_output__(self):
    output = self.proc.readAllStandardOutput()
    self.txt_output.append(str(output))
    
  def __show_error__(self):
    output = self.proc.readAllStandardError()
    self.txt_output.append(str(output))
  
  def __build_state_changed__(self, st):
    if st== QtCore.QProcess.ProcessState.NotRunning:  
      if self.build_step == 1:
        if self.cb_revert.isChecked():
          print "Reverting changes"
          self.start_build("git reset --hard HEAD", self.working_dir)
        else:
          print "Skipped Reverting"
          self.build_step+=1
          
      if self.build_step == 2:
        self.btn_build.setText("Build Again")
        self.freeze_buttons(False)
        self.building = False
        self.build_step = -1
    #if  QtCore.QProcess.ProcessState. 
    
  def cancel_build(self):
    print "cancelled"
    self.txt_output.clear()
    
  def freeze_buttons(self, freeze):
    self.cmb_brands.setDisabled(freeze)
    self.cmb_platforms.setDisabled(freeze)
    self.cb_verbose.setDisabled(freeze)
    self.btn_configure.setDisabled(freeze)
    self.btn_install_on_device.setDisabled(freeze)
    self.btn_reset_scm.setDisabled(freeze)
Exemple #6
0
 def set_message_receiver(self):
   self.messages_thread = MessageSubsriberThread(port)
   self.messages_thread.on_message_received.connect(self.on_message_received)
   self.messages_thread.start(QtCore.QThread.TimeCriticalPriority)
Exemple #7
0
class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
    def __init__(self, *args, **kwargs):
        self.fullScreen = False
        super(MainWindow, self).__init__(*args, **kwargs)
        self.setupUi(self)
        self.show()
        self.pb_build_progress.setHidden(True)
        self.bind_controls()
        self.building = False
        self.proc = None
        self.build_step = 0
        self.working_dir = None
        self.regex_tool = None
        self.config = None

    def bind_controls(self):
        self.btn_build.clicked.connect(self.on_build_clicked)
        self.cmb_brands.currentIndexChanged.connect(self.on_brand_changed)
        self.brands_model = SimpleStringListModel(self.get_available_brands())
        self.cmb_brands.setModel(self.brands_model)

        self.cmb_platforms.setModel(
            SimpleStringListModel(self.get_platforms_for_brand(None)))
        self.cmb_platforms.currentIndexChanged.connect(
            self.on_platform_changed)
        self.btn_configure.clicked.connect(self.on_configure_clicked)
        self.btn_show_config.clicked.connect(self.on_show_config_clicked)
        self.btn_install_on_device.clicked.connect(self.on_install_clicked)
        self.btn_reset_scm.clicked.connect(self.on_scm_reset_clicked)
        self.btn_sign.clicked.connect(self.on_sign_app_clicked)
        self.actionRegex_Tool.triggered.connect(self.on_toggle_regex_tool)

    ###### Event Handlers #######

    def on_toggle_regex_tool(self):
        global regex_shown
        if not self.regex_tool:
            self.regex_tool = RegexTool()
        if regex_shown:
            self.regex_tool.hide()
        else:
            self.regex_tool.show()
        regex_shown = not regex_shown

    def on_scm_reset_clicked(self):
        def state_changed(state):
            if state == QtCore.QProcess.ProcessState.NotRunning:
                self.run_external_proc("git clean -f",
                                       os.path.dirname(self.working_dir))

        self.run_external_proc("git reset --hard HEAD",
                               os.path.dirname(self.working_dir),
                               state_changed)

    def on_show_config_clicked(self):
        if self.working_dir:
            self.config = FileConfigLoader(
                self.get_config_path()).load_config()
            self.cfg = ConfigWindow(self)
            self.cfg.set_configuration(self.get_config_path(),
                                       self.working_dir)
            self.cfg.cw.set_save_path(self.get_config_path())
            self.cfg.show()

    def on_brand_changed(self):
        brand = self.cmb_brands.currentText()
        self.cmb_platforms.setModel(
            SimpleStringListModel(self.get_platforms_for_brand(brand)))

    def on_platform_changed(self):
        ind = self.cmb_platforms.currentIndex()
        if ind > 0:
            self.working_dir = solution_dir.replace(
                '{PlatformType}',
                solution_for_platform[self.cmb_platforms.currentText()])
            self.config = FileConfigLoader(
                self.get_config_path()).load_config()
        else:
            self.working_dir = None

    def on_configure_clicked(self):
        config_loader = FileConfigLoader(self.get_config_path())
        builder = AppConfigurator(config_loader,
                                  ZmqChainedLoger(port),
                                  verbose=self.cb_verbose.isChecked(),
                                  debug_mode=self.cb_verbose.isChecked())

        builder.set_execution_dir(self.working_dir)
        self.worker = ConfigRunnerThread(builder)
        self.set_message_receiver()
        self.worker.start()
        self.worker.finished.connect(self.on_worker_finished)

    def on_worker_finished(self):
        self.worker.builder = None
        del self.worker
        self.messages_thread.terminate()
        del self.messages_thread

    def set_message_receiver(self):
        self.messages_thread = MessageSubsriberThread(port)
        self.messages_thread.on_message_received.connect(
            self.on_message_received)
        self.messages_thread.start(QtCore.QThread.TimeCriticalPriority)

    def on_message_received(self, message):
        self.txt_output.append("%s" % message)

    def on_build_clicked(self):
        if self.working_dir:
            if self.is_repo_clean():
                self.building = not self.building
                if self.building:
                    self.start_build("make build",
                                     os.path.dirname(self.working_dir))
                    self.btn_build.setText("Cancel")
                    self.freeze_buttons(True)
                else:
                    self.cancel_build()
                    self.btn_build.setText("Build")
                    self.freeze_buttons(False)
            else:
                print "repo is not commited"
        else:
            print "no working dir set"

    def on_sign_app_clicked(self):
        self.run_external_proc("make sign", os.path.dirname(self.working_dir))

    def on_install_clicked(self):
        self.run_external_proc("make install",
                               os.path.dirname(self.working_dir))

    ######End Event Handlers #######

    def get_config_path(self):
        global_vars = GlobalVars.get_instance()
        global_vars.current_config_path = os.path.join(
            config_path, self.cmb_brands.currentText(),
            self.cmb_platforms.currentText(), "bc.json")
        return global_vars.current_config_path

        #self.pb_build_progress.setHidden(not self.building)

    def get_available_brands(self):
        brands = [
            d for d in os.listdir(config_path)
            if os.path.isdir(os.path.join(config_path, d))
        ]
        brands.insert(0, "--Select Brand--")
        return brands

    def get_platforms_for_brand(self, brand):
        plats = []
        if brand:
            bpath = os.path.join(config_path, brand)
            if os.path.exists(bpath):
                plats = [
                    d for d in os.listdir(bpath)
                    if os.path.isdir(os.path.join(bpath, d))
                ]
        plats.insert(0, "--Select Platform--")
        return plats

    def is_repo_clean(self):
        #self.start_build("git status", self.working_dir)
        return True

    def start_build(self, comm, working_dir):
        self.build_step += 1
        print working_dir
        print "building"
        self.proc = QtCore.QProcess(self)
        self.proc.setWorkingDirectory(working_dir)
        self.proc.readyReadStandardOutput.connect(self.__show_output__)
        self.proc.readyReadStandardOutput.connect(self.__show_error__)
        self.proc.setProcessChannelMode(
            QtCore.QProcess.ProcessChannelMode.MergedChannels)
        self.proc.closeWriteChannel()
        self.proc.stateChanged.connect(self.__build_state_changed__)
        #self.proc.setReadChannel(QtCore.QProcess.StandardError)
        self.proc.start(comm)

        #self.proc.start("make", "configure brand="++" verbose=-v")

    def run_external_proc(self, cmd, working_dir, state_changed=None):
        self.proc = QtCore.QProcess(self)
        self.proc.setWorkingDirectory(working_dir)
        self.proc.readyReadStandardOutput.connect(self.__show_output__)
        self.proc.readyReadStandardOutput.connect(self.__show_error__)
        self.proc.setProcessChannelMode(
            QtCore.QProcess.ProcessChannelMode.MergedChannels)
        if state_changed:
            self.proc.stateChanged.connect(state_changed)
        self.proc.closeWriteChannel()
        #self.proc.setReadChannel(QtCore.QProcess.StandardError)
        self.proc.start(cmd)
        #self.proc.start("make", "configure brand="++" verbose=-v")

    def __show_output__(self):
        output = self.proc.readAllStandardOutput()
        self.txt_output.append(str(output))

    def __show_error__(self):
        output = self.proc.readAllStandardError()
        self.txt_output.append(str(output))

    def __build_state_changed__(self, st):
        if st == QtCore.QProcess.ProcessState.NotRunning:
            if self.build_step == 1:
                if self.cb_revert.isChecked():
                    print "Reverting changes"
                    self.start_build("git reset --hard HEAD", self.working_dir)
                else:
                    print "Skipped Reverting"
                    self.build_step += 1

            if self.build_step == 2:
                self.btn_build.setText("Build Again")
                self.freeze_buttons(False)
                self.building = False
                self.build_step = -1
        #if  QtCore.QProcess.ProcessState.

    def cancel_build(self):
        print "cancelled"
        self.txt_output.clear()

    def freeze_buttons(self, freeze):
        self.cmb_brands.setDisabled(freeze)
        self.cmb_platforms.setDisabled(freeze)
        self.cb_verbose.setDisabled(freeze)
        self.btn_configure.setDisabled(freeze)
        self.btn_install_on_device.setDisabled(freeze)
        self.btn_reset_scm.setDisabled(freeze)
Exemple #8
0
 def set_message_receiver(self):
     self.messages_thread = MessageSubsriberThread(port)
     self.messages_thread.on_message_received.connect(
         self.on_message_received)
     self.messages_thread.start(QtCore.QThread.TimeCriticalPriority)