def remove_all_profiles(service_url, config_repository):
    ''' '''
    client = RecognizeOpenRdfClient(server_uri=service_url,
                                    config_repository=config_repository)
    for profile_name in client.get_profiles():
        client.remove_profile(profile_name)

    client.cleanup_config()
def remove_all_profiles(service_url, config_repository):
    ''' '''
    client = RecognizeOpenRdfClient(server_uri=service_url,
                                    config_repository=config_repository)
    for profile_name in client.get_profiles():
        client.remove_profile(profile_name)

    client.cleanup_config()
def upload_profile(profile_fn, service_url, config_repository):
    ''' '''

    client = RecognizeOpenRdfClient(server_uri=service_url,
                                    config_repository=config_repository)
    available_repositories = client.get_repositories()

    profile_fns = []
    if os.path.isdir(profile_fn):
        for root, dirs, files in os.walk(profile_fn):
            for fn in files:
                if fn.endswith('.ttl'):
                    profile_fns.append('%s/%s' % (root, fn))
    else:
        profile_fns = [profile_fn]

    print('Found {} profiles, uploading to {}'.format(len(profile_fns),
                                                      service_url))
    print(profile_fns)
    for p_fns in profile_fns:
        profile_name = p_fns.split(os.sep)[-1].replace('.ttl', '')
        profile_definition = open(p_fns).read()

        print('Processing profile %s' % profile_name)
        if service_url:
            url = urllib.parse.urlparse(service_url)
            hostname = '%s://%s' % (url.scheme, url.netloc)
            profile_definition = profile_definition.replace(
                '$HOSTNAME', hostname)
            repo_name = [
                line for line in profile_definition.split('\n')
                if 'dcterms:source' in line
            ][0]
            repo_name = repo_name.replace('";', '').split('/')[-1].strip()
            if not repo_name in available_repositories:
                print('Skipping profile %s: bad repository' % profile_name)
                continue
            client.update_profile(profile_name, profile_definition)
def upload_profile(profile_fn, service_url, config_repository):
    ''' '''

    client = RecognizeOpenRdfClient(server_uri=service_url,
                                    config_repository=config_repository)
    available_repositories = client.get_repositories()

    profile_fns = []
    if os.path.isdir(profile_fn):
        for root, dirs, files in os.walk(profile_fn):
            for fn in files:
                if fn.endswith('.ttl'):
                    profile_fns.append('%s/%s' % (root, fn))
    else:
        profile_fns = [profile_fn]

    print('Found {} profiles, uploading to {}'.format(len(profile_fns),
                                                      service_url))
    print(profile_fns)
    for p_fns in profile_fns:
        profile_name = p_fns.split(os.sep)[-1].replace('.ttl', '')
        profile_definition = open(p_fns).read()

        print('Processing profile %s' % profile_name)
        if service_url:
            url = urlparse.urlparse(service_url)
            hostname = '%s://%s' % (url.scheme, url.netloc)
            profile_definition = profile_definition.replace(
                '$HOSTNAME', hostname)
            repo_name = [line for line in profile_definition.split(
                '\n') if 'dcterms:source' in line][0]
            repo_name = repo_name.replace('";', '').split('/')[-1].strip()
            if not repo_name in available_repositories:
                print('Skipping profile %s: bad repository' % profile_name)
                continue
            client.update_profile(profile_name, profile_definition)
def remove_profile(profile_fn, service_url, config_repository):
    ''' '''
    client = RecognizeOpenRdfClient(server_uri=service_url,
                                    config_repository=config_repository)
    client.remove_profile(profile_fn)
def cleanup_config(service_url, config_repository):
    ''' '''
    client = RecognizeOpenRdfClient(server_uri=service_url,
                                    config_repository=config_repository)
    client.cleanup_config()
def remove_profile(profile_name, service_url, config_repository):
    ''' '''
    client = RecognizeOpenRdfClient(server_uri=service_url,
                                    config_repository=config_repository)
    client.remove_profile(profile_name)
def cleanup_config(service_url, config_repository):
    ''' '''
    client = RecognizeOpenRdfClient(server_uri=service_url,
                                    config_repository=config_repository)
    client.cleanup_config()