Exemplo n.º 1
0
    def test_get_scheduler_and_mhclient_none(self):
        conf = context.get_conf()

        conf.set('ingest', 'active', 'False')
        self.assertEqual(context.get_mhclient(), None)
        self.assertEqual(context.get_scheduler(), None)

        context.delete('mhclient')
        context.delete('scheduler')
        conf.set('ingest', 'active', 'True')
        self.assertEqual(type(context.get_mhclient()), galicaster.utils.mhhttpclient.MHHTTPClient)
        self.assertEqual(type(context.get_scheduler()), galicaster.scheduler.scheduler.Scheduler)
Exemplo n.º 2
0
def get_series():
    repo = context.get_repository()
    mhclient = context.get_mhclient()

    try:
        series_json = mhclient.getseries()
        repo.save_attach('series.json', series_json)
    except:
        try:
            series_json = repo.get_attach('series.json').read()
        except:
            series_json = '{"totalCount":"0","catalogs":[]}'

    series_json = json.loads(series_json)
    # convert JSON in ARRAY
    out = {}

    for series in series_json['catalogs']:
        k = series['http://purl.org/dc/terms/']['identifier'][0]['value']
        group = {}
        for parameter in series['http://purl.org/dc/terms/'].iterkeys():
            try:
                group[parameter] = series['http://purl.org/dc/terms/'][
                    parameter][0]['value']
            except:
                group[parameter] = None
        out[k] = group

    return out
Exemplo n.º 3
0
def get_series():
    repo = context.get_repository() 
    mhclient = context.get_mhclient()
    
    try:
        series_json = mhclient.getseries()
        repo.save_attach('series.json', series_json)
    except:
        try:
            series_json = repo.get_attach('series.json').read()
        except:
            series_json = '{"totalCount":"0","catalogs":[]}'  

    series_json = json.loads(series_json)
    # convert JSON in ARRAY
    out = {}


    for series in series_json['catalogs']:
        k = series['http://purl.org/dc/terms/']['identifier'][0]['value']
        group = {}
        for parameter in series['http://purl.org/dc/terms/'].iterkeys():
            try:
                group[parameter] = series['http://purl.org/dc/terms/'][parameter][0]['value']
            except:
                group[parameter] = None
        out[k] = group
        
    return out
Exemplo n.º 4
0
def get_series():
    repo = context.get_repository()
    mhclient = context.get_mhclient()

    # Import the 'series' section as a dictionary
    series_conf = context.get_conf().get_section('series')

    # Init 'queries' dictionary
    queries = {'startPage': 0, 'count': RESULTS_PER_PAGE}

    # Filter out keys that do not refer to a certain series property
    # Also, substitute any placeholder(s) used to filter the series
    # TODO Currently the only placeholder is {user}
    for key in series_conf.keys():
        if key not in DISALLOWED_QUERIES:
            try:
                queries[key] = series_conf[key].format(**MAPPINGS)
            except KeyError:
                # If the placeholder does not exist, log the issue but ignore it
                # TODO Log the exception
                pass

    try:
        series_list = []
        check_default = True
        while True:
            series_json = json.loads(mhclient.getseries(**queries))
            for catalog in series_json['catalogs']:
                try:
                    series_list.append(parse_json_series(catalog))
                except KeyError:
                    # Ignore ill-formated series
                    pass
            if len(series_list) >= int(series_json['totalCount']):
                # Check the default series is present, otherwise query for it
                if 'default' in series_conf and check_default and series_conf[
                        'default'] not in dict(series_list):
                    check_default = False
                    queries = {"seriesId": series_conf['default']}
                else:
                    break
            else:
                queries['startPage'] += 1

        repo.save_attach('series.json', json.dumps(series_list))

    except (ValueError, IOError, RuntimeError, AttributeError) as e:
        #TODO Log the exception
        try:
            series_list = json.load(repo.get_attach('series.json'))
        except (ValueError, IOError) as sub_e:
            #TODO Log the exception
            series_list = []

    return series_list
Exemplo n.º 5
0
def get_series():
    repo = context.get_repository() 
    mhclient = context.get_mhclient()

    # Import the 'series' section as a dictionary
    series_conf = context.get_conf().get_section('series')

    # Init 'queries' dictionary
    queries = {'startPage': 0, 'count': RESULTS_PER_PAGE}

    # Filter out keys that do not refer to a certain series property
    # Also, substitute any placeholder(s) used to filter the series
    # TODO Currently the only placeholder is {user}
    for key in series_conf.keys():
        if key not in DISALLOWED_QUERIES:
            try:
                queries[key] = series_conf[key].format(**MAPPINGS)
            except KeyError:
                # If the placeholder does not exist, log the issue but ignore it
                # TODO Log the exception
                pass
            
    try:
        series_list = []
        check_default = True
        while True:
            series_json = json.loads(mhclient.getseries(**queries))
            for catalog in series_json['catalogs']:
                try:
                    series_list.append(parse_json_series(catalog))
                except KeyError:
                    # Ignore ill-formated series
                    pass
            if len(series_list) >= int(series_json['totalCount']):
                # Check the default series is present, otherwise query for it
                if 'default' in series_conf and check_default and series_conf['default'] not in dict(series_list):
                    check_default = False
                    queries = { "seriesId": series_conf['default'] }
                else:
                    break
            else:
                queries['startPage'] += 1

        repo.save_attach('series.json', json.dumps(series_list))

    except (ValueError, IOError, RuntimeError, AttributeError) as e:
        #TODO Log the exception
        try:
            series_list = json.load(repo.get_attach('series.json'))
        except (ValueError, IOError) as sub_e:
            #TODO Log the exception
            series_list = []

    return series_list
