Ejemplo n.º 1
0
def update_olog_id( logid, text, attachments):   
    '''Update olog book  logid entry with text and attachments files
    logid: integer, the log entry id
    text: the text to update, will add this text to the old text
    attachments: add new attachment files
    An example:
    
    filename1 = '/XF11ID/analysis/2016_2/yuzhang/Results/August/af8f66/Report_uid=af8f66.pdf'
    atch=[  Attachment(open(filename1, 'rb')) ] 
    
    update_olog_id( logid=29327, text='add_test_atch', attachmenents= atch )    
    
    '''
    url='https://logbook.nsls2.bnl.gov/Olog-11-ID/Olog'
    olog_client=SimpleOlogClient(  url= url, 
                                    username= '******', password= '******'   )
    
    client = OlogClient( url='https://logbook.nsls2.bnl.gov/Olog-11-ID/Olog', 
                                    username= '******', password= '******' )
    
    old_text =  olog_client.find( id = logid )[0]['text']    
    upd = LogEntry( text= old_text + '\n'+text,   attachments=  attachments,
                      logbooks= [Logbook( name = 'Operations', owner=None, active=True)]
                  )  
    upL = client.updateLog( logid, upd )    
    print( 'The url=%s was successfully updated with %s and with the attachments'%(url, text))
Ejemplo n.º 2
0
def update_olog_id(logid, text, attachments):
    '''Update olog book  logid entry with text and attachments files
    logid: integer, the log entry id
    text: the text to update, will add this text to the old text
    attachments: add new attachment files
    An example:
    
    filename1 = '/XF11ID/analysis/2016_2/yuzhang/Results/August/af8f66/Report_uid=af8f66.pdf'
    atch=[  Attachment(open(filename1, 'rb')) ] 
    
    update_olog_id( logid=29327, text='add_test_atch', attachmenents= atch )    
    
    '''
    url = 'https://logbook.nsls2.bnl.gov/Olog-11-ID/Olog'
    olog_client = SimpleOlogClient(url=url,
                                   username='******',
                                   password='******')

    client = OlogClient(url='https://logbook.nsls2.bnl.gov/Olog-11-ID/Olog',
                        username='******',
                        password='******')

    old_text = olog_client.find(id=logid)[0]['text']
    upd = LogEntry(
        text=old_text + '\n' + text,
        attachments=attachments,
        logbooks=[Logbook(name='Operations', owner=None, active=True)])
    upL = client.updateLog(logid, upd)
    print(
        'The url=%s was successfully updated with %s and with the attachments'
        % (url, text))
Ejemplo n.º 3
0
def toOlogComment(comment):
    global client

    if (client == None):
        client = OlogClient(url, username, password)
    entry = LogEntry(text=comment, owner=owner, logbooks=[Logbook(logbook)])
    client.log(entry)
Ejemplo n.º 4
0
 def testCreateClient(self):
     '''
     Simple test to create a ologClient
     '''
     client = OlogClient(url=getDefaultTestConfig('url'))
     self.assertIsNotNone(client, 'Failed to create olog client')
     client = OlogClient(url=getDefaultTestConfig('url'))
     self.assertIsNotNone(client, 'Failed to create olog client')
     pass
Ejemplo n.º 5
0
def toOlogPicture(imagePath, comment):
    global client

    if (client == None):
        client = OlogClient(url, username, password)
    att = Attachment(open(imagePath, "rb"))
    entry = LogEntry(text=comment,
                     owner=owner,
                     logbooks=[Logbook(logbook)],
                     attachments=[att])

    client.log(entry)
Ejemplo n.º 6
0
 def setUpClass(cls):
     cls.client = client = OlogClient(url=getDefaultTestConfig('url'), username=getDefaultTestConfig('username'), password=getDefaultTestConfig('password'))
     cls.text = 'test python log entry with attachment ' + datetime.now().isoformat(' ')
     cls.testAttachment = Attachment(open('debug.log', 'rb'))
     cls.testLogbook = Logbook(name='testLogbook', owner='testOwner')
     cls.client.createLogbook(cls.testLogbook);
     cls.testTag = Tag(name='testTag') 
     cls.client.createTag(cls.testTag)               
     cls.testProperty = Property(name='testLogProperty', attributes={'id':'testSearchId', 'url':'www.bnl.gov'})
     cls.client.createProperty(cls.testProperty)
     cls.t1 = str(time.time()).split('.')[0]
     client.log(LogEntry(text=cls.text,
                        owner='testOwner',
                        logbooks=[cls.testLogbook],
                        tags=[cls.testTag],
                        attachments=[cls.testAttachment],
                        properties=[cls.testProperty]))
     cls.t2 = str(time.time()).split('.')[0]
     client.log(LogEntry(text=cls.text + ' - entry2',
                        owner='testOwner',
                        logbooks=[cls.testLogbook]))
     cls.t3 = str(time.time()).split('.')[0]
     cls.testLogEntry1 = client.find(search=cls.text)[0]
     cls.testLogEntry2 = client.find(search=cls.text + ' - entry2')[0]
     pass
