Skip to content
Snippets Groups Projects
Commit 801ccedf authored by Alejandro De Maria Antolinos's avatar Alejandro De Maria Antolinos
Browse files

It adds an example of usage from python

parent 925e27a1
No related branches found
No related tags found
No related merge requests found
......@@ -68,7 +68,9 @@ In both cases these folder locations point to the **parent** folder of the datas
MetadataManager has got as **optional** dependency graypy (https://pypi.python.org/pypi/graypy) and requests
It can be installed:
Requests is a requirement for sending notifications to the **elogbook** and graypy is required to use **Graylog**
They can be installed:
```
easy_install graypy
easy_install requests
......@@ -292,6 +294,88 @@ Select the files and follow the instruccions
Go the the requirements section where dependencies are explained: [Requirements](#requirements)
### Usage
#### Python
Example:
```
#!/usr/bin/env python
"""A simple client for MetadataManager and MetaExperiment
"""
import time
import os
import sys
import logging
import PyTango.client
from time import gmtime, strftime
class MetadataManagerClient(object):
metadataManager = None
metaExperiment = None
"""
A client for the MetadataManager and MetaExperiment tango Devices
Attributes:
name: name of the tango device. Example: 'id21/metadata/ingest'
"""
def __init__(self, metadataManagerName, metaExperimentName):
"""
Return a MetadataManagerClient object whose metadataManagerName is *metadataManagerName*
and metaExperimentName is *metaExperimentName*
"""
self.proposal = None
if metadataManagerName:
self.metadataManagerName = metadataManagerName
if metaExperimentName:
self.metaExperimentName = metaExperimentName
print('MetadataManager: %s' % metadataManagerName)
print('MetaExperiment: %s' % metaExperimentName)
""" Tango Devices instances """
try:
MetadataManagerClient.metadataManager = PyTango.client.Device(self.metadataManagerName)
MetadataManagerClient.metaExperiment = PyTango.client.Device(self.metaExperimentName)
except:
print "Unexpected error:", sys.exc_info()[0]
raise
''' Set proposal should be done before stting the data root '''
def setProposal(self, proposal):
try:
MetadataManagerClient.metaExperiment.proposal = proposal
self.proposal = proposal
except:
print "Unexpected error:", sys.exc_info()[0]
raise
def notifyInfo(self, message):
MetadataManagerClient.metadataManager.notifyInfo(message)
def notifyError(self, message):
MetadataManagerClient.metadataManager.notifyError(message)
def notifyDebug(self, message):
MetadataManagerClient.metadataManager.notifyDebug(message)
if __name__ == '__main__':
metadataManagerName = 'id00/metadata/mgr'
metaExperimentName = 'id00/metadata/exp'
client = MetadataManagerClient(metadataManagerName, metaExperimentName)
client.setProposal('ID000000')
client.notifyInfo("This is a info")
client.notifyError("This is a error")
client.notifyDebug("This is debug")
```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment