Exemple #1
0
def admin_dependencies(device):
    """ Display Dependency page """
    form_dependencies = forms_dependencies.Dependencies()

    if device != '0':
        device_unmet_dependencies = utils_general.return_dependencies(device)
    elif form_dependencies.device.data:
        device_unmet_dependencies = utils_general.return_dependencies(
            form_dependencies.device.data)
    else:
        device_unmet_dependencies = []

    unmet_dependencies = OrderedDict()
    unmet_exist = False
    met_dependencies = []
    met_exist = False
    unmet_list = {}
    install_in_progress = False

    # Read from the dependency status file created by the upgrade script
    # to indicate if the upgrade is running.
    try:
        with open(DEPENDENCY_INIT_FILE) as f:
            dep = int(f.read(1))
    except IOError:
        try:
            with open(DEPENDENCY_INIT_FILE, 'w') as f:
                f.write('0')
        finally:
            dep = 0

    if dep:
        install_in_progress = True

    list_dependencies = [DEVICE_INFO, MATH_INFO]
    for each_section in list_dependencies:
        for each_device in each_section:
            # Determine if there are any unmet dependencies
            unmet_dependencies.update(
                {each_device: utils_general.return_dependencies(each_device)})
            if utils_general.return_dependencies(each_device) != []:
                unmet_exist = True

            # Determine if there are any met dependencies
            if utils_general.return_dependencies(each_device, dep_type='met'):
                if each_device not in met_dependencies:
                    met_dependencies.append(each_device)
                    met_exist = True

            # Find all the devices that use each unmet dependency
            if unmet_dependencies[each_device]:
                for each_dep in unmet_dependencies[each_device]:
                    if each_dep not in unmet_list:
                        unmet_list[each_dep] = []
                    if each_device not in unmet_list[each_dep]:
                        unmet_list[each_dep].append(each_device)

    if request.method == 'POST':
        if not utils_general.user_has_permission('edit_controllers'):
            return redirect(
                url_for('routes_admin.admin_dependencies', device=device))

        if form_dependencies.install.data:
            install_in_progress = True
            with open(DEPENDENCY_INIT_FILE, 'w') as f:
                f.write('1')
            install_deps = threading.Thread(target=install_dependencies,
                                            args=(device_unmet_dependencies, ))
            install_deps.start()

        return redirect(
            url_for('routes_admin.admin_dependencies', device=device))

    return render_template('admin/dependencies.html',
                           measurements=DEVICE_INFO,
                           unmet_list=unmet_list,
                           device=device,
                           install_in_progress=install_in_progress,
                           unmet_dependencies=unmet_dependencies,
                           unmet_exist=unmet_exist,
                           met_dependencies=met_dependencies,
                           met_exist=met_exist,
                           form_dependencies=form_dependencies,
                           device_unmet_dependencies=device_unmet_dependencies)
Exemple #2
0
def admin_dependencies(device):
    """ Display Dependency page """
    form_dependencies = forms_dependencies.Dependencies()

    if device != '0':
        device_unmet_dependencies, _ = utils_general.return_dependencies(
            device)
    elif form_dependencies.device.data:
        device_unmet_dependencies, _ = utils_general.return_dependencies(
            form_dependencies.device.data)
    else:
        device_unmet_dependencies = []

    unmet_dependencies = OrderedDict()
    unmet_exist = False
    met_dependencies = []
    met_exist = False
    unmet_list = {}
    install_in_progress = False
    device_name = None

    # Read from the dependency status file created by the upgrade script
    # to indicate if the upgrade is running.
    try:
        with open(DEPENDENCY_INIT_FILE) as f:
            dep = int(f.read(1))
    except (IOError, ValueError):
        try:
            with open(DEPENDENCY_INIT_FILE, 'w') as f:
                f.write('0')
        finally:
            dep = 0

    if dep:
        install_in_progress = True

    dict_inputs = parse_input_information()

    list_dependencies = [
        dict_inputs, FUNCTION_ACTION_INFO, FUNCTION_INFO, LCD_INFO, MATH_INFO,
        METHOD_INFO, OUTPUT_INFO, CALIBRATION_INFO
    ]
    for each_section in list_dependencies:
        for each_device in each_section:

            if device in each_section:
                for each_device_, each_val in each_section[device].items():
                    if each_device_ in ['name', 'input_name']:
                        device_name = each_val

            # Determine if there are any unmet dependencies
            dep_unmet, dep_met = utils_general.return_dependencies(each_device)

            unmet_dependencies.update({each_device: dep_unmet})
            if dep_unmet:
                unmet_exist = True

            # Determine if there are any met dependencies
            if dep_met:
                if each_device not in met_dependencies:
                    met_dependencies.append(each_device)
                    met_exist = True

            # Find all the devices that use each unmet dependency
            if unmet_dependencies[each_device]:
                for each_dep in unmet_dependencies[each_device]:
                    if each_dep not in unmet_list:
                        unmet_list[each_dep] = []
                    if each_device not in unmet_list[each_dep]:
                        unmet_list[each_dep].append(each_device)

    if request.method == 'POST':
        if not utils_general.user_has_permission('edit_controllers'):
            return redirect(
                url_for('routes_admin.admin_dependencies', device=device))

        if form_dependencies.install.data:
            install_in_progress = True
            with open(DEPENDENCY_INIT_FILE, 'w') as f:
                f.write('1')
            install_deps = threading.Thread(target=install_dependencies,
                                            args=(device_unmet_dependencies, ))
            install_deps.start()

        return redirect(
            url_for('routes_admin.admin_dependencies', device=device))

    return render_template('admin/dependencies.html',
                           measurements=parse_input_information(),
                           unmet_list=unmet_list,
                           device=device,
                           device_name=device_name,
                           install_in_progress=install_in_progress,
                           unmet_dependencies=unmet_dependencies,
                           unmet_exist=unmet_exist,
                           met_dependencies=met_dependencies,
                           met_exist=met_exist,
                           form_dependencies=form_dependencies,
                           device_unmet_dependencies=device_unmet_dependencies)