Exemplo n.º 6
0
def push_pic(sender=None):
    conf = context.get_conf()
    mhclient = context.get_mhclient()

    endpoint = "/dashboard/rest/agents/{hostname}/snapshot.png".format(hostname=conf.hostname)
    postfield = [ ("snapshot", get_screenshot() ) ]
    
    try:
        aux = mhclient._MHHTTPClient__call('POST', endpoint, {}, {}, postfield, False, None, False)
    except IOError as e:
        # This endpoint return 204, not 200.
        aux = None
Exemplo n.º 7
0
    def test_get_mhclient_with_config(self):
        # Context init in other test
        if context.has('mhclient'):
            context.delete('mhclient') 

        host = "http://servertest.www.es"
        conf = context.get_conf()
        conf.set('ingest', 'active', 'True')
        original_host = conf.get('ingest', 'host')
        conf.set('ingest', 'host', host)
        client = context.get_mhclient()
        self.assertNotEqual(original_host, client.server)
        self.assertEqual(host, client.server)

        context.delete('mhclient') # Context init in other test
        hostname = 'foobar'
        conf.hostname = hostname
        client = context.get_mhclient()
        self.assertEqual(hostname, client.hostname)

        context.delete('mhclient') # Context init in other test
        conf.set('basic', 'admin', 'False')
        conf.remove_option('ingest', 'hostname')
        conf.hostname = conf.get_hostname()
        client = context.get_mhclient()
        self.assertEqual('GC-' + socket.gethostname(), client.hostname)

        context.delete('mhclient') # Context init in other test
        conf.set('basic', 'admin', 'True')
        conf.remove_option('ingest', 'hostname')
        conf.hostname = conf.get_hostname()
        client = context.get_mhclient()
        self.assertEqual('GCMobile-' + socket.gethostname(), client.hostname)

        context.delete('conf') # To other test
        context.delete('mhclient') # To other test
Exemplo n.º 8
0
def get_series():
    repo = context.get_repository()
    mhclient = context.get_mhclient()

    try:
        series_json = mhclient.getseries()
        repo.save_attach("series.json", series_json)
    except:
        try:
            series_json = repo.get_attach("series.json").read()
        except:
            series_json = '{"totalCount":"0","catalogs":[]}'

    series_json = json.loads(series_json)
    # convert JSON in ARRAY
    out = {}

    for series in series_json["catalogs"]:
        k = series["http://purl.org/dc/terms/"]["identifier"][0]["value"]
        v = series["http://purl.org/dc/terms/"]["title"][0]["value"]
        out[k] = v

    return out
Exemplo n.º 9
0
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

import time

from galicaster.core import context
from galicaster.mediapackage import mediapackage

logger = context.get_logger()
conf = context.get_conf()
mhclient = context.get_mhclient()
repo = context.get_repository()

check_published = conf.get_boolean('retryingest', 'check_published') or True
check_after = conf.get_int('retryingest', 'check_after') or 300
check_nightly = conf.get_boolean('retryingest', 'nightly') or False
last_checked = time.time()

logger.debug('check_published set to {}'.format(check_published))
logger.debug('check_after set to {}'.format(str(check_after)))
logger.debug('check_nightly set to {}'.format(check_nightly))


def init():        
    try:
        dispatcher = context.get_dispatcher()
Exemplo n.º 10
0
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

import time

from galicaster.core import context
from galicaster.mediapackage import mediapackage

logger = context.get_logger()
conf = context.get_conf()
mhclient = context.get_mhclient()
repo = context.get_repository()

check_published = conf.get_boolean('retryingest', 'check_published') or True
check_after = conf.get_int('retryingest', 'check_after') or 300
check_nightly = conf.get_boolean('retryingest', 'nightly') or False
last_checked = time.time()

logger.debug('check_published set to {}'.format(check_published))
logger.debug('check_after set to {}'.format(str(check_after)))
logger.debug('check_nightly set to {}'.format(check_nightly))


def init():
    try:
        dispatcher = context.get_dispatcher()