Example #1
0
 def visit(path, key, value):
     if key is SarBase.OLINK:
         for l in value:
             try:
                 update(data[l], {k: data[k][SarBase.TYPE]})
             except:
                 Log.warning("LinkNotFound = %s ( %s )" %
                             (l, data[k][SarBase.TYPE]))
             #
         #
     #
     return True
Example #2
0
def main(params):
    # start
    Log.info('Start')
    # xml to python and filter
    #SarFilter(params.target, params.filter)(SarParser(params.path)())
    print(dump(SarFilter(params.target, params.filter)(SarParser(params.path)())))
    # finish
    Log.info('Finish')
    return 0
# -------------------------------------------------------------------------------------------------
# end
# -------------------------------------------------------------------------------------------------
Example #3
0
 def insert(data, new):
     for d in new:
         if d in data:
             if data[d][SarBase.TYPE] != new[d][SarBase.TYPE]:
                 Log.warning("ObjectConflit = %s (%s != %s)" %
                             (d, data[d][TYPE], new[d][TYPE]))
             #
         else:
             data[d] = new[d]
         #
     #
     return data
Example #4
0
 def __call__(self):
     result = {}
     # find all arxml
     for f in self.__findFiles():
         # prase and merge
         try:
             result = self.__mergeData(result, self.__parseFile(f))
         except Exception as e:
             Log.warning("file=%s exception=%s" % (f, str(e)))
     # link data
     result = self.__linkData(result)
     return result
Example #5
0
def main(params):
    from yaml import dump
    # start
    Log.info('Start')
    # xml to python
    data = SarParser(params.path)()
    # print
    print(dump(data))
    # finish
    Log.info('Finish')
    return 0


# -------------------------------------------------------------------------------------------------
# end
# -------------------------------------------------------------------------------------------------
Example #6
0
def main(params):
    import networkx as nx
    import matplotlib.pyplot as plt
    G = nx.Graph()
    G.add_edge("NA12878", "NA12892", weight=2)
    G.add_edge("NA12878", "NA12891", weight=7)
    G.add_edge("NA12892", "NA12891", weight=4)

    G.add_node("NA12878", relationship="child")
    G.add_node("NA12892", relationship="mother")
    G.add_node("NA12891", relationship="father")

    nx.draw_shell(G)
    plt.show()

    # start
    Log.info('Start Trace')
    # load data
    data = load(params.path, 'cache.pickle')

    PATTERN = '.*DispDrasyLng.*'

    from re import match

    data = dict(filter(lambda d: match(PATTERN, d[0]), data.items()))

    for k, v in data.items():
        print('\n {:<100} : {:<100}'.format(k, v['$']))
        for kk, vv in v.get('<-', {}).items():
            print('\t {:<100} : {:<100}'.format(kk, vv))
        for kk, vv in v.get('->', {}).items():
            print('\t {:<100} : {:<100}'.format(kk, vv))

    # finish
    Log.info('Finish Trace')
    return 0


# -------------------------------------------------------------------------------------------------
# end
# -------------------------------------------------------------------------------------------------
Example #7
0
def main(params):
    # log
    Log.info('Start')
    # xml to python
    data = SarFiles(params.path)()
    # seek for equal UUIDs
    result = {}
    for f, d in data.items():
        for a in find('UUID', d):
            if a in result:
                Log.error("UUID=%s F1=%s F2=%s" % (a, f, result[a]))
            else:
                result[a] = f
            #
        #
    #
    Log.info('Finish')
    return 0


# -------------------------------------------------------------------------------------------------
# end
# -------------------------------------------------------------------------------------------------
Example #8
0
def main(args=None):
	# -----------------------------------------------------------------------------------
	# parsers
	# -----------------------------------------------------------------------------------
	# head
	# -----------------------------------------------------------------------------
	head = ArgumentParser(prog='toolsar')
	sub  = head.add_subparsers(title='sub-command')
	
	# -----------------------------------------------------------------------------
	# check uuid
	# -----------------------------------------------------------------------------
	parser = sub.add_parser('check-uuids')
	# arguments
	parser.add_argument('path', type=str, help='search path')
	# function
	parser.set_defaults(func=check_uuids)
	
	# -----------------------------------------------------------------------------
	# parse sar
	# -----------------------------------------------------------------------------
	parser = sub.add_parser('parse')
	# arguments
	parser.add_argument('path', type=str, help='search path')
	# function
	parser.set_defaults(func=sar_parse)
	
	# -----------------------------------------------------------------------------
	# filter sar
	# -----------------------------------------------------------------------------
	parser = sub.add_parser('filter')
	# arguments
	parser.add_argument(
		'path', type=str, help='search path')
	parser.add_argument(
		'--target', type=str, help='target key', nargs='+', default='.*')
	parser.add_argument(
		'--filter', type=str, help='filter key', nargs='+', default='')
	# function
	parser.set_defaults(func=sar_filter)
	
	# -----------------------------------------------------------------------------
	# trace sar
	# -----------------------------------------------------------------------------
	parser = sub.add_parser('trace')
	# arguments
	parser.add_argument('path',
	 	type   =str, 
		help   ='search path')
	parser.add_argument('--target', '-t', 
		type   =str, 
		help   ='target key', 
		default='.*')
	# function
	parser.set_defaults(func=sar_trace)

	# -----------------------------------------------------------------------------
	# view sar
	# -----------------------------------------------------------------------------
	parser = sub.add_parser('view')
	# arguments
	parser.add_argument(
		'path', type=str, help='search path')
	parser.add_argument(
		'--target', type=str, help='target key', nargs='+', default='.*')
	parser.add_argument(
		'--filter', type=str, help='filter key', nargs='+', default='')
	# function
	parser.set_defaults(func=sar_view)

	# -----------------------------------------------------------------------------------
	# execute
	# -----------------------------------------------------------------------------------
	# logger configuration
	config_logger(
		format = '%(log_color)s%(asctime)s %(levelname)-8s %(reset)s| %(message)s',
		stream = stdout,
		level  = INFO,
		datefmt='%H:%M:%S')
	# call method
	opt = head.parse_args(args=args)
	try:
		opt.func(opt)
	except AttributeError:
		head.print_help()
	except:
		Log.exception('main')