コード例 #1
0
def parse_facet(data):
    if not isinstance(data, dict):
        om_fatal_output("parse_facet()::facet data is not a dict type, exit now")
        om_output(str(data))
        exit(-1)
    f = Facet(str(data['typeCode']), data['title'])
    f.id = data['id']
    if len(data['backgroundImages']) == 0:
        # for no backgroundimage problem just set the picture to empty
        # and the later verification will report related error with alarm
        om_err_output("parse_facet() fail to parse facet %s due to no "
                      "backgroudImages found"%data['title'])
        f.pic = ""
    else:
        f.pic = data['backgroundImages'][0]['url']

    return f
コード例 #2
0
def parse_view(data):
    if not isinstance(data, dict):
        om_fatal_output("navigation data is not a dict type, exit now")
        exit(-1)
        
    v = View(data['title'], data['navigationId'])
    v.layout = data['layoutId']
    if 'tiles' not in data:
        om_fatal_outut("parse_navigation()::no tiles in view data")
        exit(-1)
    for t in data['tiles']:
        tile = parse_tile(t)
        if tile is None:
            om_err_output("parse_view() fail to parse view %s"%data['title'])
            return None
        v.tiles.append(parse_tile(t))
    return v
コード例 #3
0
def parse_view(data):
    if not isinstance(data, dict):
        om_fatal_output("navigation data is not a dict type, exit now")
        exit(-1)

    v = View(data['title'], data['navigationId'])
    v.layout = data['layoutId']
    if 'tiles' not in data:
        om_fatal_outut("parse_navigation()::no tiles in view data")
        exit(-1)
    for t in data['tiles']:
        tile = parse_tile(t)
        if tile is None:
            om_err_output("parse_view() fail to parse view %s" % data['title'])
            return None
        v.tiles.append(parse_tile(t))
    return v
コード例 #4
0
def parse_facet(data):
    if not isinstance(data, dict):
        om_fatal_output(
            "parse_facet()::facet data is not a dict type, exit now")
        om_output(str(data))
        exit(-1)
    f = Facet(str(data['typeCode']), data['title'])
    f.id = data['id']
    if len(data['backgroundImages']) == 0:
        # for no backgroundimage problem just set the picture to empty
        # and the later verification will report related error with alarm
        om_err_output("parse_facet() fail to parse facet %s due to no "
                      "backgroudImages found" % data['title'])
        f.pic = ""
    else:
        f.pic = data['backgroundImages'][0]['url']

    return f
コード例 #5
0
def parse_tile(data):
    if not isinstance(data, dict):
        om_fatal_output("parse_tile()::tile data is not a dict type, exit now")
        exit(-1)
        
    t = Tile(data['index'])
    t.pos = [int(data['x']), int(data['y'])]
    t.size = [int(data['height']), int(data['width'])]

    if 'facets' not in data:
        om_fatal_output("parse_tile()::no facets in tile data")
        exit(-1)

    for f in data['facets']:
        facet = parse_facet(f)
        if facet is None:
            return None
        t.facets.append(facet)
    return t
コード例 #6
0
def parse_tile(data):
    if not isinstance(data, dict):
        om_fatal_output("parse_tile()::tile data is not a dict type, exit now")
        exit(-1)

    t = Tile(data['index'])
    t.pos = [int(data['x']), int(data['y'])]
    t.size = [int(data['height']), int(data['width'])]

    if 'facets' not in data:
        om_fatal_output("parse_tile()::no facets in tile data")
        exit(-1)

    for f in data['facets']:
        facet = parse_facet(f)
        if facet is None:
            return None
        t.facets.append(facet)
    return t
コード例 #7
0
def handle_argv():
    global VOD_FRONTPAGE_URL, VENDER
    if len(sys.argv) == 2:
        if sys.argv[1] == '-d':
            settings.debug_mode = True
        else:
            settings.VENDER = sys.argv[1]
            if settings.VENDER.upper() not in settings.FRONTPAGE.keys():
                om_fataal_ouptput("not support vender %s"%settings.VENDER)
                exit(0)
            settings.VOD_FRONTPAGE_URL = \
                            settings.FRONTPAGE[settings.VENDER.upper()]
    elif len(sys.argv) == 3:
        if sys.argv[1] == "-d" :
            settings.debug_mode = True
            settings.VENDER = sys.argv[2]
            if settings.VENDER.upper() not in settings.FRONTPAGE.keys():
                #err("not support vender %s"%settings.VENDER)
                om_fatal_output("not support vender %s"%settings.VENDER)
                exit(0)
            settings.VOD_FRONTPAGE_URL = \
                            settings.FRONTPAGE[settings.VENDER.upper()]
        elif sys.argv[2] == '-d':
            settings.debug_mode = True
            settings.VENDER = sys.argv[1]
            if settings.VENDER.upper() not in settings.FRONTPAGE.keys():
                #err("not support vender %s"%settings.VENDER)
                om_fatal_output("not support vender %s"%settings.VENDER)
                exit(0)
            settings.VOD_FRONTPAGE_URL = \
                            settings.FRONTPAGE[settings.VENDER.upper()]
        else:
            #err("invalid parameter")
            om_fatal_output("invalid parameter")
            exit(0)
    else:
        #err("invalid parameter")
        om_fatal_output("invalid parameter")
        exit(0)
