def hLineTest(self):
        self.logger.info("hLineTest")
        hline = HLine(240, Yaml().load("{ azimuth: 240, elevation: 60 }"))
        t1 = round(hline.getElevationAtAzimuth(240))
        self.logger.debug(t1)
        assert t1 == 60

        t2 = hline.getElevationAtAzimuth(200)
        self.logger.debug(t2)
        assert t2 < 55 and t2 > 50

        hline2 = HLine(240, Yaml().load("{ azimuth: 200, elevation: 53 }"))
        t3 = hline2.getElevationAtAzimuth(240)
        assert round(t3) == 60
        t4 = hline2.getElevationAtAzimuth(60)
        assert t4 < 0

        # two measurements back and forth
        hline3 = HLine(150, Yaml().load("{ azimuth: 145, elevation: 62.5 }"))
        hline4 = HLine(150, Yaml().load("{ azimuth: 198.3, elevation: 52.4 }"))

        t5 = hline3.getElevationAtAzimuth(198.3)
        t6 = hline4.getElevationAtAzimuth(145)
        #self.logger.info("t5:" + str(t5))
        #self.logger.info("t6:" + str(t6))
        assert round(t5) == 52
        assert round(t6) == 63
示例#2
0
def readYaml(file):
    from java.io import FileInputStream
    from org.yaml.snakeyaml import Yaml

    input = FileInputStream(file)
    yaml = Yaml()
    data = yaml.load(input)
    return data
示例#3
0
def getFormatData(type):
    from org.yaml.snakeyaml import Yaml
    from java.io import ByteArrayInputStream
    formatData = loadResource('template.yaml')
    input = java.io.ByteArrayInputStream(formatData)
    yaml = Yaml()
    data = yaml.load(input)
    return data[type]
    def lineTest(self):
        self.logger.info("lineTest")
        line1 = Line(
            60,
            Yaml().load("""
             - { azimuth: 120, elevation: 35.82 }
             - { azimuth: 110, elevation: 49 }
             """))
        line = Line(
            240,
            Yaml().load("""
             - { azimuth: 197.28, elevation: 39.54 }
             - { azimuth: 227, elevation: 59 }
             """))
        line3 = Line(
            240,
            Yaml().load("""
             - { azimuth: 197.28, elevation: 39.54 }
             - { azimuth: 199.52, elevation: 41.56 }
             """))
        line4 = Line(
            240,
            Yaml().load("""
             - { azimuth: 197.28, elevation: 39.54, angle: -35 }
             """))

        # gäste
        line5 = Line(
            240,
            Yaml().load("""
             - { azimuth: 174.88, elevation: 30.3 }
             - { azimuth: 189.58, elevation: 53.66 }
             """))
        self.logger.debug(line.getElevationAtAzimuth(240))
        self.logger.debug(line.getElevationAtAzimuth(224))
        self.logger.debug(line.getElevationAtAzimuth(227))
        self.logger.debug(line.getElevationAtAzimuth(200))
        self.logger.debug(line.getElevationAtAzimuth(199.52))
        self.logger.debug(line.getElevationAtAzimuth(180))
        self.logger.debug(line.getElevationAtAzimuth(170))
        self.logger.debug(line.getElevationAtAzimuth(160))
        self.logger.debug(line.getElevationAtAzimuth(150))
        self.logger.debug(line.getElevationAtAzimuth(290))
        self.logger.debug(line.getElevationAtAzimuth(300))
        self.logger.debug(line.getElevationAtAzimuth(310))
        self.logger.debug(line.getElevationAtAzimuth(320))
        self.logger.debug(line.getElevationAtAzimuth(330))
        self.logger.debug(line.getElevationAtAzimuth(175))
        self.logger.debug(line5.getElevationAtAzimuth(181.68))

        assert round(line.getElevationAtAzimuth(240)) == 62
        assert round(line.getElevationAtAzimuth(224)) == 58
        assert round(line.getElevationAtAzimuth(227)) == 59
        assert round(line.getElevationAtAzimuth(199.52)) == 42

        assert round(line.getElevationAtAzimuth(174)) == 0
示例#5
0
def genNEFYaml(fileName):

    input = 'nef : ' + fileName + '\n'
    input += yamlStr

    print input
    
    yaml = Yaml()
    data = yaml.load(input)
    return data
示例#6
0
def genYaml():
    input = '''
molecule :
  entities :
    - sequence : GPGAST
      type : nv
      ptype : protein

anneal:
    steps : 1000
    highTemp : 1000.0
'''
    yaml = Yaml()
    data = yaml.load(input)
    return data
