コード例 #1
0
    def run(self):

        argu = ["get"]
        opt = atrdict.AttrDict({
            "serverno": None,
            "server": self.conf["Server"]
        })
        result = initcommand(opt, argu, self.conf)
        print result
        self.emit(SIGNAL('connected(QString)'), result)
コード例 #2
0
ファイル: Server.py プロジェクト: maxburian/SAXS
 def _checkdirectorycollision(self,pathlist):
      if not self.serverid=="Local":
          serverconfs=json.load(open(os.path.expanduser("~"+os.sep+".saxsdognetwork")))
          mydir=os.path.normpath(os.sep.join(pathlist))
          
          for i,conf in enumerate(serverconfs):
             if i!=self.serverid and self.serverid!="Local":
                 argu=["get"]
                 opt=atrdict.AttrDict({"serverno":i,"server":conf["Server"]})
                 result=json.loads(Leash.initcommand(opt,argu,conf))
                 if result['result']=="cal":
                     otherpath=os.path.normpath(os.sep.join(result["data"]["cal"]['Directory']))
                     
                 
                     if ((otherpath.startswith(mydir) or mydir.startswith(otherpath))
                         or (otherpath=="." or mydir==".")):
                         raise DirectoryCollisionException("Directory collides with: "+otherpath)
コード例 #3
0
ファイル: Server.py プロジェクト: maxburian/SAXS
 def start_image_queue(self,object,attachment):
     """
     prepare new image queue
     start processing threads
     """
     self.lasttime=time.time()
     self.lastcount=0
     self.history=history()
     self.attachments=[]        
     try:
         self._checkdirectorycollision(object['argument']['calibration']['Directory'])
         for attachstr in attachment:
             self.attachments.append(json.loads(attachstr))        
         self.calibration=object['argument']['calibration']
         if object['argument']['calibration'].get("Threads")>0:
             self.threads=object['argument']['calibration'].get("Threads")
         else:
             self.threads=self.options.threads
         self.threads=max(self.threads,2)
         print "abort old queue"
         if self.imagequeue:
              self.queue_abort()
         print "aborted old queue"
         
         o=atrdict.AttrDict({"plotwindow":False,"threads":self.threads,
                 		"watch":self.options.watchdir,
                         "watchdir":os.sep.join(object['argument']['calibration'].get("Directory")),
                         "servermode":True,
                         "silent":True,"plotwindow":False,
                         "walkdirinthreads":True,
                 		"outdir":self.options.outdir,
                         "relpath":self.options.relpath,
                 		"writesvg":False,
                         "writepng":False,"resume":False,
                         "serverport":self.serverport,
                         "nowalk":True,
                         "GISAXSmode":self.calibration["GISAXSmode"],
                         "livefilelist":"xxx",
                         "OverwriteFiles":False
                          })
         cals=[]
         
         dir=os.path.normpath(
             os.path.join(
                           self.serverdir,
                          os.sep.join(object['argument']['calibration'].get('Directory')
                         )))
         if "Masks" in object['argument']['calibration']:
             for mnumber,mask in enumerate(object['argument']['calibration']["Masks"]):
                 cals.append(calibration.calibration(
                                             object['argument']['calibration'],
                                             mask,
                                             self.attachments[mnumber]))
         if "Slices" in   object['argument']['calibration']:
             for slice in object['argument']['calibration']["Slices"]:
                 cals.append(GISAXSSlices.slice(object['argument']['calibration'],slice,self.attachments))
         
         if self.calibration["OverwriteFiles"]:
             o["OverwriteFiles"]=True
         
         '''Create empty file for filelisting'''
         filelist_path="xxx"
         if self.calibration["Live-Filelisting"]:
             filelist_path = os.path.join(os.path.split(dir)[0],"results")
             filelist_name = "filelist_" + os.path.split(dir)[1]+".log"
             filelist_path = os.path.join(filelist_path,filelist_name)
             try:
                 open(filelist_path, "w+").close()
                 o["livefilelist"]=filelist_path
             except:
                 print "Couldn't open " + filelist_path
             
         self.imagequeue=imagequeuelib.imagequeue(cals,
                 o,dir,self.serverconf)
         print "startimgq"
         self.imagequeueprocess=Process(target=self.imagequeue.start)
         self.imagequeueprocess.start()
         print "listening to feeder"
         serverdir= self.serverdir
         self.feederproc=Process(target=subscribeToFileChanges,args=
                                 (self.imagequeue,
                                  self.feederurl,
                                 dir,
                                 serverdir
                                 )
                                 )
         print "directory to watch "+dir
     
         self.feederproc.start()
         
         self.queuestatrtime=time.time()
         self.plotresult={"result":"Empty","data":{"stat":self.stat()}}
        
         result={"result":"new queue","data":{"cal":object['argument']['calibration']}}
     except IOError as e: 
         result={"result":"IOError","data":{"Error": str(e).replace("\n"," ")}}
     except ValueError as e:
         result={"result":"ValueError","data":{"Error": str(e)}}
     except Exception as e:
         result={"result":"Error","data":{"Error": str(e)}}
         print e
     return result