Ejemplo n.º 7
0
def update_olog_uid(uid, text, attachments):
    '''Update olog book  logid entry cotaining uid string with text and attachments files
    uid: string, the uid of a scan or a specficial string (only gives one log entry)
    text: the text to update, will add this text to the old text
    attachments: add new attachment files    
    An example:
    
    filename1 = '/XF11ID/analysis/2016_2/yuzhang/Results/August/af8f66/Report_uid=af8f66.pdf'
    atch=[  Attachment(open(filename1, 'rb')) ] 
    update_olog_uid( uid='af8f66', text='Add xpcs pdf report', attachments= atch )    
    
    '''

    olog_client = SimpleOlogClient(
        url='https://logbook.nsls2.bnl.gov/Olog-11-ID/Olog',
        username='******',
        password='******')

    client = OlogClient(url='https://logbook.nsls2.bnl.gov/Olog-11-ID/Olog',
                        username='******',
                        password='******')

    logid = olog_client.find(search=uid)[0]['id']
    #print(attachments)
    update_olog_id(logid, text, attachments)
Ejemplo n.º 8
0
 def testCreateTag(self):
     '''
     Basic operations of creating, listing and deleting a Tag object
     '''
     client = OlogClient(url=getDefaultTestConfig('url'), username=getDefaultTestConfig('username'), password=getDefaultTestConfig('password'))
     testTag = Tag(name='testTag', state="Active")
     client.createTag(testTag)
     self.assertTrue(testTag in client.listTags(), 'failed to create the testTag')
     client.delete(tagName='testTag')
     self.assertTrue(testTag not in client.listTags(), 'failed to cleanup the testTag')
Ejemplo n.º 9
0
 def testCreateLogbook(self):
     '''
     Basic operations of creating, listing and deleting a Logbook object
     '''
     client = OlogClient(url=getDefaultTestConfig('url'), username=getDefaultTestConfig('username'), password=getDefaultTestConfig('password'))
     testLogbook = Logbook(name='testLogbook', owner='testOwner')
     client.createLogbook(testLogbook)
     self.assertTrue(testLogbook in client.listLogbooks(), 'failed to create the testLogbook')
     client.delete(logbookName='testLogbook')
     self.assertTrue(testLogbook not in client.listLogbooks(), 'failed to cleanup the testLogbook')
Ejemplo n.º 10
0
 def CreateProperty(self):
     '''
     Basic operations of creating, listing and deleting a property object
     TODO: the cleanup needs to be resolved
     '''
     client = OlogClient(url=getDefaultTestConfig('url'), username=getDefaultTestConfig('username'), password=getDefaultTestConfig('password'))
     testAttributes = {"attr":"test"}
     testProperty = Property(name='testProperty31', attributes=testAttributes)
     client.createProperty(testProperty)
     self.assertTrue(testProperty in client.listProperties(), 'failed to create the testProperty')
     '''Delete Property only deletes attributes in the service - will be fixed in the service'''
     client.delete(propertyName='testProperty31')
     self.assertTrue(testProperty not in client.listProperties(), 'failed to cleanup the testProperty')
Ejemplo n.º 11
0
 def testCreateLogbook(self):
     '''
     Basic operations of creating, listing and deleting a Logbook object
     '''
     client = OlogClient(url='https://localhost:8181/Olog', username='******', password='******')
     testLogbook = Logbook(name='testLogbook', owner='testOwner')
     client.createLogbook(testLogbook)
     self.assertTrue(testLogbook in client.listLogbooks(), 'failed to create the testLogbook')
     client.delete(logbookName='testLogbook')
     self.assertTrue(testLogbook not in client.listLogbooks(), 'failed to cleanup the testLogbook')
Ejemplo n.º 12
0
 def testCreateTag(self):
     '''
     Basic operations of creating, listing and deleting a Tag object
     '''
     client = OlogClient(url='https://localhost:8181/Olog', username='******', password='******')
     testTag = Tag(name='testTag', state="Active")
     client.createTag(testTag)
     self.assertTrue(testTag in client.listTags(), 'failed to create the testTag')
     client.delete(tagName='testTag')
     self.assertTrue(testTag not in client.listTags(), 'failed to cleanup the testTag')