Exemple #3
0
def admin_dependencies(device):
    """Display Dependency page"""
    form_dependencies = forms_dependencies.Dependencies()

    if device != '0':
        # Only loading a single dependency page
        device_unmet_dependencies, _, _ = utils_general.return_dependencies(
            device)
    elif form_dependencies.device.data:
        device_unmet_dependencies, _, _ = utils_general.return_dependencies(
            form_dependencies.device.data)
    else:
        device_unmet_dependencies = []

    unmet_dependencies = OrderedDict()
    unmet_exist = False
    met_dependencies = []
    met_exist = False
    unmet_list = {}
    install_in_progress = False
    device_name = None
    dependencies_message = ""

    # Read from the dependency status file created by the upgrade script
    # to indicate if the upgrade is running.
    try:
        with open(DEPENDENCY_INIT_FILE) as f:
            dep = int(f.read(1))
    except (IOError, ValueError):
        try:
            with open(DEPENDENCY_INIT_FILE, 'w') as f:
                f.write('0')
        finally:
            dep = 0

    if dep:
        install_in_progress = True

    list_dependencies = [
        parse_function_information(),
        parse_action_information(),
        parse_input_information(),
        parse_output_information(),
        parse_widget_information(), CAMERA_INFO, FUNCTION_INFO, METHOD_INFO,
        DEPENDENCIES_GENERAL
    ]
    for each_section in list_dependencies:
        for each_device in each_section:

            if device in each_section:
                # Determine if a message for the dependencies exists
                if "dependencies_message" in each_section[device]:
                    dependencies_message = each_section[device][
                        "dependencies_message"]

                # Find friendly name for device
                for each_device_, each_val in each_section[device].items():
                    if each_device_ in [
                            'name', 'input_name', 'output_name',
                            'function_name', 'widget_name'
                    ]:
                        device_name = each_val
                        break

            # Only get all dependencies when not loading a single dependency page
            if device == '0':
                # Determine if there are any unmet dependencies for every device
                dep_unmet, dep_met, _ = utils_general.return_dependencies(
                    each_device)

                unmet_dependencies.update({each_device: dep_unmet})
                if dep_unmet:
                    unmet_exist = True

                # Determine if there are any met dependencies
                if dep_met:
                    if each_device not in met_dependencies:
                        met_dependencies.append(each_device)
                        met_exist = True

                # Find all the devices that use each unmet dependency
                if unmet_dependencies[each_device]:
                    for each_dep in unmet_dependencies[each_device]:
                        # Determine if the third element of the tuple is a list, convert it to a tuple
                        if (type(each_dep) == tuple and len(each_dep) == 3
                                and type(each_dep[2]) == list):
                            each_dep = list(each_dep)
                            each_dep[2] = tuple(each_dep[2])
                            each_dep = tuple(each_dep)

                        if each_dep not in unmet_list:
                            unmet_list[each_dep] = []
                        if each_device not in unmet_list[each_dep]:
                            unmet_list[each_dep].append(each_device)

    if request.method == 'POST':
        if not utils_general.user_has_permission('edit_controllers'):
            return redirect(
                url_for('routes_admin.admin_dependencies', device=device))

        if form_dependencies.install.data:
            with open(DEPENDENCY_INIT_FILE, 'w') as f:
                f.write('1')
            install_deps = threading.Thread(target=install_dependencies,
                                            args=(device_unmet_dependencies, ))
            install_deps.start()

        return redirect(
            url_for('routes_admin.admin_dependencies', device=device))

    return render_template('admin/dependencies.html',
                           measurements=parse_input_information(),
                           unmet_list=unmet_list,
                           dependencies_message=dependencies_message,
                           device=device,
                           device_name=device_name,
                           install_in_progress=install_in_progress,
                           unmet_dependencies=unmet_dependencies,
                           unmet_exist=unmet_exist,
                           met_dependencies=met_dependencies,
                           met_exist=met_exist,
                           form_dependencies=form_dependencies,
                           device_unmet_dependencies=device_unmet_dependencies)