示例#7
0
def dumpYamlWin(yamlFile):
    yaml = Yaml()
    win = {}
    win['geometry'] = nw.geometry()
    win['title'] = "Test"
    win['grid'] = nw.getGrid()
    win['sconfig'] = nw.sconfig()
    (rows, cols) = win['grid']
    spectra = []
    win['spectra'] = spectra
    nCharts = nw.nCharts()
    for iSpectrum in range(nCharts):
        nw.active(iSpectrum)
        sd = {}
        spectra.append(sd)
        iRow = iSpectrum / cols
        iCol = iSpectrum % cols
        sd['grid'] = [iRow, iCol]
        sd['lim'] = nw.lim()
        sd['cconfig'] = nw.cconfig()
        sd['datasets'] = []
        datasets = nw.datasets()
        for dataset in datasets:
            dset = {}
            dset['name'] = dataset
            dset['config'] = nw.config(dataset)
            dset['dims'] = nw.getDims(dataset)
            sd['datasets'].append(dset)
        sd['peaklists'] = []
        peakLists = nw.peakLists()
        for peakList in peakLists:
            pset = {}
            pset['name'] = peakList
            pset['config'] = nw.pconfig(peakList)
            sd['peaklists'].append(pset)

    print win
    yamlDump = yaml.dump(win)
    with open(yamlFile, 'w') as fOut:
        fOut.write(yamlDump)
    def dailySchedulesTest(self, rules):
        self.logger.info("dailySchedulesTest")

        schedules = DailySchedules(
            Yaml().load("""
              weekend:
                - kids_evening
                - kids_open
              workday:
                - kids_open
              vacation:
                - kids_open
        """), rules)
        return schedules
    def sunExposureTest(self):
        self.logger.info("sunExposureTest")
        se = SunExposure(Yaml().load("""
            orientation: 240
            sun_openings:
              - azimuth: 160
                below:
                  - { azimuth: 240, elevation: 60 }
                above:
                  - { elevation: 5 }
              - azimuth: 240
                below:
                  - { azimuth: 240, elevation: 60 }
                above:
                  - { elevation: 3 }
              - azimuth: 330
            """))
        assert se.isSunlit(159, 9) == False

        assert se.isSunlit(161, 15) == True
        assert se.isSunlit(161, 6) == True
        assert se.isSunlit(161, 4) == False

        assert se.isSunlit(241, 58) == True
        assert se.isSunlit(241, 62) == False
        assert se.isSunlit(241, 4) == True
        assert se.isSunlit(325, 4) == True

        assert se.isSunlit(331, 4) == False

        se2 = SunExposure(Yaml().load("""
            orientation: 240
            sun_openings:
              - azimuth: 160
              - azimuth: 330
            """))
        assert se2.isSunlit(200, 9) == True
    def calendarTest(self, schedules):
        self.logger.info("calendarTest")

        calendar = Calendar(
            Yaml().load("""
            - desc: "Sommerferien"
              timerange: {from: "12.06.2017", to: "16.08.2017" }
              daily_schedule: vacation
            - desc: "Weekend"
              cron: "? * 7,1 *"
              daily_schedule: weekend
            - desc: "Workdays"
              cron: "? * 2-6 *"
              daily_schedule: workday
        """), schedules).getDailyScheduleName()
    def rulesTest(self):
        self.logger.info("rulesTest")

        rules = Rules(
            Yaml().load("""
            kids_evening:
                triggers:
                  - cron: '0 30 19'
                action: MANUAL
                items:
                  - shutter_living
            kids_open:
                triggers:
                  - cron: '0 30 20'
                  - channel_event: {channel: 'astro:sun:local:nauticDusk#event', event: 'START'}
                action: SUN
                items:
                  - shutter_living
        """), {'shutter_automation': 'shutter_automation'})
        return rules
