<s> import numpy as np <EOL> import json <EOL> import urllib2 <EOL> from lxml import etree <EOL> from django . conf import settings <EOL> import ocpcadb <EOL> from ocptype import ZSLICES <EOL> import logging <EOL> logger = logging . getLogger ( "<STR_LIT>" ) <EOL> def projdict ( proj ) : <EOL> projdict = { } <EOL> projdict [ '<STR_LIT:name>' ] = proj . getProjectName ( ) <EOL> projdict [ '<STR_LIT:description>' ] = proj . getProjectDescription ( ) <EOL> projdict [ '<STR_LIT:version>' ] = proj . getOCPVersion ( ) <EOL> return projdict <EOL> def datasetdict ( dataset ) : <EOL> dsdict = { } <EOL> dsdict [ '<STR_LIT:name>' ] = dataset . getDatasetName ( ) <EOL> dsdict [ '<STR_LIT>' ] = dataset . scalinglevels <EOL> if dataset . scalingoption == ZSLICES : <EOL> dsdict [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> else : <EOL> dsdict [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> dsdict [ '<STR_LIT>' ] = dataset . resolutions <EOL> dsdict [ '<STR_LIT>' ] = dataset . imagesz <EOL> dsdict [ '<STR_LIT>' ] = dataset . offset <EOL> dsdict [ '<STR_LIT>' ] = dataset . voxelres <EOL> dsdict [ '<STR_LIT>' ] = dataset . cubedim <EOL> dsdict [ '<STR_LIT>' ] = dataset . nearisoscaledown <EOL> dsdict [ '<STR_LIT>' ] = dataset . neariso_offset <EOL> dsdict [ '<STR_LIT>' ] = dataset . neariso_voxelres <EOL> dsdict [ '<STR_LIT>' ] = dataset . neariso_imagesz <EOL> dsdict [ '<STR_LIT>' ] = dataset . timerange <EOL> dsdict [ '<STR_LIT:description>' ] = dataset . getDatasetDescription ( ) <EOL> return dsdict <EOL> def chandict ( channel ) : <EOL> chandict = { } <EOL> chandict [ '<STR_LIT>' ] = channel . getChannelType ( ) <EOL> chandict [ '<STR_LIT>' ] = channel . getDataType ( ) <EOL> chandict [ '<STR_LIT>' ] = channel . getExceptions ( ) <EOL> chandict [ '<STR_LIT>' ] = channel . getReadOnly ( ) <EOL> chandict [ '<STR_LIT>' ] = channel . getResolution ( ) <EOL> chandict [ '<STR_LIT>' ] = channel . getPropagate ( ) <EOL> chandict [ '<STR_LIT>' ] = channel . getWindowRange ( ) <EOL> chandict [ '<STR_LIT:description>' ] = channel . getChannelDescription ( ) <EOL> return chandict <EOL> def jsonInfo ( proj ) : <EOL> """<STR_LIT>""" <EOL> jsonprojinfo = { } <EOL> jsonprojinfo [ '<STR_LIT>' ] = datasetdict ( proj . datasetcfg ) <EOL> jsonprojinfo [ '<STR_LIT>' ] = projdict ( proj ) <EOL> jsonprojinfo [ '<STR_LIT>' ] = { } <EOL> for ch in proj . projectChannels ( ) : <EOL> jsonprojinfo [ '<STR_LIT>' ] [ ch . getChannelName ( ) ] = chandict ( ch ) <EOL> jsonprojinfo [ '<STR_LIT>' ] = metadatadict ( proj ) <EOL> return json . dumps ( jsonprojinfo , sort_keys = True , indent = <NUM_LIT:4> ) <EOL> def xmlInfo ( token , proj ) : <EOL> """<STR_LIT>""" <EOL> jsonprojinfo = { } <EOL> jsonprojinfo [ '<STR_LIT>' ] = datasetdict ( proj . datasetcfg ) <EOL> jsonprojinfo [ '<STR_LIT>' ] = projdict ( proj ) <EOL> jsonprojinfo [ '<STR_LIT>' ] = { } <EOL> for ch in proj . projectChannels ( ) : <EOL> jsonprojinfo [ '<STR_LIT>' ] [ ch . getChannelName ( ) ] = chandict ( ch ) <EOL> jsonprojinfo [ '<STR_LIT>' ] = metadatadict ( proj ) <EOL> root = etree . Element ( '<STR_LIT>' , InputChecksum = "<STR_LIT>" , host = "<STR_LIT>" , name = token , num_sections = str ( jsonprojinfo [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:2> ] ) , num_stos = "<STR_LIT:0>" , path = "<STR_LIT>" ) <EOL> etree . SubElement ( root , '<STR_LIT>' , UnitsOfMeasure = "<STR_LIT>" , UnitsPerPixel = str ( jsonprojinfo [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] / jsonprojinfo [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] ) ) <EOL> tileserver_element = etree . SubElement ( root , '<STR_LIT>' , CoordSpaceName = "<STR_LIT>" , host = "<STR_LIT>" , FilePrefix = "<STR_LIT>" , FilePostfix = "<STR_LIT>" , TileXDim = "<STR_LIT>" , TileYDim = "<STR_LIT>" , GridXdim = str ( jsonprojinfo [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] / <NUM_LIT> ) , GridYDim = str ( jsonprojinfo [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] / <NUM_LIT> ) , MaxLevel = str ( jsonprojinfo [ '<STR_LIT>' ] [ "<STR_LIT>" ] [ - <NUM_LIT:1> ] ) ) <EOL> for channel_name in jsonprojinfo [ '<STR_LIT>' ] . keys ( ) : <EOL> etree . SubElement ( tileserver_element , "<STR_LIT>" , Name = channel_name , Path = channel_name , Datatype = jsonprojinfo [ '<STR_LIT>' ] [ channel_name ] [ '<STR_LIT>' ] ) <EOL> for slice_number in range ( jsonprojinfo [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:2> ] , jsonprojinfo [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:2> ] + jsonprojinfo [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:2> ] ) : <EOL> etree . SubElement ( root , "<STR_LIT>" , Number = "<STR_LIT:{}>" . format ( slice_number ) ) <EOL> return etree . tostring ( root ) <EOL> def metadatadict ( proj ) : <EOL> """<STR_LIT>""" <EOL> if settings . LIMS_SERVER_ENABLED : <EOL> try : <EOL> url = '<STR_LIT>' . format ( settings . LIMS_SERVER , proj . getProjectName ( ) ) <EOL> req = urllib2 . Request ( url ) <EOL> response = urllib2 . urlopen ( req , timeout = <NUM_LIT:0.5> ) <EOL> return json . loads ( response . read ( ) ) <EOL> except urllib2 . URLError , e : <EOL> print "<STR_LIT>" . format ( url ) <EOL> return { } <EOL> else : <EOL> return { } <EOL> def publicTokens ( projdb ) : <EOL> """<STR_LIT>""" <EOL> tokens = projdb . getPublic ( ) <EOL> return json . dumps ( tokens , sort_keys = True , indent = <NUM_LIT:4> ) </s>