Ejemplo n.º 13
0
def toOlog(imagePath, comment, omega_pv=None):
    global client

    if (client == None):
        client = OlogClient(url, username, password)
    att = Attachment(open(imagePath, "rb"))
    if (omega_pv == None):
        propOmega = Property(name='motorPosition',
                             attributes={
                                 'id': 'XF:AMXFMX{MC-Goni}Omega.RBV',
                                 'name': 'Omega',
                                 'value': 'offline',
                                 'unit': 'deg'
                             })
    else:
        propOmega = Property(name='motorPosition',
                             attributes={
                                 'id': 'XF:AMXFMX{MC-Goni}Omega.RBV',
                                 'name': 'Omega',
                                 'value': str(omega_pv.get()),
                                 'unit': 'deg'
                             })
    client.createProperty(propOmega)
    entry = LogEntry(text=comment,
                     owner="HHS",
                     logbooks=[Logbook("raster")],
                     properties=[propOmega],
                     attachments=[att])
    client.log(entry)
Ejemplo n.º 14
0
 def testCreateProperty(self):
     '''
     Basic operations of creating, listing and deleting a Logbook object
     '''
     client = OlogClient(url='https://localhost:8181/Olog', username='******', password='******')
     testAttributes = {"attr":"test"}
     testProperty = Property(name='testProperty32', attributes=testAttributes)
     client.createProperty(testProperty)
     self.assertTrue(testProperty in client.listProperties(), 'failed to create the testProperty')
     '''Delete Property only deletes attributes in the service - will be fixed in the service'''
     client.delete(propertyName='testProperty32')
     self.assertTrue(testProperty not in client.listProperties(), 'failed to cleanup the testProperty')
Ejemplo n.º 15
0
 def testProcess(self):
     client = OlogClient(url='https://localhost:8181/Olog', username='******', password='******')
     property = Property(name='Process',
                         attributes={'processType':'diffCalc',
                                     'processId':'1234',
                                     'processAttchments':'rawDataFile.txt'})
     # load Data
     client.log(LogEntry(text='Initial setup',
                        owner='experimenter',
                        logbooks=[Logbook(name='Experimental Logbook')],
                        properties=[property],
                        attachments=[Attachment(open('rawDataFile.txt', 'rb'))]
                        ))
     # run scan
     property = Property(name='Process',
                         attributes={'processType':'diffCalc.process',
                                     'processId':'1234',
                                     'processAttchments':'.txt'})
     client.log(LogEntry(text='Initial setup',
                        owner='experimenter',
                        logbooks=[Logbook(name='Experimental Logbook')],
                        properties=[property]
                        ))
Ejemplo n.º 16
0
 def testProcess(self):
     client = OlogClient(url=getDefaultTestConfig('url'), username=getDefaultTestConfig('username'), password=getDefaultTestConfig('password'))
     property = Property(name='Process',
                         attributes={'processType':'diffCalc',
                                     'processId':'1234',
                                     'processAttchments':'debug.log'})
     client.createProperty(property)
     # load Data
     client.log(LogEntry(text='Initial setup',
                        owner='experimenter',
                        logbooks=[self.testLogbook],
                        properties=[property],
                        attachments=[Attachment(open('debug.log', 'rb'))]
                        ))
     # run scan
     property = Property(name='Process',
                         attributes={'processType':'diffCalc.process',
                                     'processId':'1234',
                                     'processAttchments':'.log'})
     client.log(LogEntry(text='Initial setup',
                        owner='experimenter',
                        logbooks=[self.testLogbook],
                        properties=[property]
                        ))
Ejemplo n.º 17
0
 def testCreateEntryWithAttachments(self):
     client = OlogClient(url=getDefaultTestConfig('url'), username=getDefaultTestConfig('username'), password=getDefaultTestConfig('password'))
     testLogbook = Logbook(name='testLogbook', owner='testOwner')
     client.createLogbook(testLogbook);
     text = 'test python log entry with attachments ' + datetime.now().isoformat(' ')
     testImageAttachment = Attachment(open('Desert.jpg', 'rb'))
     testTextAttachment = Attachment(open('debug.log', 'rb'))
     testLog = LogEntry(text=text,
                        owner='testOwner',
                        logbooks=[testLogbook],
                        attachments=[testImageAttachment, testTextAttachment]
                        )
     client.log(testLog)
     logEntries = client.find(search=text)
     self.assertEqual(len(logEntries), 1, 'Failed to create log entry with attachment')
     attachments = client.listAttachments(logEntryId=logEntries[0].getId())
     self.assertEqual(len(attachments), 2, 'Failed to create log entry with attachment');
     for attachment in attachments:
         if attachment.getFile().name.endswith('.log'):
             print attachment.getFile().readline()
             print attachment.getFile().fileno(), open('debug.log', 'rb').fileno()      
     client.delete(logEntryId=logEntries[0].getId()) 
     self.assertEqual(len(client.find(search=text)), 0, 'Failed to cleanup log entry with attachment')      
     client.delete(logbookName=testLogbook.getName())
     self.assertTrue(testLogbook not in client.listLogbooks(), 'failed to cleanup the testLogbook')
     pass
