コード例 #1
0
def process_commands():
    """
    Processes commmands from a command list
    ---
    tags: [commands]
    parameters:
      - name: filename
        in: formData
        description: filename of the commands text file to parse
        required: true
        type: string
    responses:
      200:
        description: Processing OK
    """
    fi = request.args.get('filename')
    file = request.files.get('file_data')
    fd = None
    if (not file is None):
        fd = file.read()
    queue = Queue()
    if (not fi == None or not fd == None):
        get_valid_commands(queue, fi, fd)
    else:
        return 'Please attach commands'
    processes = [
        Process(target=process_command_output, args=(queue, ))
        for num in range(2)
    ]
    for process in processes:
        process.start()
    # removed the join so that the processes are non blocking and the user does not have to wait for every process to finish
    return 'Successfully processed commands.'
コード例 #2
0
def process_commands():
    """
    Processes commmands from a command list
    ---
    tags: [commands]
    parameters:
      - name: filename
        in: formData
        description: filename of the commands text file to parse
                     which exists on the server
        required: true
        type: string
    responses:
      200:
        description: Processing OK
    """
    fi = request.args.get('filename')

    queue = Queue()
    get_valid_commands(queue, fi)
    processes = [
        Process(target=process_command_output, args=(queue, ))
        for num in range(2)
    ]
    for process in processes:
        process.start()
    for process in processes:
        process.join()
    return 'Successfully processed commands.'
コード例 #3
0
def process_commands():
    """
    Processes commmands from a command list
    ---
    tags: [commands]S
    parameters:
      - name: filename
        in: formData
        description: filename of the commands text file to parse
        required: true
        type: string
    responses:
      200:
        description: Processing OK
    """

    fi = request.args.get('file')
    nxt = request.form['check']

    if nxt == "yes":
        return redirect(url_for('make_db'))
    elif nxt == "no":
        return redirect(url_for('drop_db'))
    else:
        queue = Queue()
        get_valid_commands(queue, fi)
        processes = [Process(target=process_command_output, args=(queue,))
                     for num in range(2)]
        for process in processes:
            process.start()
        for process in processes:
            process.join()

        return 'Successfully processed commands.'
コード例 #4
0
def process_commands():
    """
    Processes commmands from a command list
    ---
    tags: [commands]
    parameters:
      - name: filename
        in: formData
        description: filename of the commands text file to parse
        required: true
        type: string
    responses:
      200:
        description: Processing OK
    """
    file_data = request.args.get('file_data')
    fi = request.args.get('filename')
    data = ''
    logger.info('The filename posted in the request is {}'.format(file_data))
    if file_data:
        logger.info(
            'File_data posted in request paylod ,it is {}'.format(file_data))
        data = json.loads(file_data)
        if 'COMMAND_LIST' not in data or 'VALID_COMMANDS' not in data:
            response = Response({'Parameters did not match expected format'},
                                content_type='text/plain')
            response.status_code = 400
            return response
        data = json.loads(file_data)
        logger.info('list of  commands are {}'.format(data['COMMAND_LIST']))
        logger.info('list of valid commands are {}'.format(
            data['VALID_COMMANDS']))
    else:
        if fi is None or not os.path.exists(fi):
            response = Response('Missing filename parameter OR File not found',
                                content_type='text/plain')
            response.status_code = 400
            return response
    queue = Queue()
    logger.info('file data value is {}'.format(file_data))
    get_valid_commands(queue, fi, data)
    q_size = queue.qsize()
    processes = [
        Process(target=process_command_output, args=(queue, ))
        for num in range(q_size)
    ]
    for process in processes:
        process.start()
    for process in processes:
        process.join()
    return 'Successfully processed commands.'
コード例 #5
0
def process_commands():
    """
    Processes commmands from a command list
    ---
    tags: [commands]
    parameters:
      - name: filename
        in: formData
        description: filename of the commands text file to parse
        required: true
        type: string
    responses:
      200:
        description: Processing OK
    """
    temp_expns = request.get_json(force=True)
    filename = temp_expns['filename']
    file_data = temp_expns['file_data']

    queue = Queue()
    status = get_valid_commands(queue, filename, file_data)

    if status is 200:
        jres = Response(status=200)
    else:
        jres = Response(status=400)
    return jres
