def object_description_sentence( objid, type, director): """given an object's id, return a sentence describing the object. In case the id is empty, return a sentence saying the object is not yet created, please create it. In case the id is valid, return a sentence describing the object, and a link to configure the object. """ if objid == '': link = action_link( actionRequireAuthentication( type.lower(), director.sentry, label = 'create', routine = 'new', ), director.cgihome) obj_ctrl = "%s has not been defined. Please %s a %s" % ( type, link, type.lower()) else: link = action_link( actionRequireAuthentication( type.lower(), director.sentry, label = 'configure', routine = 'new', ), director.cgihome) method = 'get%s' % type method = getattr( director.clerk, method ) obj_record = method( objid ) obj_ctrl = "%s (%s)" % ( obj_record.short_description, link) pass return obj_ctrl
class NeutronExperiment(base): class Inventory(base.Inventory): import pyre.inventory id = pyre.inventory.str("id", default=None) id.meta['tip'] = "the unique identifier of the experiment" ncount = pyre.inventory.float( 'ncount', default = 1e6 ) ncount.meta['tip'] = 'number of neutrons' pass # end of Inventory def default(self, director): try: page = director.retrieveSecurePage( 'neutronexperiment' ) except AuthenticationError, err: return err.page main = page._body._content._main # populate the main column document = main.document(title='Neutron Experiment') document.description = '' document.byline = 'byline?' p = document.paragraph() action = actionRequireAuthentication( actor = 'neutronexperimentwizard', sentry = director.sentry, label = 'this wizard', routine = 'start', ) wizard_link = action_link( action, director.cgihome ) action = actionRequireAuthentication( actor = 'neutronexperiment', sentry = director.sentry, label = 'experiments', routine = 'listall', ) list_link = action_link( action, director.cgihome ) p.text = [ 'In this virtual neutron facility, you can set up', 'a new experiment by using %s.' % wizard_link, 'Or you can select from one of the %s you have run' % list_link, 'and rerun it with new settings.', ] return page
def listall(self, director): page = director.retrievePage('scatteringKernel') main = page._body._content._main # populate the main column document = main.document(title='List of scattering kernels') document.description = '' document.byline = 'byline?' # retrieve id:record dictionary from db clerk = director.clerk scatteringKernels = clerk.indexScatteringKernels().values() scatteringKernels = [ clerk.getHierarchy(scatteringKernel) for scatteringKernel in scatteringKernels] p = document.paragraph() numScatteringKernels = len(scatteringKernels) columns = ['id', 'reference', 'short_description', 'type', 'creator', 'date' ] columnTitles = ['Short description', 'Type of scattering kernel', 'Creator', 'Date of creation'] from PyHtmlTable import PyHtmlTable t = PyHtmlTable(numScatteringKernels, len(columnTitles), {'width':'400','border':2})#,'bgcolor':'white'}) for colNum, col in enumerate(columnTitles): t.setc(0,colNum,col) for row, sk in enumerate(scatteringKernels): for colNum, colName in enumerate( columns[2:] ): value = sk.getColumnValue(colName) if colName == 'short_description': link = action_link( actionRequireAuthentication( 'scatteringKernel', director.sentry, label = value, routine = 'show', id = sk.id, ), director.cgihome ) value = link t.setc(row+1,colNum,value) p.text = [t.return_html()] p = document.paragraph() p.text = [action_link( actionRequireAuthentication( 'scatteringKernelInput', director.sentry, label = 'Add a new scattering kernel'), director.cgihome ), '<br>'] return page
def list( container, document, actor, director, routines = ['edit'] ): p = document.paragraph() formatstr = '%(index)s: %(name)s ' formatstr += ' '.join( [ '(%'+'(%slink)s)' % routine for routine in routines ] ) for i, element in enumerate( container ): p = document.paragraph() subs = {'name': element.short_description, 'index': i+1} #links for routine in routines: link = action_link( actionRequireAuthentication( actor, director.sentry, routine = routine, label = routine, id = element.id, ), director.cgihome ) subs[ '%slink' % routine ] = link continue p.text += [ formatstr % subs, ] continue return
def listall(self, director): page = director.retrievePage( 'job' ) main = page._body._content._main # populate the main column document = main.document(title='List of computational jobs') document.description = '' document.byline = 'byline?' # retrieve id:record dictionary from db clerk = director.clerk jobs = clerk.getJobs( where = 'owner=%r' % director.sentry.username ) p = document.paragraph() numJobs = len(jobs) columns = [ 'jobName', 'id', 'owner', 'server', 'numprocessors', 'status', 'timeStart', 'timeCompletion', ] numColumns=len(columns) from PyHtmlTable import PyHtmlTable t=PyHtmlTable(numJobs,numColumns, {'width':'400','border':2,'bgcolor':'white'}) for colNum, col in enumerate(columns): t.setc(0,colNum,col) continue for row, job in enumerate( jobs ): for colNum, colName in enumerate( columns ): value = job.getColumnValue(colName) if colName == 'jobName': link = action_link( actionRequireAuthentication( 'job', director.sentry, label = value, routine = 'show', id = job.id, ), director.cgihome ) value = link pass # endif t.setc(row+1,colNum,value) #colNum+=1 p.text = [t.return_html()] return page
def _add_delete_sentence(self, document, director): p = document.paragraph() action = actionRequireAuthentication( label = 'here', actor = 'neutronexperiment', routine = 'delete', sentry = director.sentry, id = self.inventory.id) link = action_link( action, director.cgihome ) p.text = [ 'To delete this experiment, please click %s.' % link, ] return
def _add_run_sentence(self, document, director): p = document.paragraph() action = actionRequireAuthentication( label = 'here', actor = 'neutronexperiment', routine = 'run', sentry = director.sentry, id = self.inventory.id) link = action_link( action, director.cgihome ) p.text = [ 'If you are done with experiment configuration,', 'please click %s to start this experiment.' % link, ] return
def _add_revision_sentence(self, document, director): p = document.paragraph() action = actionRequireAuthentication( label = 'here', actor = 'neutronexperimentwizard', routine = 'start', sentry = director.sentry, id = self.inventory.id) link = action_link( action, director.cgihome ) p.text = [ 'If you need to make changes to this experiment,', 'please click %s.' % link, ] return
def _footer(self, document, director): # document.paragraph() p = document.paragraph(align='right') action = actionRequireAuthentication(label='Cancel', actor='neutronexperimentwizard', routine='cancel', id=self.inventory.id, sentry=director.sentry) link = action_link(action, director.cgihome) p.text = [ '%s this experiment planning.' % link, ] return
def _footer(self, document, director): # document.paragraph() p = document.paragraph(align = 'right') action = actionRequireAuthentication( label = 'Cancel', actor = 'neutronexperimentwizard', routine = 'cancel', id = self.inventory.id, sentry = director.sentry) link = action_link( action, director.cgihome ) p.text = [ '%s this experiment planning.' % link, ] return
def noscatterer(document, director): p = document.paragraph() link = action_link( actionRequireAuthentication( 'scatterer', director.sentry, label='add', routine='new', ), director.cgihome) p.text = [ "There is no scatterer in this sample assembly. ", 'Please %s a scatter.' % (director.cgihome, link) ] return
def noscatterer( document, director ): p = document.paragraph() link = action_link( actionRequireAuthentication( 'scatterer', director.sentry, label = 'add', routine = 'new', ), director.cgihome ) p.text = [ "There is no scatterer. ", 'Please %s a scatter.' % ( director.cgihome, link) ] return
main = page._body._content._main # populate the main column document = main.document(title='Experiments') document.description = '' document.byline = 'byline?' # p = document.paragraph() action = actionRequireAuthentication( label = 'this wizard', actor = 'neutronexperimentwizard', routine = 'start', sentry = director.sentry, ) link = action_link( action, director.cgihome ) p.text = [ 'You can perform various kinds of neutron experiments in', 'this virtual neutron facility.', 'To start, you can plan a new experiment by following %s.' % link, ] # retrieve id:record dictionary from db clerk = director.clerk experiments = clerk.indexNeutronExperiments() # make a list of all experiments listexperiments( experiments.values(), document, director ) return page def view(self, director):
def listexperiments( experiments, document, director ): p = document.paragraph() n = len(experiments) p.text = [ 'Here is a list of experiments you have planned or run:' ] formatstr = '%(index)s: %(viewlink)s (%(status)s) is a measurement of %(sample)r in %(instrument)r (%(deletelink)s)' actor = 'neutronexperiment' container = experiments for i, element in enumerate( container ): p = document.paragraph() name = element.short_description if name in ['', None, 'None'] : name = 'undefined' action = actionRequireAuthentication( actor, director.sentry, routine = 'view', label = name, id = element.id, ) viewlink = action_link( action, director.cgihome ) action = actionRequireAuthentication( actor, director.sentry, routine = 'delete', label = 'delete', id = element.id, ) deletelink = action_link( action, director.cgihome ) element = director.clerk.getHierarchy( element ) if element.instrument is None \ or element.instrument.instrument is None: action = actionRequireAuthentication( 'neutronexperimentwizard', sentry = director.sentry, label = 'select instrument', routine = 'select_instrument', id = element.id, ) link = action_link( action, director.cgihome ) instrument = link else: instrument = element.instrument.instrument instrument = instrument.short_description pass # end if subs = {'index': i+1, 'viewlink': viewlink, 'deletelink': deletelink, 'status': element.status, 'instrument': instrument, 'sample': 'sample', } p.text += [ formatstr % subs, ] continue return
label='', id=self.inventory.id, arguments={'form-received': formcomponent.name}, ) from vnf.weaver import action_formfields action_formfields(action, form) # expand the form with fields of the data object that is being edited formcomponent.expand(form) p = form.paragraph() p.text = [ action_link( actionRequireAuthentication( 'neutronexperimentwizard', director.sentry, label='Add a new sample', #routine = 'create_new_sample', routine='input_material', id=self.inventory.id), director.cgihome), '<br>' ] submit = form.control(name='submit', type="submit", value="next") #self.processFormInputs(director) # self._footer( form, director ) return page def input_material(self, director): try: page = director.retrieveSecurePage('neutronexperimentwizard')
try: page = director.retrieveSecurePage( 'sampleassembly' ) except AuthenticationError, err: return err.page id = self.inventory.id record = director.clerk.getSampleAssembly( id ) record = director.getHierarchy( record ) scatterers = record.scatterers for scatterer in scatterers: p = document.paragraph() link = action_link( actionRequireAuthentication( 'scatterer', director.sentry, routine = 'addscatterer', label = 'add', ), director.cgihome ) continue p = document.paragraph() link = action_link( actionRequireAuthentication( 'sampleassemblywizard', director.sentry, routine = 'addscatterer', label = 'add', ), director.cgihome ) p.text = [
def listall(self, director): page = director.retrievePage('sample') main = page._body._content._main # populate the main column document = main.document(title='List of samples') document.description = '' document.byline = 'byline' # retrieve id:record dictionary from db clerk = director.clerk scatterers = clerk.indexScatterers(where='template=True').values() scatterers = [ clerk.getHierarchy(scatterer) for scatterer in scatterers ] samples = scatterers p = document.paragraph() import operator generators = [ operator.attrgetter('short_description'), lambda s: s.matter.realmatter.chemical_formula, lambda s: format_lattice_parameters(s.matter.realmatter), lambda s: format_atoms(s.matter.realmatter), lambda s: format_shape(s.shape.realshape), ] columnTitles = [ 'Sample description', 'Chemical formula', 'Cartesian lattice', 'Atom positions', 'Shape' ] t = PyHtmlTable(len(samples), len(columnTitles), { 'width': '90%', 'border': 2, 'bgcolor': 'white' }) # first row for labels for colNum, col in enumerate(columnTitles): t.setc(0, colNum, col) # other rows for values for row, sample in enumerate(samples): #first put in the radio button #selection = "<input type='radio' name='actor.form-received.kernel_id' value="+sample.id+" id='radio'/>" #t.setc(row+1, 0, selection) for colNum, generator in enumerate(generators): value = generator(sample) t.setc(row + 1, colNum, value) p.text = [t.return_html()] p = document.paragraph() p.text = [ action_link( actionRequireAuthentication('sampleInput', director.sentry, label='Add a new sample', routine='default'), director.cgihome), '<br>' ] return page
routine = 'configure_scatteringkernels', label = '', id=self.inventory.id, arguments = {'form-received': formcomponent.name }, ) from vnf.weaver import action_formfields action_formfields( action, form ) # expand the form with fields of the data object that is being edited formcomponent.expand( form ) p = form.paragraph() p.text = [action_link( actionRequireAuthentication( 'neutronexperimentwizard', director.sentry, label = 'Add a new sample', #routine = 'create_new_sample', routine = 'input_material', id=self.inventory.id ), director.cgihome),'<br>'] submit = form.control(name='submit',type="submit", value="next") #self.processFormInputs(director) # self._footer( form, director ) return page def input_material(self, director): try: page = director.retrieveSecurePage( 'neutronexperimentwizard' ) except AuthenticationError, err: return err.page
id = self.inventory.id record = director.clerk.getJob( id ) assert record.owner == director.sentry.username main = page._body._content._main document = main.document( title = 'Job # %s: %s' % ( record.id, record.status ) ) if record.status == 'created': p = document.paragraph() link = action_link( actionRequireAuthentication( 'job', director.sentry, label = 'submit', routine = 'edit', id = record.id, ), director.cgihome ) p.text = [ 'This job is created but not submitted.', 'Please %s it first' % link, ] return page if record.status not in ['created', 'finished']: status = check( record, director ) props = record.getColumnNames()
try: page = director.retrieveSecurePage('sampleassembly') except AuthenticationError, err: return err.page id = self.inventory.id record = director.clerk.getSampleAssembly(id) record = director.getHierarchy(record) scatterers = record.scatterers for scatterer in scatterers: p = document.paragraph() link = action_link( actionRequireAuthentication( 'scatterer', director.sentry, routine='addscatterer', label='add', ), director.cgihome) continue p = document.paragraph() link = action_link( actionRequireAuthentication( 'sampleassemblywizard', director.sentry, routine='addscatterer', label='add', ), director.cgihome) p.text = [ 'There is no scatterer in sample assembly at this moment. ',
def listall(self, director): page = director.retrievePage('job') main = page._body._content._main # populate the main column document = main.document(title='List of computational jobs') document.description = '' document.byline = 'byline?' # retrieve id:record dictionary from db clerk = director.clerk jobs = clerk.getJobs(where='owner=%r' % director.sentry.username) p = document.paragraph() numJobs = len(jobs) columns = [ 'jobName', 'id', 'owner', 'server', 'numprocessors', 'status', 'timeStart', 'timeCompletion', ] numColumns = len(columns) from PyHtmlTable import PyHtmlTable t = PyHtmlTable(numJobs, numColumns, { 'width': '400', 'border': 2, 'bgcolor': 'white' }) for colNum, col in enumerate(columns): t.setc(0, colNum, col) continue for row, job in enumerate(jobs): for colNum, colName in enumerate(columns): value = job.getColumnValue(colName) if colName == 'jobName': link = action_link( actionRequireAuthentication( 'job', director.sentry, label=value, routine='show', id=job.id, ), director.cgihome) value = link pass # endif t.setc(row + 1, colNum, value) #colNum+=1 p.text = [t.return_html()] return page
return err.page id = self.inventory.id record = director.clerk.getJob(id) assert record.owner == director.sentry.username main = page._body._content._main document = main.document(title='Job # %s: %s' % (record.id, record.status)) if record.status == 'created': p = document.paragraph() link = action_link( actionRequireAuthentication( 'job', director.sentry, label='submit', routine='edit', id=record.id, ), director.cgihome) p.text = [ 'This job is created but not submitted.', 'Please %s it first' % link, ] return page if record.status not in ['created', 'finished']: status = check(record, director) props = record.getColumnNames() lines = ['%s=%s' % (prop, getattr(record, prop)) for prop in props]
page = director.retrieveSecurePage( 'sampleassembly' ) except AuthenticationError, err: return err.page main = page._body._content._main # populate the main column document = main.document(title='List of sample assemblies') document.description = '' document.byline = 'byline?' p = document.paragraph() link = action_link( actionRequireAuthentication( 'sampleassembly', director.sentry, label = 'link', routine = 'new', ), director.cgihome ) p.text = [ 'To create a new sample assembly, please use this %s' % link ] p = document.paragraph() p = document.paragraph() # retrieve id:record dictionary from db clerk = director.clerk sampleassemblies = clerk.indexSampleAssemblies() listsampleassemblies( sampleassemblies.values(), document, director )
def listall(self, director): page = director.retrievePage('scatteringKernel') main = page._body._content._main # populate the main column document = main.document(title='List of scattering kernels') document.description = '' document.byline = 'byline?' # retrieve id:record dictionary from db clerk = director.clerk scatteringKernels = clerk.indexScatteringKernels().values() scatteringKernels = [ clerk.getHierarchy(scatteringKernel) for scatteringKernel in scatteringKernels ] p = document.paragraph() numScatteringKernels = len(scatteringKernels) columns = [ 'id', 'reference', 'short_description', 'type', 'creator', 'date' ] columnTitles = [ 'Short description', 'Type of scattering kernel', 'Creator', 'Date of creation' ] from PyHtmlTable import PyHtmlTable t = PyHtmlTable(numScatteringKernels, len(columnTitles), { 'width': '400', 'border': 2 }) #,'bgcolor':'white'}) for colNum, col in enumerate(columnTitles): t.setc(0, colNum, col) for row, sk in enumerate(scatteringKernels): for colNum, colName in enumerate(columns[2:]): value = sk.getColumnValue(colName) if colName == 'short_description': link = action_link( actionRequireAuthentication( 'scatteringKernel', director.sentry, label=value, routine='show', id=sk.id, ), director.cgihome) value = link t.setc(row + 1, colNum, value) p.text = [t.return_html()] p = document.paragraph() p.text = [ action_link( actionRequireAuthentication( 'scatteringKernelInput', director.sentry, label='Add a new scattering kernel'), director.cgihome), '<br>' ] return page
page = director.retrieveSecurePage('sampleassembly') except AuthenticationError, err: return err.page main = page._body._content._main # populate the main column document = main.document(title='List of sample assemblies') document.description = '' document.byline = 'byline?' p = document.paragraph() link = action_link( actionRequireAuthentication( 'sampleassembly', director.sentry, label='link', routine='new', ), director.cgihome) p.text = ['To create a new sample assembly, please use this %s' % link] p = document.paragraph() p = document.paragraph() # retrieve id:record dictionary from db clerk = director.clerk sampleassemblies = clerk.indexSampleAssemblies() listsampleassemblies(sampleassemblies.values(), document, director) return page
class Greeter(Actor): class Inventory(Actor.Inventory): import pyre.inventory def default(self, director): try: page = director.retrieveSecurePage('greet') except AuthenticationError, error: return error.page main = page._body._content._main # populate the main column username = director.sentry.username userrecord = director.clerk.getUser(username) fullname = userrecord.fullname title = 'Welcome to the Virtual Neutron Facility, %s!' % (fullname, ), document = main.document(title=title) p = document.paragraph() action = actionRequireAuthentication( actor='neutronexperiment', sentry=director.sentry, label='run virtual neutron experiments', routine='default', ) link = action_link(action, director.cgihome) p.text = [ 'In this web service facility, you can %s. ' % link, 'In a virtual neutron experiment, ', 'virtual neutrons are generated from a virtual neutron moderator,', 'guided by virtual neutron guides,', 'scattered by a virtual sample and sample environment,', 'and intercepted by detectors.', ] p = document.paragraph() action = actionRequireAuthentication( actor='instrument', sentry=director.sentry, label='neutron instruments', routine='listall', ) link = action_link(action, director.cgihome) p.text = [ 'You can do your experiments on a variety of %s,' % link, 'both actual physical instruments and conceptual, nonphysical instruments' ] p = document.paragraph() action = actionRequireAuthentication( actor='scatteringKernel', sentry=director.sentry, label='scattering kernels', routine='default', ) link = action_link(action, director.cgihome) p.text = [ 'You can also create your sample and predict its neutron', 'scattering properties by calculating its structure or dynamics.', 'For example, the material behaviors calculated by ab initio', 'or molecular dynamics methods become', '%s that can be used in the sample simulation' % link, 'part of your virtual experiment.', ] p = document.paragraph() p.text = [ 'On the left, several menu items link to a variety of', 'functions.', 'You can review past experiments by clicking "Experiments",', 'or browse your personal library of sample assemblies by', 'clicking "Sample Assemblies".', 'Neutron instruments in which you can run your experiments', 'are accessible through "Instruments".', 'When you start a virtual experiment, or a material', 'simulation, they became jobs submitted to computing', 'resources. You can monitor their progress by clicking', '"Jobs".', ] p = document.paragraph() email = '<a href="mailto:[email protected]">us</a>' p.text = [ 'We welcome your comments on this web service, ', 'suggestions for new features, and reports of', 'discrepancies or bugs.' ] return page