示例#12
0
文件: nomjyc.py 项目: relet/nomjyc
class nomjyc (HttpServlet):
  """
This is the nomjyc web interface. Nomic is a game where the players change the rules. 
Nomjyc is the same game, except that the rules are written in jython. 

Called without parameters, it will most probably just display its own rules. 
Call it with GET or POST parameters to execute and change them. 
Read the code to understand how.

Just kidding. We have a wiki at <a href="http://nomjyc.ath.cx:8080/cgi/fossil">http://nomjyc.ath.cx:8080/cgi/fossil</a>
"""

  def __init__(self):
    self.yaml          = Yaml()
    self.yamlLexer     = YamlLexer()
    self.pythonLexer   = PythonLexer()
    self.pythonTBLexer = PythonTracebackLexer()
    self.htmlFormatter = HtmlFormatter()

  def dumpData(self,c):
    rules = c.data["rules"]
    c.data["rules"] = "omitted"
    code = highlight(self.yaml.dump(c.data), self.yamlLexer, self.htmlFormatter)	
    c.data["rules"] = rules
    return code

  def dumpYaml(self, anything):
    #return highlight(self.yaml.dump(anything), self.yamlLexer, self.htmlFormatter)	
    return "<pre>%s</pre>" % self.yaml.dump(anything)
  def dumpPython(self, code):
    return highlight(code, self.pythonLexer, self.htmlFormatter)	
  def dumpPythonTB(self, code):
    return highlight(code, self.pythonTBLexer, self.htmlFormatter)	

  def explainException(self, title):
    nruter = "<div class=\"erroroutput\"><span class=\"gu\">%s</span>" % title
    exc_type, exc_value, exc_tb = sys.exc_info()
    for line in traceback.format_exception(exc_type, exc_value, exc_tb):
      nruter += "\n%s" % self.dumpPythonTB(line)
    return nruter + "</div>"
    
  def doGet(self, request, response):
    # Treat GET and POST equally
    self.doPost(request, response)

  DIV_HIDEOUS_BOX = "<div class=\"%s\"><div class=\"gh\">%s - <a href=\"javascript:ReverseDisplay('%s')\">show/hide %s</a></div><div id=\"%s\" style=\"display:%s\">%s</div>%s"
  def divHideCode(self, claz, title, id, data, visible=False, content="", openend=False):
    return self.DIV_HIDEOUS_BOX % (claz, title, id, content, id, visible and "show" or "none", data, openend and " " or "</div>")

  def doPost(self, request, response):
    c = NomjycContainer() # re-initialized container upon every request    
    c.parameters = request.getParameterMap()
    
    log = open("/var/log/nomjyc/nomjyc.log","a")
    safelog = dict(c.parameters)
    if "pass" in safelog:
      safelog["pass"]=len(safelog["pass"])
    log.write(("[[%s]] %s %s\n" % (request.getRemoteAddr(), datetime.utcnow(), self.yaml.dump(safelog))).encode("utf-8"))
    log.close()

    output = "<div class=\"infobox\"><span class=\"gh\">nomjyc 0.1</span>\n"
    c.session    = {}
    if len(c.parameters)==0:
      output += "<pre>%s</pre>" % self.__doc__
    output += "</div>"

    c.salt="dckx"

    try:
      c.data = self.yaml.load(FileInputStream("/var/lib/tomcat6/webapps/nomjyc/data/nomjyc.yaml"))
    except:
      output += self.explainException("Error while initiating game state - trying to load backup.")
      c.data = self.yaml.load(FileInputStream("/var/lib/tomcat6/webapps/nomjyc/data/nomjyc.bak"))

    # Print some debug information - for now.
    output += self.divHideCode("infobox", "Request", "reqi", self.dumpYaml(c.parameters), visible=True)
    output += self.divHideCode("infobox", "Data read", "dri", self.dumpYaml(c.data))

    # If we have come so far, we assume that it is safe to write a backup.
    try:
      self.yaml.dump(c.data, FileWriter("/var/lib/tomcat6/webapps/nomjyc/data/nomjyc.bak"))    
    except:
      output += self.explainException("Error while storing backup game state")
    
    # Execute all rules against the user input
    brain = PythonInterpreter()
    c.sandbox = False # a flag that tells that we are not in a sandbox
    checksum = hashlib.md5(self.yaml.dump(c.data)).hexdigest()
    for rule in c.data["rules"][:]: # we are going to modify the rules. a lot. this prevents concurrent modification.
      try:
        output += self.divHideCode("rulebox", "Executing rule '%s'" % rule["title"], "id"+str(random()), self.dumpPython(rule["code"]), openend=True)
        err = StringWriter()
        out = StringWriter()
        # Compile the rule into a jython/java class
        brain.set("self", c) # expose the container to the rules
        brain.setErr(err)
        brain.setOut(out)
        before = time.time()
        timeout (brain.exec,(rule["code"],),timeout_duration=30)
        runtime = int((time.time()-before) * 1000)
        newsum   = hashlib.md5(self.yaml.dump(c.data)).hexdigest()
        changes  = (checksum != newsum)
        checksum = newsum
        output += "<div class=\"ruleoutput\">" 
        if changes: output += "<div class=\"erroroutput\">This rule changed the game data.</div>"
        if (err.getBuffer().length()): output += "<div class=\"erroroutput\">Err:<br />%s</div>" % self.dumpPythonTB(err.toString())
        if (out.getBuffer().length()): output += "<div class=\"gu\">Out:</div>"+out.toString()
        output += "<div>(runtime: %sms)</div></div></div>" % runtime

      except Exception, ex:
        output += self.explainException("Execution failed") + "</div>"

    # Dump the data back to file    
    try:
      self.yaml.dump(c.data, FileWriter("/var/lib/tomcat6/webapps/nomjyc/data/nomjyc.yaml"))    
    except:
      output += self.explainException("Error while storing game state")

    # Print some debug information - for now.
    output += self.divHideCode("infobox", "Session data", "sess", self.dumpYaml(c.session), visible=True) 
    output += self.divHideCode("infobox", "Data stored", "dsf", self.dumpYaml(c.data)) 

    # Send all output to the user (xml or html?)
    toClient = response.getWriter()
    response.setContentType("text/html")
    toClient.println("""
<html>
  <head>
    <title>Nomjyc</title>
    <link rel="stylesheet" type="text/css" href="pygments.css" />
    <script type="text/javascript" src="nomjyc.js"></script>
  </head>
  <body>%s</body>
</html>
""" % output)
 def horizonTest(self):
     self.logger.info("horizonTest")
     horizon = Horizon(240, Yaml().load("{ elevation: 53 }"))
     assert horizon.getElevationAtAzimuth(60) == 53
     assert horizon.getElevationAtAzimuth(200) == 53