コード例 #4
0
ファイル: Server.py プロジェクト: isaxs/SAXS
    def start_image_queue(self, object, attachment):
        """
        prepare new image queue
        start processing threads
        """
        self.lasttime = time.time()
        self.lastcount = 0
        self.history = history()
        self.attachments = []
        for attachstr in attachment:
            self.attachments.append(json.loads(attachstr))
        self.calibration = object['argument']['calibration']
        print "abort old queue"
        if self.imagequeue:
            self.queue_abort()
        print "aborted old queue"
        try:
            if object['argument']['calibration'].get("Threads") > 0:
                self.threads = object['argument']['calibration'].get("Threads")
            else:
                self.threads = self.options.threads
            o = atrdict.AttrDict({
                "plotwindow":
                False,
                "threads":
                self.threads,
                "watch":
                self.options.watchdir,
                "watchdir":
                os.sep.join(
                    object['argument']['calibration'].get("Directory")),
                "servermode":
                True,
                "silent":
                True,
                "plotwindow":
                False,
                "walkdirinthreads":
                True,
                "outdir":
                self.options.outdir,
                "relpath":
                self.options.relpath,
                "writesvg":
                False,
                "writepng":
                False,
                "resume":
                False,
                "serverport":
                self.serverport
            })
            cals = []

            dir = os.path.normpath(
                os.path.join(
                    self.args[0],
                    os.sep.join(
                        object['argument']['calibration'].get('Directory'))))
            for mnumber, mask in enumerate(
                    object['argument']['calibration']["Masks"]):
                cals.append(
                    calibration.calibration(object['argument']['calibration'],
                                            mask, self.attachments[mnumber]))
            self.imagequeue = imagequeuelib.imagequeue(cals, o, [dir],
                                                       self.serverconf)
            print "startimgq"
            self.imagequeueprocess = Process(target=self.imagequeue.start)
            self.imagequeueprocess.start()
            print "listening to feeder"
            serverdir = self.args[0]
            self.feederproc = Process(target=subscribeToFileChanges,
                                      args=(self.imagequeue, self.feederurl,
                                            dir, serverdir))
            print "directory to watch " + dir

            self.feederproc.start()

            self.queuestatrtime = time.time()
            self.plotresult = {
                "result": "Empty",
                "data": {
                    "stat": self.stat()
                }
            }

            result = {
                "result": "new queue",
                "data": {
                    "cal": object['argument']['calibration']
                }
            }
        except IOError as e:
            result = {
                "result": "IOError",
                "data": {
                    "Error": str(e).replace("\n", " ")
                }
            }
        except ValueError as e:
            result = {"result": "ValueError", "data": {"Error": str(e)}}
        except Exception as e:
            result = {"result": "Error", "data": {"Error": str(e)}}
            print e
        return result
