Example #1
0
def saxsdog():
    """
    This implements the functionality of :ref:`saxsdog`
    """
    (options, args) = saxsdogparseopt()

    if options.profile:
        import cProfile, pstats, StringIO
        pr = cProfile.Profile()
    conf = json.load(open(options.calfilename, "r"))
    cals = []
    directory = args[0]
    if "Masks" in conf:
        for mnumber, mask in enumerate(conf["Masks"]):
            cals.append(calibration.calibration(conf, mask, None))
    if "Slices" in conf:
        for slice in conf["Slices"]:
            cals.append(GISAXSSlices.slice(conf, slice, None))
    imgq = imagequeuelib.imagequeue(cals, options, directory, None)
    if options.profile:
        pr.enable()

    imgq.start()

    if options.profile:
        pr.disable()
        s = StringIO.StringIO()
        sortby = 'cumulative'
        ps = pstats.Stats(pr, stream=s).sort_stats(sortby)
        ps.print_stats()
        print "#####################################"
        print '# Wrote profile to the file "prof". #'
        print '#####################################'
        open("prof", "w").write(s.getvalue())
Example #2
0
def saxsdogintqueue(Cal, options, args):
    """
    Initialize image queue object.
    """
    from imagequeuelib import imagequeue
    imqueue = imagequeue(Cal, options, args)
    if not options.nowalk: imqueue.fillqueuewithexistingfiles()
    return imqueue
Example #3
0
 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
Example #4
0
File: Server.py Project: 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