Exemple #1
0
def mexsession(config):
    "Create a BQApi BQSession object based on config"
    host = config.get ( 'host.root')
    user = config.get ( 'host.user')
    passwd = config.get ( 'host.password')

    bq = BQSession()
    bq.config = config
    bq.init_local (user, passwd, bisque_root = host, create_mex = True)
    yield  bq
    bq.close()
Exemple #2
0
def test_initalize_session_From_mex(config):
    """
        Test initalizing a session from a mex
    """
    host = config.get('host.root')
    user = config.get('host.user')
    pwd = config.get('host.password')
    bqsession = BQSession().init_local(user, pwd, bisque_root=host)
    mex_url = bqsession.mex.uri
    token = bqsession.mex.resource_uniq
    bqmex = BQSession().init_mex(mex_url, token, user, bisque_root=host)
    bqmex.close()
    bqsession.close()
Exemple #3
0
def test_initalize_mex_locally(config):
    """
        Test initalizing a mex locally
    """
    host = config.get('host.root')
    user = config.get('host.user')
    pwd = config.get('host.password')
    bqsession = BQSession().init_local(user,
                                       pwd,
                                       bisque_root=host,
                                       create_mex=True)
    assert bqsession.mex.uri
    bqsession.close()
Exemple #4
0
def test_open_session(config):
    """
        Test Initalizing a BQSession locally
    """
    host = config.get('host.root')
    user = config.get('host.user')
    pwd = config.get('host.password')

    bqsession = BQSession().init_local(user,
                                       pwd,
                                       bisque_root=host,
                                       create_mex=False)
    bqsession.close()
Exemple #5
0
    def main(self, image_url, mex_url=None, bisque_token=None, bq=None):
        #  Allow for testing by passing an alreay initialized session
        if bq is None:
            bq = BQSession().init_mex(mex_url, bisque_token)
        # Fetch the image metadata
        image = bq.load(image_url)

        # Fetch embedded tags from image service
        meta = image.pixels().meta().fetch()
        meta = ET.XML(meta)
        tags = []
        # Create a new tag 'MyData' to be placed on the image
        md = BQTag(name='MyData')
        # Filter the embedded metadata and place subtags in MyData
        for t in meta.getiterator('tag'):
            if t.get('name') in wanted_tags:
                md.addTag(name=t.get('name'), value=t.get('value'))
        # Add the new tag to the image
        image.addTag(tag=md)
        bq.save(md, image.uri + "/tags")
        bq.close()
Exemple #6
0
    def main(self, mex_url=None, auth_token=None, bq=None, **kw):
        #  Allow for testing by passing an alreay initialized session
        if bq is None:
            bq = BQSession().init_mex(mex_url, auth_token)

        # check for list parameters
        params = bq.get_mex_inputs()
        if isinstance(params,
                      dict) or not isinstance(params, collections.Iterable):
            params = [params]
        # pass values directly as args
        for single_params in params:
            for param_name in single_params:
                if 'value' in single_params[param_name]:
                    single_params[param_name] = single_params[param_name].get(
                        'value')

        # TODO: measure block startup time
        self.start_block(bq, params)

        for kw in params:
            # TODO: measure single item time
            # TODO: run in parallel
            if 'mex_url' in kw:
                # set (innermost) single item mex
                sub_bq = BQSession().init_mex(kw['mex_url'], auth_token)
            else:
                sub_bq = bq
            self.process_single(sub_bq, **kw)
            if 'mex_url' in kw:
                sub_bq.close()

        # TODO: measure block teardown time
        self.end_block(bq)

        sys.exit(0)
Exemple #7
0
    # use import service to /import/transfer activating import service
    r = etree.XML(session.postblob(filepath, xml=resource)).find('./')

    if r is None or r.get('uri') is None:
        print 'Upload failed'
    else:
        print 'Uploaded ID: %s, URL: %s' % (r.get('resource_uniq'),
                                            r.get('uri'))
        f['url'] = r.get('uri')

# upload dataset
dataset = etree.Element('dataset', name=dataset_name)
for f in files:
    if 'url' not in f:
        continue
    v = etree.SubElement(dataset, 'value', type="object")
    v.text = f['url']
print etree.tostring(dataset)

url = session.service_url('data_service')
r = session.postxml(url, dataset)

if r is None or r.get('uri') is None:
    print 'Dataset failed'
else:
    print 'Dataset ID: %s, URL: %s' % (r.get('resource_uniq'), r.get('uri'))
    f['url'] = r.get('uri')

session.close()