コード例 #5
0
  def __init__(self,app,parent=None):
      usage = ("usage: %prog  [options] [arguments]")
      parser = OptionParser(usage)
      parser.add_option("-S", "--server", dest="server",
                    help='URL of "Saxsdog Server"', metavar="tcp://HOSTNAME:PORT",default="")
      (self.options, self.args) = parser.parse_args(args=None, values=None)
      
      super(LeashUI,self).__init__(parent)
     
      self.clipboard=app.clipboard()
      self.ui=uic.loadUi(os.path.dirname(__file__)+os.sep+"LeashMW.ui",self)
      self.mainWindow=super(LeashUI,self)
      self.mainWindow.setWindowTitle("SAXS Leash")
      self.appdir=os.path.dirname(__file__)+os.sep
      self.mainWindow.setWindowIcon(QIcon(self.appdir+"icons"+os.sep+"program.png"))
      self.ui.tabWidget.setCurrentIndex(0)
      self.data=atrdict.AttrDict({})
      self.data.cal=None
      self.data.queueon=False
      self.ui.resize(1000,800)
      self.plotthread=QThread(parent=self)
      self.serveronline=False
      self.connect(self.ui.actionLoad_Calibration, SIGNAL("triggered()"),self.newFile)
      self.connect(self.ui.actionNew_Calibration, SIGNAL("triggered()"),self.newfromscratch)
      self.connect(self.ui.actionSave_Calibration,SIGNAL('triggered()'),self.safecalibration)
      self.connect(self.ui.actionSave_Calibration_as,SIGNAL('triggered()'),self.safecalibrationas)
      self.connect(self.ui.actionImport,SIGNAL('triggered()'),self.importcalib)
      self.connect(self.ui.actionAbort_Queue ,SIGNAL('triggered()'),self.abortqueue)
      self.connect(self.ui.actionClose_Queue ,SIGNAL('triggered()'),self.closequeue)
      self.connect(self.ui.actionShow_Server_Configuration ,SIGNAL('triggered()'),self.showserver)
      self.connect(self.ui.action_Reread_Directory ,SIGNAL('triggered()'),self.rereaddir)
      
      self.connect(self.ui.actionOpen_Hep_in_Browser ,SIGNAL('triggered()'),self.help)
 
      self.data.calschema=json.load(open(os.path.dirname(__file__)+os.sep+'schema.json')) 
      self.ui.treeWidgetCal.clear()
      self.ui.treeWidgetCal.setColumnWidth (0, 200 )
      self.ui.toolButtonRescale.setText("Fit to Window")
      self.connect(self.ui.toolButtonRescale, SIGNAL("clicked()"), self.resizemask)
      self.connect(self.ui.pushButtonLoadMask, SIGNAL("clicked()"), self.pickmask)
     
      self.connect(self.ui.pushButtonnew, SIGNAL('clicked()'),self.commandnew)
      self.figure = plt.figure()
      self.figurehist=plt.figure()
      self.plotcanvas= FigureCanvas(self.figure)
      self.canvashist= FigureCanvas(self.figurehist)
      self.ui.verticalLayout_3.addWidget(self.plotcanvas)
      self.ylogchkbox=QCheckBox("Y Log Scale")
      self.ylogchkbox.setCheckState(2)
      self.ui.verticalLayout_3.addWidget(self.ylogchkbox)
   
      self.ui.verticalLayout_5.addWidget( self.canvashist)
      self.plotworker = plotthread(self )
      self.connect(self.ylogchkbox, SIGNAL("stateChanged(int)"),self.plotworker.setyscale)
      self.data.queueon=True
      self.recentfilemenue=recentfilemenue(self,self.ui.menuSAXS_Leash )
      self.connect(self.recentfilemenue, SIGNAL('openFile(QString)'),self.newFile)
      self.connect(self.plotworker, SIGNAL('update(QString)'),self.statupdate)
      self.errmsg=QErrorMessage(self)
      self.errmsg.setWindowTitle("Error")
      self.changeportdialog()
      self.filename=""
      self.logbox= self.ui.textBrowserLogs
      self.log("hello")
      self.ui.Threads.setValue(2)
      QShortcut(QKeySequence("Ctrl+Q"), self, self.close)
      QShortcut(QKeySequence("Ctrl+O"), self, self.newFile)
      QShortcut(QKeySequence("Ctrl+S"),self,self.safecalibration)
      QShortcut(QKeySequence("Ctrl+I"),self,self.importcalib)
      self.connect(self.ui,SIGNAL("reconnect()"),self.reconnect)
      
      if len( sys.argv)>1:
          if os.path.isfile(sys.argv[1]):
              print sys.argv[1]
              self.filename=sys.argv[1]
              self.newFile(filename=self.filename)
              self.plotworker.start()
              return
      self.emit(SIGNAL('reconnect()'))
      self.directory=["","",""]
      self.directorypicker= directorypicker(self)