コード例 #8
0
def handle_argv():
    global VOD_FRONTPAGE_URL, VENDER
    if len(sys.argv) == 2:
        if sys.argv[1] == '-d':
            settings.debug_mode = True
        else:
            settings.VENDER = sys.argv[1]
            if settings.VENDER.upper() not in settings.FRONTPAGE.keys():
                om_fataal_ouptput("not support vender %s" % settings.VENDER)
                exit(0)
            settings.VOD_FRONTPAGE_URL = \
                            settings.FRONTPAGE[settings.VENDER.upper()]
    elif len(sys.argv) == 3:
        if sys.argv[1] == "-d":
            settings.debug_mode = True
            settings.VENDER = sys.argv[2]
            if settings.VENDER.upper() not in settings.FRONTPAGE.keys():
                #err("not support vender %s"%settings.VENDER)
                om_fatal_output("not support vender %s" % settings.VENDER)
                exit(0)
            settings.VOD_FRONTPAGE_URL = \
                            settings.FRONTPAGE[settings.VENDER.upper()]
        elif sys.argv[2] == '-d':
            settings.debug_mode = True
            settings.VENDER = sys.argv[1]
            if settings.VENDER.upper() not in settings.FRONTPAGE.keys():
                #err("not support vender %s"%settings.VENDER)
                om_fatal_output("not support vender %s" % settings.VENDER)
                exit(0)
            settings.VOD_FRONTPAGE_URL = \
                            settings.FRONTPAGE[settings.VENDER.upper()]
        else:
            #err("invalid parameter")
            om_fatal_output("invalid parameter")
            exit(0)
    else:
        #err("invalid parameter")
        om_fatal_output("invalid parameter")
        exit(0)
コード例 #9
0
def data_initialize():
    om_output("start to initialize frontpage data")
    retry_times_left = 3
    while retry_times_left > 0:
        frontpage_data = get_frontpage_data()
        if frontpage_data is not None and len(frontpage_data) > 0:
            break
        retry_times_left -= 1
    if retry_times_left <= 0:
        alarm(
            ALARM_LEVEL.CRITICAL, "NETWORK_ISSUE", "cannot get frontpage "
            "data after several reties, url(%s) is not accessable" %
            settings.VOD_FRONTPAGE_URL)
        exit(-1)

    try:
        frontj = json.loads(frontpage_data)
    except:
        om_fatal_output("frontpage data can not be jsonlized, exit now")
        exit(-1)

    if 'apiMapping' not in frontj:
        om_fatal_output(
            "no apiMapping information in frontpage data, exit now")
        exit(-1)

    parse_api_mapping(frontj['apiMapping'])

    if 'masterViews' not in frontj:
        om_fatal_output(
            "no apiMapping information in masterViews data, exit now")
        exit(-1)

    for v in frontj['masterViews']:
        view = parse_view(v)
        if view is None:
            return False
        settings.master_views.append(view)
    return True
コード例 #10
0
def data_initialize():
    om_output("start to initialize frontpage data")
    retry_times_left = 3
    while retry_times_left > 0:
        frontpage_data = get_frontpage_data()
        if frontpage_data is not None and len(frontpage_data) > 0:
            break
        retry_times_left -= 1
    if retry_times_left <= 0:
        alarm(ALARM_LEVEL.CRITICAL, "NETWORK_ISSUE", "cannot get frontpage "
              "data after several reties, url(%s) is not accessable"
              %settings.VOD_FRONTPAGE_URL)
        exit(-1)

    try:
        frontj = json.loads(frontpage_data)
    except:
        om_fatal_output("frontpage data can not be jsonlized, exit now")
        exit(-1)

    if 'apiMapping' not in frontj:
        om_fatal_output("no apiMapping information in frontpage data, exit now")
        exit(-1)
        
    parse_api_mapping(frontj['apiMapping'])
    
    if 'masterViews' not in frontj:
        om_fatal_output("no apiMapping information in masterViews data, exit now")
        exit(-1)

    for v in frontj['masterViews']:
        view = parse_view(v)
        if view is None:
            return False
        settings.master_views.append(view)
    return True