示例#14
0
def loadYamlWin(yamlFile, createNewStage=True):
    with open(yamlFile) as fIn:
        inputData = fIn.read()
    yaml = Yaml()
    if createNewStage > 0:
        nw.new()
        pathComps = os.path.split(yamlFile)
        title = pathComps[1]
        if title.endswith('_fav.yaml'):
            title = title[0:-9]
        elif title.endswith('.yaml'):
            title = title[0:-5]
        nw.setTitle(title)
    data = yaml.load(inputData)
    if 'geometry' in data:
        (x, y, w, h) = data['geometry']
        nw.geometry(x, y, w, h)
    if 'grid' in data:
        (rows, cols) = data['grid']
        nw.grid(rows, cols)
    if 'sconfig' in data:
        sconfig = data['sconfig']
        nw.sconfig(sconfig)
    spectra = data['spectra']
    for v in spectra:
        print v
        datasets = v['datasets']
        if 'grid' in v:
            (iRow, iCol) = v['grid']
        else:
            iRow = 0
            iCol = 0
        activeWin = iRow * cols + iCol
        print 'g', iRow, iCol, activeWin
        nw.active(activeWin)
        if 'cconfig' in v:
            cconfig = v['cconfig']
            nw.cconfig(cconfig)
        datasetValues = []
        for dataset in datasets:
            print dataset
            name = dataset['name']
            datasetValues.append(name)
        print 'dv', datasetValues
        nw.cmd.datasets(datasetValues)
        if 'lim' in v:
            lim = v['lim']
            nw.lim(lim)
        for dataset in datasets:
            name = dataset['name']
            if 'config' in dataset:
                cfg = dataset['config']
                nw.config(datasets=[name], pars=cfg)
            if 'dims' in dataset:
                dims = dataset['dims']
                nw.setDims(dataset=name, dims=dims)

        if 'peaklists' in v:
            peakLists = v['peaklists']
            peakListValues = []
            for peakList in peakLists:
                print peakList
                name = peakList['name']
                peakListValues.append(name)
            print 'dv', peakListValues
            nw.cmd.peakLists(peakListValues)
            for peakList in peakLists:
                name = peakList['name']
                if 'config' in peakList:
                    cfg = peakList['config']
                    nw.pconfig(peakLists=[name], pars=cfg)
        nw.drawAll()
 def __init__(self):
     self.logger = logging.getLogger(logger_name + ".Config")
     self.shutterConfig = Yaml().load(open(shuttersFile))
     self.scheduleConfig = Yaml().load(open(scheduleFile))
     self.logger.info("Config loaded")
import de.embl.cba.metadata.MetaData as MetaData
import de.embl.cba.metadata.MetadataCreator as MetadataCreator
import ij.IJ as IJ
import org.yaml.snakeyaml.DumperOptions as DumperOptions
import org.yaml.snakeyaml.Yaml as Yaml
import java.io.FileWriter as FileWriter

file = "/Volumes/cba/exchange/OeyvindOedegaard/yaml_project/01_TestFiles/20180627_LSM780M2_208_ibidi1_fcs_B_Posx96.lsm"
metadataCreator = MetadataCreator(file)
metadata = metadataCreator.getMetadata()

dumperOptions = DumperOptions()
dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK)

