def insert_node_subtree(nodeObj, nodeIdDatabase, cookie):
    print 'Inserting node: %s ' % nodeObj['name']
    responseObj = rest.insert_node(json.dumps(nodeObj), cookie)    
    nodeIdRegistered =  responseObj['id']
    queryChild = "-e select name, node_id from node where parent_node_id = %s" % nodeIdDatabase
    childNodeFile = subprocess.Popen(["mysql", '-B', '-uroot', '-Ddidata', queryChild], stdout=subprocess.PIPE).stdout
    childNodeFile.readline() #ignoring first line (column names)
    childNodeLine = childNodeFile.readline()
    while childNodeLine:
        childNodeName = childNodeLine.split('\t')[0]
        childNodeIdDatabase = childNodeLine.split('\t')[1].rstrip('\n')
        childNodeObj = {
                    "description":   "",
                    "perspectiveId": nodeObj['perspectiveId'],
                    "parentNodeId":  nodeIdRegistered,
                    "name":          childNodeName
        }
        insert_node_subtree(childNodeObj, childNodeIdDatabase, cookie)
        childNodeLine = childNodeFile.readline()
def insert_node_subtree(nodeObj, nodeIdDatabase, cookie):
    print 'Inserting node: %s ' % nodeObj['name']
    responseObj = rest.insert_node(json.dumps(nodeObj), cookie)
    nodeIdRegistered = responseObj['id']
    queryChild = "-e select name, node_id from node where parent_node_id = %s" % nodeIdDatabase
    childNodeFile = subprocess.Popen(
        ["mysql", '-B', '-uroot', '-Ddidata', queryChild],
        stdout=subprocess.PIPE).stdout
    childNodeFile.readline()  #ignoring first line (column names)
    childNodeLine = childNodeFile.readline()
    while childNodeLine:
        childNodeName = childNodeLine.split('\t')[0]
        childNodeIdDatabase = childNodeLine.split('\t')[1].rstrip('\n')
        childNodeObj = {
            "description": "",
            "perspectiveId": nodeObj['perspectiveId'],
            "parentNodeId": nodeIdRegistered,
            "name": childNodeName
        }
        insert_node_subtree(childNodeObj, childNodeIdDatabase, cookie)
        childNodeLine = childNodeFile.readline()
예제 #3
0
def handle_insert_nodes_option():
    cookie = rest.login_holmes()
    for data in nodes.DATA:
        print 'Inserting node: %s ' % data['name']
        rest.insert_node(json.dumps(data), cookie)
예제 #4
0
def handle_insert_nodes_option():
    cookie = rest.login_holmes()
    for data in nodes.DATA:
        print 'Inserting node: %s ' % data['name']
        rest.insert_node(json.dumps(data), cookie)