Ejemplo n.º 18
0
 def testCreateBasicEntry(self):
     client = OlogClient(url=getDefaultTestConfig('url'), username=getDefaultTestConfig('username'), password=getDefaultTestConfig('password'))
     testLogbook = Logbook(name='testLogbook', owner='testOwner')
     client.createLogbook(testLogbook)
     text = 'test python log entry ' + datetime.now().isoformat(' ')
     testLog = LogEntry(text=text,
                        owner='testOwner',
                        logbooks=[testLogbook])
     client.log(logEntry=testLog)
     logEntries = client.find(search=testLog.getText())
     self.assertTrue(len(logEntries) == 1, 'Failed to create test log entry')
     client.delete(logEntryId=logEntries[0].getId())
     self.assertTrue(len(client.find(search=testLog.getText())) == 0, 'Failed to delete test log entry')
     client.delete(logbookName='testLogbook')
     self.assertTrue(testLogbook not in client.listLogbooks(), 'failed to cleanup the testLogbook')
     pass
Ejemplo n.º 19
0
 def tearDownClass(cls):
     client = OlogClient(url=getDefaultTestConfig('url'), username=getDefaultTestConfig('username'), password=getDefaultTestConfig('password'))
     client.delete(logbookName='testLogbook')
     pass
Ejemplo n.º 20
0
 def setUpClass(cls):
     client = OlogClient(url=getDefaultTestConfig('url'), username=getDefaultTestConfig('username'), password=getDefaultTestConfig('password'))
     cls.testLogbook = Logbook(name='testLogbook', owner='testOwner')
     client.createLogbook(cls.testLogbook)
     pass
Ejemplo n.º 21
0
 def setUpClass(cls):
     client = OlogClient(url='https://localhost:8181/Olog', username='******', password='******')
     cls.testLogbook = Logbook(name='testLogbook', owner='testOwner')
     client.createLogbook(cls.testLogbook)
     pass
Ejemplo n.º 22
0
 def tearDownClass(cls):
     client = OlogClient(url='https://localhost:8181/Olog', username='******', password='******')
     client.delete(logbookName='testLogbook')
     pass
Ejemplo n.º 23
0
 def testCreateBasicEntry(self):
     client = OlogClient(url='https://localhost:8181/Olog', username='******', password='******')
     testLogbook = Logbook(name='testLogbook', owner='testOwner')
     client.createLogbook(testLogbook)
     text = 'test python log entry ' + datetime.now().isoformat(' ')
     testLog = LogEntry(text=text,
                        owner='testOwner',
                        logbooks=[testLogbook])
     client.log(logEntry=testLog)
     logEntries = client.find(search=testLog.getText())
     self.assertTrue(len(logEntries) == 1, 'Failed to create test log entry')
     client.delete(logEntryId=logEntries[0].getId())
     self.assertTrue(len(client.find(search=testLog.getText())) == 0, 'Failed to delete test log entry')
     client.delete(logbookName='testLogbook')
     self.assertTrue(testLogbook not in client.listLogbooks(), 'failed to cleanup the testLogbook')
     pass
Ejemplo n.º 24
0
import time, os, sys

if __name__ == '__main__':

    def getDefaultConfig(arg):
        if _conf.has_option('DEFAULT', arg):
            return _conf.get('DEFAULT', arg)
        else:
            print('No python configuration for ' + arg +
                  ' found.\n Exiting demo!')
            sys.exit()

    ologurl = getDefaultConfig('url')

    client = OlogClient(url=ologurl,
                        username=getDefaultConfig('username'),
                        password=getDefaultConfig('password'))
    ''' List all logbooks that currently exist in elog '''

    def listLogbooks():
        print('Retrieving the logbooks from ' + ologurl)
        logs = client.listLogbooks()
        print('  Logbooks:')
        for s in logs:
            print('    ' + s.getName())

    ''' Create a new entry containing a specific text in the logbook CODAC '''

    def createTextEntry():
        lb = Logbook(name='CODAC')
        print('Creating a text entry in the logbook ' + lb.getName())