outputPath = "/Volumes/cba/exchange/OeyvindOedegaard/yaml_project/test.yaml"
yaml = Yaml(dumperOptions)
writer = FileWriter(outputPath)
yaml.dump(metadata, writer)
writer.flush()
writer.close()

IJ.open(outputPath)
示例#17
0
 def __init__(self):
     self.logger = LoggerFactory.getLogger(logger_name + ".Config")
     self.gardenaConfig = Yaml().load(open(gardena_config_file))
     self.logger.info("Config loaded")
示例#18
0
        iEntity += 1

def isRNA(mol):
    polymers = mol.getPolymers()
    rna = False
    for polymer in polymers:
        for residue in polymer.getResidues():
            resName = residue.getName()
            if resName in ["A","C","G","U"]:
                rna = True
                break
    return rna
                
if argFile.endswith('.yaml'):
    input = FileInputStream(argFile)
    yaml = Yaml()
    data = yaml.load(input)

    refiner=refine()
    osfiles.setOutFiles(refiner,dataDir, 0)
    refiner.rootName = "temp"
    refiner.loadFromYaml(data,0)
    mol = refiner.molecule
    vienna = data['rna']['vienna']
    mol.setDotBracket(vienna)
    #rnapred.predictFromSequence(mol,vienna)
    rnapred.predictFromSequence()
    rnapred.dumpPredictions(mol)
elif argFile.endswith('.pdb') or argFile.endswith('.cif'):
    if argFile.endswith('.pdb'):
        mol = molio.readPDB(argFile)
示例#19
0
文件: sandbox.py 项目: relet/nomjyc
 def __init__(self):
   self.yaml          = Yaml()
   self.yamlLexer     = YamlLexer()
   self.pythonLexer   = PythonLexer()
   self.pythonTBLexer = PythonTracebackLexer()
   self.htmlFormatter = HtmlFormatter()
示例#20
0
文件: sandbox.py 项目: relet/nomjyc
class nomjyc (HttpServlet):
  """
This is the sandbox of the nomjyc web interface. Please refer to 
<a href="http://nomjyc.ath.cx:8080">nomjyc.ath.cx:8080</a> for the main game. 

Called without parameters, it will most probably just display the nomjyc rules,
read from the main nomjyc game. Send a GET or POST parameter called "test" to 
add an arbitrary rule to be executed at the end of the rule list.
"""

  def __init__(self):
    self.yaml          = Yaml()
    self.yamlLexer     = YamlLexer()
    self.pythonLexer   = PythonLexer()
    self.pythonTBLexer = PythonTracebackLexer()
    self.htmlFormatter = HtmlFormatter()

  def dumpData(self,c):
    rules = c.data["rules"]
    c.data["rules"] = "omitted"
    code = highlight(self.yaml.dump(c.data), self.yamlLexer, self.htmlFormatter)	
    c.data["rules"] = rules 
    return code

  def dumpYaml(self, anything):
    return highlight(self.yaml.dump(anything), self.yamlLexer, self.htmlFormatter)	
  def dumpPython(self, code):
    return highlight(code, self.pythonLexer, self.htmlFormatter)	
  def dumpPythonTB(self, code):
    return highlight(code, self.pythonTBLexer, self.htmlFormatter)	

  def explainException(self, title):
    nruter = "<div class=\"erroroutput\"><span class=\"gu\">%s</span>" % title
    exc_type, exc_value, exc_tb = sys.exc_info()
    for line in traceback.format_exception(exc_type, exc_value, exc_tb):
      nruter += "\n%s" % self.dumpPythonTB(line)
    return nruter + "</div>"
    
  def doGet(self, request, response):
    # Treat GET and POST equally
    self.doPost(request, response)

  DIV_HIDEOUS_BOX = "<div class=\"%s\"><div class=\"gh\">%s - <a href=\"javascript:ReverseDisplay('%s')\">show/hide %s</a></div><div id=\"%s\" style=\"display:%s\">%s</div>%s"
  def divHideCode(self, claz, title, id, data, visible=False, content="", openend=False):
    return self.DIV_HIDEOUS_BOX % (claz, title, id, content, id, visible and "show" or "none", data, openend and " " or "</div>")

  def doPost(self, request, response):
    c = NomjycContainer()
    c.parameters = request.getParameterMap()

    log = open("/var/log/nomjyc/sandbox.log","a")
    safelog = dict(c.parameters)
    if "pass" in safelog:
      safelog["pass"]=len(safelog["pass"])
    log.write(("[[%s]] %s %s\n" % (request.getRemoteAddr(), datetime.utcnow(), self.yaml.dump(safelog))).encode("utf-8"))
    log.close()

    output = "<div class=\"infobox\"><span class=\"gh\">nomjyc 0.1</span>\n"
    c.session    = {}
    if len(c.parameters)==0:
      output += "<pre>%s</pre>" % self.__doc__
    output += "</div>"

    c.salt="dckx"

    try:
      c.data = self.yaml.load(FileInputStream("/var/lib/tomcat6/webapps/nomjyc/data/nomjyc.yaml"))
    except:
      output += self.explainException("Error while initiating game state")

    # Print some debug information - for now.
    output += self.divHideCode("infobox", "Request", "reqi", self.dumpYaml(c.parameters), visible=True)
    output += self.divHideCode("infobox", "Data read", "dri", self.dumpYaml(c.data))

    # Add a final rule, if the test parameter is set
    if "test" in c.parameters:
      for code in c.parameters["test"]:
        c.data["rules"].add({"author":"impromptu", "code":code, "creation":datetime.utcnow(), "title":"test rule"})

    cycles = 1
    if "cycles" in c.parameters:
      try: 
        cycles = int(c.parameters["cycles"][0])
      except:
        pass
    if cycles<0 or cycles>3:
      cycles = 1

    # Execute all rules against the user input
    brain = PythonInterpreter()
    c.sandbox = True # a flag that gives away that we are in a sandbox
    for i in range(cycles):
      c.cycle = i    # a counter for the cycle we are in
      for rule in c.data["rules"][:]: # we are going to modify the rules. a lot. this prevents concurrent modification.
        try:
          output += self.divHideCode("rulebox", "Executing rule '%s'" % rule["title"], "id"+str(random()), self.dumpPython(rule["code"]), openend=True)
   	  err = StringWriter()
  	  out = StringWriter()
          checksum = hashlib.md5(self.yaml.dump(c.data)).hexdigest()
          brain.set("self", c)
          brain.setErr(err)
          brain.setOut(out)
          before = time.time()
          timeout (brain.exec,(rule["code"],),timeout_duration=30)
          runtime = int((time.time()-before) * 1000)
          changes = (checksum != hashlib.md5(self.yaml.dump(c.data)).hexdigest())
          output += "<div class=\"ruleoutput\">"
          if changes: output += "<div class=\"erroroutput\">This rule changed the game data.</div>"
          if (err.getBuffer().length()): output += "<div class=\"erroroutput\">Err:<br />%s</div>" % self.dumpPythonTB(err.toString().strip())
          if (out.getBuffer().length()): output += "<div class=\"gu\">Out:</div>"+out.toString().strip()
          output += "<div>(runtime: %sms)</div></div></div>" % runtime

        except Exception, ex:
          output += self.explainException("Execution failed") + "</div>"

    # Dump the data back to file - but not in the sandbox 
    #try:
    #  self.yaml.dump(c.data, FileWriter("/var/lib/tomcat6/webapps/sandbox/data/nomjyc.yaml"))    
    #except:
    #  output += self.explainException("Error while storing game state")

    # Print some debug information - for now.
    output += self.divHideCode("infobox", "Session data", "sess", self.dumpYaml(c.session), visible=True) 
    output += self.divHideCode("infobox", "Data stored", "dsf", self.dumpYaml(c.data)) 

    # Send all output to the user (xml or html?)
    toClient = response.getWriter()
    response.setContentType("text/html")
    toClient.println("""
<html>
  <head>
    <title>Nomjyc</title>
    <link rel="stylesheet" type="text/css" href="pygments.css" />
    <script type="text/javascript" src="nomjyc.js"></script>
  </head>
  <body>%s</body>
</html>
""" % output)
示例#21
0
    def _readTemplate(self, file2read):
        '''
           evaluate if the template has a yaml format
        '''
        if not self.isYamlTemplate:
            initialFile = file2read
            logger.debug('[%s._readTemplate] Looking for file: "%s"' %
                         (self.__class__.__name__, initialFile))

            if not os.path.exists(file2read):
                # check both .yaml & .yml extension
                file2read = '%s.yaml' % (file2read)
                logger.debug('[%s._readTemplate] Looking for file: "%s"' %
                             (self.__class__.__name__, file2read))
                if os.path.exists(file2read):
                    self.isYamlTemplate = True
                else:
                    file2read = '%s.yml' % (file2read)
                    logger.debug('[%s._readTemplate] Looking for file: "%s"' %
                                 (self.__class__.__name__, file2read))
                    if os.path.exists(file2read):
                        self.isYamlTemplate = True
                    else:
                        logger.error(
                            '[%s._readTemplate] Template File "%s" doesn\'t exist (even with yaml extension)'
                            % (self.__class__.__name__, initialFile))
                        raise MySyntaxError(
                            '[%s._readTemplate] Template File "%s" doesn\'t exist (even with yaml extension)'
                            % (self.__class__.__name__, initialFile))

            # So the template file exists
            try:
                logger.debug('[%s._readTemplate] Reading template file "%s"' %
                             (self.__class__.__name__, file2read))
                lines = open(file2read, 'r').readlines()
            except:
                logger.error(
                    '[%s._readTemplate] failure opening template file "%s"' %
                    (self.__class__.__name__, file2read))
                raise MySyntaxError(
                    '[%s._readTemplate] failure opening template file "%s"' %
                    (self.__class__.__name__, file2read))

            # Shebang testing for Yaml format
            if not self.isYamlTemplate and (lines[0].find('#!yaml') >= 0
                                            or lines[0].find('#!yml') >= 0):
                self.isYamlTemplate = True

        if not self.isYamlTemplate:
            logger.error(
                '[%s._readTemplate] compatibility issue ! template must be YAML data',
                (self.__class__.__name__))
            raise SyntaxError(
                '[%s._readTemplate] compatibility issue ! template must be YAML data',
                (self.__class__.__name__))

        # Yaml format: load the string to Yaml if we don't have already
        if not self.yamlTemplate:
            yaml = Yaml(Constructor(), Representer(), DumperOptions(),
                        CustomResolver())
            try:
                self.yamlTemplate = yaml.load(''.join(lines).strip())
            except (MarkedYAMLException, YAMLException, ParserException,
                    ReaderException, ScannerException), e:
                logger.error('Error while parsing YAML-file "%s":\n%s' %
                             (file2read, e))
                raise MySyntaxError('Error while parsing YAML-file "%s":\n%s' %
                                    (file2read, e))

            logger.trace("_readTemplate - Loaded Yaml : '''%s'''" %
                         (self.yamlTemplate))
    def sunExposureRuleTest(self):
        testExposureConfig = Yaml().load("""
            shutter_living:
                orientation: 240
                sun_openings:
                  - azimuth: 160
                  - azimuth: 330
        """)
        testExposure = {}
        for shutter in testExposureConfig:
            testExposure[shutter] = SunExposure(testExposureConfig[shutter])
        ser = SunExposureRule(testExposure, "astro_sun_azimuth",
                              "astro_sun_elevation", "weather_sunny",
                              "shutter_automation", True)

        # values for DOWN = 100, STOP = 50, UP = 0
        shutterName = "shutter_living"
        shutterItem = ir.get(shutterName)
        sunlitStateItem = ir.get(prefix_sunlit + shutterName)
        autoStateItem = ir.get(prefix_auto + shutterName)
        isSunnyItem = ir.get("weather_sunny")

        events.postUpdate(isSunnyItem.getName(), "OFF")
        events.sendCommand(shutterItem.getName(), "DOWN")
        events.postUpdate(sunlitStateItem.getName(), sunlitStateFalse)
        events.postUpdate(autoStateItem.getName(), autoStateSun)

        # sunlit: true, state: SUN, weather: cloudy
        time.sleep(1)
        ser._execute(240, 30, True)
        time.sleep(1)
        assert shutterItem.getState().toString() == "100"

        # sunlit: true, state: SUN, weather: sunny
        events.postUpdate(isSunnyItem.getName(), "ON")
        time.sleep(1)
        ser._execute(240, 30, True)
        time.sleep(1)
        assert shutterItem.getState().toString() == "50"

        # sunlit: true, state: SUN, weather: cloudy
        events.postUpdate(isSunnyItem.getName(), "OFF")
        time.sleep(1)
        ser._execute(240, 30, True)
        time.sleep(1)
        assert shutterItem.getState().toString() == "50"

        # sunlit: false, state: SUN, weather: cloudy
        ser._execute(60, 30, True)
        time.sleep(1)
        assert shutterItem.getState().toString() == "0"

        # sunlit: true, state: DOWN, weather: sunny
        events.postUpdate(isSunnyItem.getName(), "ON")
        events.postUpdate(autoStateItem.getName(), autoStateDown)
        events.sendCommand(shutterItem.getName(), "DOWN")
        time.sleep(1)
        ser._execute(240, 30, True)
        time.sleep(1)
        assert shutterItem.getState().toString() == "100"

        # sunlit: false, state: DOWN, weather: sunny
        ser._execute(60, 30, True)
        time.sleep(1)
        assert shutterItem.getState().toString() == "100"

        # sunlit: true, state: UP, weather: sunny
        events.postUpdate(autoStateItem.getName(), autoStateUp)
        events.sendCommand(shutterItem.getName(), "UP")
        time.sleep(1)
        ser._execute(240, 30, True)
        time.sleep(1)
        assert shutterItem.getState().toString() == "0"

        # sunlit: false, state: UP, weather: sunny
        ser._execute(60, 30, True)
        time.sleep(1)
        assert shutterItem.getState().toString() == "0"

        # sunlit: true, state: MANUAL, weather: sunny
        events.postUpdate(autoStateItem.getName(), autoStateManual)
        events.postUpdate(sunlitStateItem.getName(), sunlitStateUnknown)
        events.sendCommand(shutterItem.getName(), "UP")
        time.sleep(1)
        ser._execute(240, 30, True)
        time.sleep(1)
        assert shutterItem.getState().toString() == "0"

        # sunlit: true, state: SUN, weather: sunny, sunlitstat: unknown
        events.postUpdate(autoStateItem.getName(), autoStateSun)
        time.sleep(1)
        ser._execute(240, 30, True)
        time.sleep(1)
        assert shutterItem.getState().toString() == "0"
        assert sunlitStateItem.getState().toString() == sunlitStateTrue