コード例 #6
0
def process_commands(filename):
    try:
        queue = Queue()
        Parser.get_valid_commands(queue, filename)
        processes = [
            Process(target=Parser.process_command_output,
                    args=(
                        queue,
                        session,
                    )) for num in range(2)
        ]
        for process in processes:
            process.start()
        for process in processes:
            process.join()
        print("Process Completed")
    except Exception as detail:
        print('Exception raised' + detail)
コード例 #7
0
def process_commands():
    """
    Processes commmands from a command list
    ---
    tags: [commands]
    parameters:
      - name: filename
        in: formData
        description: filename of the commands text file to parse
        required: true
        type: string
    responses:
      200:
        description: Processing OK
    """
    fi = request.args.get('filename')
    print(fi)
    file_data = request.args.get('file_data')
    print(file_data)
    if file_data is not None:
        fi = "commands_data.txt"
        with open(fi, 'w') as f:
            file_data = file_data.split("\\n")
            print(file_data)
            for data in file_data:
                f.write(data + "\n")
    if fi is None:
        return "Processing Error"
    queue = Queue()
    get_valid_commands(queue, fi)
    processes = [
        Process(target=process_command_output, args=(
            queue,
            session,
        )) for num in range(3)
    ]
    for process in processes:
        process.start()
    #for process in processes:
    #    process.join()
    if file_data is not None:
        os.remove("commands_data.txt")
        pass
    return 'Successfully processed commands.'
コード例 #8
0
def process_commands():
    """
    Processes commmands from a command list
    ---
    tags: [commands]
    parameters:
      - name: filename
        in: formData
        description: filename of the commands text file to parse
                     which exists on the server
        required: true
        type: string
    responses:
      200:
        description: Processing OK
    """
    fi = request.args.get('filename')
    file_data = request.args.get('file_data')
    queue = Queue()
    if file_data:
        get_valid_commands(queue, file_data=file_data)
    else:
        #Check if filename exists on the server else return 400
        if not os.path.isfile(fi):
            return "Command file '{0}'  do not exists on server, Please provide correct file name".format(
                fi), 400
        get_valid_commands(queue, fi=fi)

    processes = [
        Process(target=process_command_output, args=(queue, ))
        for num in range(queue.qsize())
    ]
    for process in processes:
        process.start()
    for process in processes:
        process.join()
    return 'Successfully processed commands.'
コード例 #9
0
def process_commands():
    """
    Processes commmands from a command list
    ---
    tags: [commands]
    parameters:
      - name: filename
        in: formData
        description: filename of the commands text file to parse
        required: true
        type: string
    responses:
      200:
        description: Processing OK
    """
    fi = request.args.get('filename')

    queue = Queue()
    # If the argument contains 'file_data' then the commands data is coming from POST body
    if 'file_data' in request.args:
        get_valid_commands_using_data(queue,
                                      data=request.get_data(as_text=False))
    # If the 'commands.txt' file is passed then parse the file
    else:
        get_valid_commands(queue, fi)

    processes = [
        Process(target=process_command_output, args=(queue, ))
        for num in range(2)
    ]

    for process in processes:
        process.start()
    for process in processes:
        process.join()
    return 'Successfully processed commands.'
コード例 #10
0
def process_commands():
    """
    Processes commmands from a command list
    ---
    tags: [commands]
    parameters:
      - name: filename
        in: formData
        description: filename of the commands text file to parse
        required: true
        type: string
    responses:
      200:
        description: Processing OK
    """
    file_data = request.data.decode("utf-8")
    if not file_data:
        fileName = request.args.get('filename')
        logging.info(
            'Post request for Commands called. Fole_Data not present. File name from input parameters is:'
            + str(fileName))
        if fileName == None:
            logging.info('File name not provided in imput parameters')
            return 'fileName not provided', 400

    queue = Queue()
    if file_data:
        countElements = get_valid_commands_file_data(queue, file_data)
    else:
        countElements = get_valid_commands(queue, fileName)

    if (countElements > 0):
        processes = [
            Process(target=process_command_output, args=(queue, ))
            for num in range(countElements)
        ]
        for process in processes:
            process.start()
        for process in processes:
            process.join()
    return 'Successfully processed commands.', 200