Ejemplo n.º 25
0
    def testCreateEntryWithProperties(self):
        client = OlogClient(url=getDefaultTestConfig('url'), username=getDefaultTestConfig('username'), password=getDefaultTestConfig('password'))
        testLogbook = Logbook(name='testLogbook', owner='testOwner')
        client.createLogbook(testLogbook);
        testProperty = Property(name='testLogProperty', attributes={'id':None, 'url':None})
#        client.createProperty(testProperty)
        text = 'test python log entry with attachment ' + datetime.now().isoformat(' ')
        property = Property(name='testLogProperty', attributes={'id':'prop1234', 'url':'www.bnl.gov'})
        testLog = LogEntry(text=text,
                           owner='testOwner',
                           logbooks=[testLogbook],
                           properties=[property]
                           )
        client.log(testLog)
        logEntries = client.find(search=text)
        self.assertEqual(len(logEntries), 1, 'Failed to create log entry with property')
        properties = logEntries[0].getProperties()
        self.assertIn(property, properties, 'TestLogEntry does not contain property ' + property.getName())
        '''Cleanup'''
        client.delete(logEntryId=logEntries[0].getId()) 
        self.assertEqual(len(client.find(search=text)), 0, 'Failed to cleanup log entry with property') 
        client.delete(logbookName=testLogbook.getName())
        self.assertTrue(testLogbook not in client.listLogbooks(), 'failed to cleanup the ' + testLogbook.getName())
        pass
Ejemplo n.º 26
0
    def testCreateEntryWithMultipleAttributes(self):
        client = OlogClient(url=getDefaultTestConfig('url'), username=getDefaultTestConfig('username'), password=getDefaultTestConfig('password'))
        text = 'test python log entry with multiple attributes ' + datetime.now().isoformat(' ')
        testImageAttachment = Attachment(open('Desert.jpg', 'rb'))
        testTextAttachment = Attachment(open('debug.log', 'rb'))
        logbooks = client.listLogbooks()
        tags = client.listTags()
        properties = client.listProperties()    
#        for property in properties:
#            for attribute in property.getAttributeNames():
#                property.Attributes[attribute] = 'testValue'+attribute
        testLog = LogEntry(text=text,
                           owner='testOwner',
                           logbooks=logbooks,
                           tags=tags,
#                           properties=properties,
                           attachments=[testImageAttachment, testTextAttachment]
                           )
        client.log(testLog)
        logEntries = client.find(search=text)
        self.assertEqual(len(logEntries), 1, 'Failed to create log entry with multiple attributes')
        logEntry = logEntries[0]
        self.assertListEqual(logbooks, logEntry.getLogbooks(), 'Failed to create log entry with all the logbooks')
        self.assertListEqual(tags, logEntry.getTags(), 'Failed to create log entry with all the tags')
#        self.assertListEqual(properties, logEntry.getProperties(), 'Failed to create log Entry with all the properties')
        client.delete(logEntryId=logEntry.getId()) 
        self.assertEqual(len(client.find(search=text)), 0, 'Failed to cleanup log entry with attachment')      
Ejemplo n.º 27
0
 def testCreateEntryWithTag(self):
     client = OlogClient(url=getDefaultTestConfig('url'), username=getDefaultTestConfig('username'), password=getDefaultTestConfig('password'))
     testLogbook = Logbook(name='testLogbook', owner='testOwner')
     client.createLogbook(testLogbook);
     testTag = Tag(name='testTag')
     client.createTag(testTag)        
     text = 'test python log entry with tag ' + datetime.now().isoformat(' ')
     testLog = LogEntry(text=text,
                        owner='testOwner',
                        logbooks=[testLogbook],
                        tags=[testTag])
     client.log(testLog)
     logEntries = client.find(search=testLog.getText())
     self.assertTrue(len(logEntries) == 1, 'Failed to create log Entry with Tag')
     self.assertTrue(testTag in logEntries[0].getTags(), 'testTag not attached to the testLogEntry1')
     '''cleanup'''
     client.delete(logEntryId=logEntries[0].getId())
     self.assertTrue(len(client.find(search=testLog.getText())) == 0, 'Failed to delete log Entry with Tag')
     client.delete(logbookName=testLogbook.getName())
     self.assertTrue(testLogbook not in client.listLogbooks(), 'failed to cleanup the testLogbook')
     client.delete(tagName=testTag.getName())
     self.assertTrue(testTag not in client.listTags(), 'failed to cleanup the testTag')
     pass