示例#23
0
def readYamlString(yamlString):
    from org.yaml.snakeyaml import Yaml

    yaml = Yaml()
    data = yaml.load(yamlString)
    return data
示例#24
0
import de.embl.cba.metadata.MetaData as MetaData;
import de.embl.cba.metadata.MetadataCreator as MetadataCreator;
import ij.IJ as IJ;
import org.yaml.snakeyaml.DumperOptions as DumperOptions;
import org.yaml.snakeyaml.Yaml as Yaml;
import java.io.FileInputStream as FileInputStream;

outputPath = "/Volumes/cba/exchange/OeyvindOedegaard/yaml_project/test.yaml";
yaml = Yaml();
md = yaml.load( FileInputStream( "/Volumes/cba/exchange/OeyvindOedegaard/yaml_project/test.yaml" ) );
metaDict = md.metadata
print( metaDict[ MetadataCreator.IMAGE_DIMENSIONS ] );
示例#25
0
def parseArgs():
    parser = OptionParser()
    parser.add_option("-p", "--pdbs", dest="pdbPath", default="")
    parser.add_option("-o", "--outDir", dest="outDir", default="analysis")

    parser.add_option("-y", "--yaml", dest="yamlFile", default=None)

    #Will now be used to add addition files to parse that are not included in the yaml file
    parser.add_option("-c",
                      "--convert",
                      action='store_true',
                      dest="modifyFileType",
                      default=False)  # not used!
    parser.add_option("-s", "--shifts", dest="shiftFile", default=None)
    parser.add_option("-d", "--distances", dest="disFile", default=None)
    parser.add_option("-r", "--range", dest="resRange", default="")

    (options, args) = parser.parse_args()
    outDir = os.path.join(homeDir, options.outDir)
    if not os.path.exists(outDir):
        os.mkdir(outDir)

    pdbFilePath = options.pdbPath
    if pdbFilePath == "":
        pdbFiles = args
    else:
        pdbFiles = getFiles(pdbFilePath)

    changeRange = (options.resRange != '')
    range = options.resRange

    if (options.yamlFile != None):
        input = FileInputStream(options.yamlFile)
        yaml = Yaml()
        data = yaml.load(input)
    else:
        data = {'ribose': True}

    if options.shiftFile != None:
        shift = {}
        if changeRange:
            shift['range'] = range
        arr = options.shiftFile.split(' ')
        if len(arr) == 1:
            shift['type'] = 'nv'
            shift['file'] = arr[0]
        else:
            shift['file'] = arr[0]
            if arr[1] == 's':
                shift['type'] = 'str3'
            elif arr[1] == 'n':
                shift['type'] = 'nv'
        data['shifts'] = shift
    else:
        if changeRange:
            data['shifts']['range'] = range

    if options.disFile != None:
        dis = {}
        if changeRange:
            dis['range'] = range

        arr = options.disFile.split(' ')
        if len(arr) == 1:
            dis['type'] = 'nv'
            dis['file'] = arr[0]
        else:
            dis['file'] = arr[0]
            if arr[1] == 'a':
                dis['type'] = 'amber'
            elif arr[1] == 'n':
                dis['type'] = 'nv'
        if 'distances' in data:
            included = checkIncluded(data['distances'], dis)
            if not included:
                data['distances'].append(dis)
            else:
                print dis[
                    'file'] + ' is already included in yaml file. Ignoring Duplicate.'
        else:
            data['distances'] = [dis]
    else:
        if changeRange:
            for dict in data['distances']:
                dict['range'] = range

    outFiles = loadPDBModels(pdbFiles, data, outDir)
    summary(outFiles)