<commit_before>import os
import json
import sublime
import sublime_plugin

from .bootstrapper import has_compatible_working_appbuilder_cli
from .notifier import log_info, log_error
from .command_executor import show_quick_panel, run_command
from .sublime_events_listener import on_sublime_view_loaded
from .base_commands import AppBuilderWindowCommandBase
from .project import Project

class DevicesCommandBase(AppBuilderWindowCommandBase):
    @property
    def command_name(self):
        return ""

    def is_enabled(self):
        return has_compatible_working_appbuilder_cli()

    def run(self):
        self.do_run()

    def do_run(self):
        self.choose_project()

    def choose_project(self):
        self.projects = []

        project_dir = Project.get_project_dir(self.get_working_dir())
        if (bool(project_dir)):
            self.projects.append(project_dir)

        for index, value in enumerate(self.window.folders()):
            project_dir = Project.get_project_dir(value)
            if (bool(project_dir)):
                self.projects.append(project_dir)

        self.projects = list(set(self.projects))
        self.projects = list(map((lambda project: [Project.get_project_name(project), project]), self.projects))

        projectsCount = len(self.projects)
        if projectsCount == 1:
            self.on_project_chosen(0)
        elif projectsCount > 1:
            show_quick_panel(self, self.projects, self.on_project_chosen)
        else:
            log_info("There are no projects in your currently opened folders")

    def on_project_chosen(self, project_index):
        if project_index >= 0:
            self.choose_device(lambda device_index: self.execute(project_index, device_index))
        else:
            self.execute(project_index, -1)

    def choose_device(self, callback):
        self.on_device_chosen = callback
        command = ["list-devices", "--json"]
        self.devices = []
        run_command(command, self.on_device_data_reveived, self.on_devices_data_finished, True, "Retrieving devices")

    def on_device_data_reveived(self, data):
        try:
            device = json.loads(data)
            self.devices.append(device)
        except ValueError:  # includes simplejson.decoder.JSONDecodeError
            log_error(data)

    def on_devices_data_finished(self, exit_code):
        if (exit_code == 0):
            devicesCount = len(self.devices)
            if devicesCount == 0:
                log_info("There are no connected devices")
                self.on_device_chosen(-1)
            elif devicesCount == 1:
                self.on_device_chosen(0)
            elif devicesCount > 1:
                devicesList = map((lambda device: [device["name"],
                        "Platform: {platform} {version}".format(platform=device["platform"], version=device["version"]),
                        "Model: {model}".format(model=device["model"]),
                        "Vendor: {vendor}".format(vendor=device["vendor"])]),
                    self.devices)
                show_quick_panel(self, devicesList, self.on_device_chosen)
        else:
            log_error("Command failed with exit code: {code}".format(code = exit_code))
            self.on_device_chosen(-1)

    def on_data(self, data):
        log_info(data)

    def on_done(self, exit_code):
        if exit_code != 0:
            log_error("Command failed with exit code: {code}".format(code = exit_code))

        log_info("Exit code: {exit_code}".format(exit_code=exit_code))

class DeployCommand(DevicesCommandBase):
    @property
    def command_name(self):
        return "Deploy"

    def execute(self, project_index, device_index):<commit_msg>The devices list must be of type that has 'len' function<commit_after>import os
import json
import sublime
import sublime_plugin

from .bootstrapper import has_compatible_working_appbuilder_cli
from .notifier import log_info, log_error
from .command_executor import show_quick_panel, run_command
from .sublime_events_listener import on_sublime_view_loaded
from .base_commands import AppBuilderWindowCommandBase
from .project import Project

class DevicesCommandBase(AppBuilderWindowCommandBase):
    @property
    def command_name(self):
        return ""

    def is_enabled(self):
        return has_compatible_working_appbuilder_cli()

    def run(self):
        self.do_run()

    def do_run(self):
        self.choose_project()

    def choose_project(self):
        self.projects = []

        project_dir = Project.get_project_dir(self.get_working_dir())
        if (bool(project_dir)):
            self.projects.append(project_dir)

        for index, value in enumerate(self.window.folders()):
            project_dir = Project.get_project_dir(value)
            if (bool(project_dir)):
                self.projects.append(project_dir)

        self.projects = list(set(self.projects))
        self.projects = list(map((lambda project: [Project.get_project_name(project), project]), self.projects))

        projectsCount = len(self.projects)
        if projectsCount == 1:
            self.on_project_chosen(0)
        elif projectsCount > 1:
            show_quick_panel(self, self.projects, self.on_project_chosen)
        else:
            log_info("There are no projects in your currently opened folders")

    def on_project_chosen(self, project_index):
        if project_index >= 0:
            self.choose_device(lambda device_index: self.execute(project_index, device_index))
        else:
            self.execute(project_index, -1)

    def choose_device(self, callback):
        self.on_device_chosen = callback
        command = ["list-devices", "--json"]
        self.devices = []
        run_command(command, self.on_device_data_reveived, self.on_devices_data_finished, True, "Retrieving devices")

    def on_device_data_reveived(self, data):
        try:
            device = json.loads(data)
            self.devices.append(device)
        except ValueError:  # includes simplejson.decoder.JSONDecodeError
            log_error(data)

    def on_devices_data_finished(self, exit_code):
        if (exit_code == 0):
            devicesCount = len(self.devices)
            if devicesCount == 0:
                log_info("There are no connected devices")
                self.on_device_chosen(-1)
            elif devicesCount == 1:
                self.on_device_chosen(0)
            elif devicesCount > 1:
                devicesList = list(map((lambda device: [device["name"],
                        "Platform: {platform} {version}".format(platform=device["platform"], version=device["version"]),
                        "Model: {model}".format(model=device["model"]),
                        "Vendor: {vendor}".format(vendor=device["vendor"])]),
                    self.devices))
                show_quick_panel(self, devicesList, self.on_device_chosen)
        else:
            log_error("Command failed with exit code: {code}".format(code = exit_code))
            self.on_device_chosen(-1)

    def on_data(self, data):
        log_info(data)

    def on_done(self, exit_code):
        if exit_code != 0:
            log_error("Command failed with exit code: {code}".format(code = exit_code))

        log_info("Exit code: {exit_code}".format(exit_code=exit_code))

class DeployCommand(DevicesCommandBase):
    @property
    def command_name(self):
        return "Deploy"

    def execute(self, project_index, device_index):
{'fraction_non_alphanumeric': 0.09814146276240139, 'fraction_numerical': 0.003476400588313946, 'mean_word_length': 2.6901825357671436, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3806408', 'n_tokens_mistral': 2165, 'n_tokens_neox': 2080, 'n_words': 445}