def updateMirroring(self): #print "UPDATE MIRRORING",self.myProposal,self.inControl if BlissWidget.isInstanceModeSlave(): if BlissWidget.isInstanceUserIdUnknown(): if BlissWidget.isInstanceRoleServer( ) and self.inControl is not None and self.inControl[1] is None: BlissWidget.setInstanceMirror( BlissWidget.INSTANCE_MIRROR_ALLOW) else: BlissWidget.setInstanceMirror( BlissWidget.INSTANCE_MIRROR_PREVENT) elif BlissWidget.isInstanceUserIdInhouse(): BlissWidget.setInstanceMirror( BlissWidget.INSTANCE_MIRROR_ALLOW) else: try: control_is_inhouse = self.inControl[1]['inhouse'] except: control_is_inhouse = False if control_is_inhouse or self.inControl[1] is None: BlissWidget.setInstanceMirror( BlissWidget.INSTANCE_MIRROR_ALLOW) else: try: my_prop_codes = [ self.myProposal['code'], self.myProposal['alias'] ] except: my_prop_codes = [] try: control_prop_codes = [ self.inControl[1]['code'], self.inControl[1]['alias'] ] except: control_prop_codes = [] mirror = BlissWidget.INSTANCE_MIRROR_PREVENT for code in my_prop_codes: try: control_prop_codes.index(code) except: pass else: mirror = BlissWidget.INSTANCE_MIRROR_ALLOW break for code in control_prop_codes: try: my_prop_codes.index(code) except: pass else: mirror = BlissWidget.INSTANCE_MIRROR_ALLOW break BlissWidget.setInstanceMirror(mirror) else: BlissWidget.setInstanceMirror(BlissWidget.INSTANCE_MIRROR_PREVENT)
def impersonateProposal(self, proposal_code, proposal_number): if BlissWidget.isInstanceUserIdInhouse(): self._do_login(proposal_code, proposal_number, None, self.dbConnection.beamline_name, impersonate=True) else: logging.getLogger().debug( 'ProposalBrick2: cannot impersonate unless logged as the inhouse user!' )
def impersonateProposal(self, proposal_code, proposal_number): if BlissWidget.isInstanceUserIdInhouse(): self._do_login( proposal_code, proposal_number, None, self.dbConnection.beamline_name, impersonate=True, ) else: logging.getLogger().debug( "SoleilLoginBrick: cannot impersonate unless logged as the inhouse user!" )
def updateMirroring(self): #print "UPDATE MIRRORING",self.myProposal,self.inControl if BlissWidget.isInstanceModeSlave(): if BlissWidget.isInstanceUserIdUnknown(): if BlissWidget.isInstanceRoleServer() and self.inControl is not None and self.inControl[1] is None: BlissWidget.setInstanceMirror(BlissWidget.INSTANCE_MIRROR_ALLOW) else: BlissWidget.setInstanceMirror(BlissWidget.INSTANCE_MIRROR_PREVENT) elif BlissWidget.isInstanceUserIdInhouse(): BlissWidget.setInstanceMirror(BlissWidget.INSTANCE_MIRROR_ALLOW) else: try: control_is_inhouse=self.inControl[1]['inhouse'] except: control_is_inhouse=False if control_is_inhouse or self.inControl[1] is None: BlissWidget.setInstanceMirror(BlissWidget.INSTANCE_MIRROR_ALLOW) else: try: my_prop_codes=[self.myProposal['code'],self.myProposal['alias']] except: my_prop_codes=[] try: control_prop_codes=[self.inControl[1]['code'],self.inControl[1]['alias']] except: control_prop_codes=[] mirror=BlissWidget.INSTANCE_MIRROR_PREVENT for code in my_prop_codes: try: control_prop_codes.index(code) except: pass else: mirror=BlissWidget.INSTANCE_MIRROR_ALLOW break for code in control_prop_codes: try: my_prop_codes.index(code) except: pass else: mirror=BlissWidget.INSTANCE_MIRROR_ALLOW break BlissWidget.setInstanceMirror(mirror) else: BlissWidget.setInstanceMirror(BlissWidget.INSTANCE_MIRROR_PREVENT)
def haveControl(self,have_control,gui_only=False): #print "INSTANCELISTBRICK.HAVECONTROL",have_control,gui_only if not gui_only: if have_control: BlissWidget.setInstanceMode(BlissWidget.INSTANCE_MODE_MASTER) else: BlissWidget.setInstanceMode(BlissWidget.INSTANCE_MODE_SLAVE) if have_control: if self.xmlrpc_server: gevent.spawn_later(1, self.xmlrpc_server.open) self.inControl=None self.takeControlButton.setEnabled(False) self.askForControlButton.setEnabled(False) self.listBox.setSelectionMode(QListBox.Single) self.listBox.clearSelection() i=self.listBox.firstItem() while i is not None: i.setSelectable(False) i=next(i) self.listBox.setSelectionMode(QListBox.NoSelection) else: if self.xmlrpc_server: self.xmlrpc_server.close() if BlissWidget.isInstanceUserIdLogged(): self.askForControlButton.setEnabled(True) elif BlissWidget.isInstanceUserIdInhouse(): if self.hutchtrigger is not None: hutch_opened = self.hutchtrigger.hutchIsOpened() #hutch_opened = 1-int(self.hutchtrigger.getChannelObject("status").getValue()) logging.getLogger().debug("%s: hutch is %s, %s 'Take control' button", self.name(), hutch_opened and "opened" or "close", hutch_opened and "disabling" or "enabling") self.takeControlButton.setEnabled(1-hutch_opened) #elif BlissWidget.isInstanceRoleServer(): # self.askForControlButton.setEnabled(True) if BlissWidget.isInstanceRoleServer(): self.takeControlButton.setEnabled(True) if not gui_only: if have_control: try: frombl = os.environ['SMIS_BEAMLINE_NAME'] #user = os.environ['SMIS_BEAMLINE_NAME'] #frombl = user.replace(' ','-') except (KeyError,TypeError,ValueError,AttributeError): frombl = 'ID??' try: proposal="%s-%d" % (self.myProposal["code"],self.myProposal["number"]) except: proposal="unknown" is_local=BlissWidget.isInstanceLocationLocal() if is_local: control_place="LOCAL" else: control_place="EXTERNAL" email_subject="[MX REMOTE ACCESS] %s control is %s (proposal %s)" % (frombl,control_place,proposal) email_toaddrs=self["controlEmails"] email_fromaddrs="*****@*****.**" % frombl msg_event=UserInfoDialogEvent("I've gained control of the application.",\ email_fromaddrs,email_toaddrs,email_subject,is_local,\ self.font().pointSize()) logging.getLogger('user_level_log').warning("You have gained control of the application.") #qApp.postEvent(self,msg_event) else: msg_event=MsgDialogEvent(QMessageBox.Warning,\ "I've lost control of the application!",\ self.font().pointSize()) logging.getLogger('user_level_log').warning("You have lost control of the application!")
def haveControl(self, have_control, gui_only=False): #print "INSTANCELISTBRICK.HAVECONTROL",have_control,gui_only if not gui_only: if have_control: BlissWidget.setInstanceMode(BlissWidget.INSTANCE_MODE_MASTER) else: BlissWidget.setInstanceMode(BlissWidget.INSTANCE_MODE_SLAVE) if have_control: if self.xmlrpc_server: gevent.spawn_later(1, self.xmlrpc_server.open) self.inControl = None self.takeControlButton.setEnabled(False) self.askForControlButton.setEnabled(False) self.listBox.setSelectionMode(QListBox.Single) self.listBox.clearSelection() i = self.listBox.firstItem() while i is not None: i.setSelectable(False) i = next(i) self.listBox.setSelectionMode(QListBox.NoSelection) else: if self.xmlrpc_server: self.xmlrpc_server.close() if BlissWidget.isInstanceUserIdLogged(): self.askForControlButton.setEnabled(True) elif BlissWidget.isInstanceUserIdInhouse(): if self.hutchtrigger is not None: hutch_opened = self.hutchtrigger.hutchIsOpened() #hutch_opened = 1-int(self.hutchtrigger.getChannelObject("status").getValue()) logging.getLogger().debug( "%s: hutch is %s, %s 'Take control' button", self.name(), hutch_opened and "opened" or "close", hutch_opened and "disabling" or "enabling") self.takeControlButton.setEnabled(1 - hutch_opened) #elif BlissWidget.isInstanceRoleServer(): # self.askForControlButton.setEnabled(True) if BlissWidget.isInstanceRoleServer(): self.takeControlButton.setEnabled(True) if not gui_only: if have_control: try: frombl = os.environ['SMIS_BEAMLINE_NAME'] #user = os.environ['SMIS_BEAMLINE_NAME'] #frombl = user.replace(' ','-') except (KeyError, TypeError, ValueError, AttributeError): frombl = 'ID??' try: proposal = "%s-%d" % (self.myProposal["code"], self.myProposal["number"]) except: proposal = "unknown" is_local = BlissWidget.isInstanceLocationLocal() if is_local: control_place = "LOCAL" else: control_place = "EXTERNAL" email_subject = "[MX REMOTE ACCESS] %s control is %s (proposal %s)" % ( frombl, control_place, proposal) email_toaddrs = self["controlEmails"] email_fromaddrs = "*****@*****.**" % frombl msg_event=UserInfoDialogEvent("I've gained control of the application.",\ email_fromaddrs,email_toaddrs,email_subject,is_local,\ self.font().pointSize()) logging.getLogger('user_level_log').warning( "You have gained control of the application.") #qApp.postEvent(self,msg_event) else: msg_event=MsgDialogEvent(QMessageBox.Warning,\ "I've lost control of the application!",\ self.font().pointSize()) logging.getLogger('user_level_log').warning( "You have lost control of the application!")