<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import absolute_import
from __future__ import print_function
from __future__ import division
from __future__ import unicode_literals

import os
import time
import sublime
import glob
import sublime_plugin
from shutil import rmtree

try:
    from .libs import Paths, Tools
    from .libs.Menu import Menu
    from .libs.Messages import Console
    from .libs.PlatformioCLI import PlatformioCLI
    from .libs.Preferences import Preferences
except:
    from libs import Paths
    from libs import Tools
    from libs.Menu import Menu
    from libs.Messages import Console
    from libs.PlatformioCLI import PlatformioCLI
    from libs.Preferences import Preferences


class DeviotListener(sublime_plugin.EventListener):
    """
    This is the first class to run when the plugin is excecuted
    Extends: sublime_plugin.EventListener
    """

    def __init__(self):
        """
        Checks if platformIO is installed
        """
        if(not PlatformioCLI().platformioCheck()):
            return None

        super(DeviotListener, self).__init__()

    def on_activated(self, view):
        """
        Set the current version of Deviot

        Arguments: view {ST object} -- Sublime Text Object
        """
        PlatformioCLI(view, command=False).checkInitFile()
        Tools.setStatus(view)

    def on_close(self, view):
        """
        When a sketch is closed, temp files are deleted

        Arguments: view {ST object} -- Sublime Text Object
        """
        file_path = Tools.getPathFromView(view)
        if(not file_path):
            return
        file_name = Tools.getFileNameFromPath(file_path, ext=False)
        tmp_path = Paths.getDeviotTmpPath()
        tmp_all = os.path.join(tmp_path, '*')
        tmp_all = glob.glob(tmp_all)

        for content in tmp_all:
            if file_name in content:
                tmp_path = os.path.join(tmp_path, content)
                rmtree(tmp_path, ignore_errors=False)
                Preferences().set('builded_sketch', False)


class PlatformioInstallCommand(sublime_plugin.WindowCommand):
    """
        This command send the user to a website with platformio install
        instructions
    """

    def run(self):
        sublime.run_command('open_url', {'url': 'http://goo.gl/66BHnk'})


class CheckRequirementsCommand(sublime_plugin.TextCommand):
    """
        Check the if minimum requirements has been established
        detailed information in libs/PlatformioCLI.py
    """

    def run(self, edit):
        view = self.view
        console_name = 'Deviot|Check' + str(time.time())
        console = Console(view.window(), name=console_name)
        PlatformioCLI(view, console, True).platformioCheck()


class SelectBoardCommand(sublime_plugin.WindowCommand):
    """
    This class trigger two methods to know what board(s)
    were chosen and to store it in a preference file.

    Extends: sublime_plugin.WindowCommand
    """

    def run(self, board_id):
        """
        Get the ID of the board selected and store it in a
        preference file.

        Arguments: board_id {string} -- id of the board selected
        """
        native = Preferences().get('native', False)
        remove = Preferences().boardSelected(board_id)
        if(remove):
            PlatformioCLI().removeEnvFromFile(board_id)
        if(native and not remove):
            Preferences().set('init_queue', board_id)
            PlatformioCLI().openInThread('init')
        Menu().createEnvironmentMenu()

    def is_checked(self, board_id):
        """
        Check if the node in the menu is check or not, this
        function need to return always a bolean

        Arguments: board_id {string} -- id of the board selected
        """
        check = Preferences().checkBoard(board_id)
        return check

    def is_enabled(self):
        return Preferences().get('enable_menu', False)


class MainEnvironmentCommand(sublime_plugin.WindowCommand):
    """
    Enable or disable the "Select environment" menu if none board
    is selected from the list.

    Extends: sublime_plugin.WindowCommand
    """

    def is_enabled(self):
        check = Preferences().get('enable_menu', False)
        if(check):
            check = Preferences().get('env_selected', '')
            if(len(check) == 0):
                check = False
        return check

<commit_msg>Remove deprecated function<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import absolute_import
from __future__ import print_function
from __future__ import division
from __future__ import unicode_literals

import os
import time
import sublime
import glob
import sublime_plugin
from shutil import rmtree

try:
    from .libs import Paths, Tools
    from .libs.Menu import Menu
    from .libs.Messages import Console
    from .libs.PlatformioCLI import PlatformioCLI
    from .libs.Preferences import Preferences
except:
    from libs import Paths
    from libs import Tools
    from libs.Menu import Menu
    from libs.Messages import Console
    from libs.PlatformioCLI import PlatformioCLI
    from libs.Preferences import Preferences


class DeviotListener(sublime_plugin.EventListener):
    """
    This is the first class to run when the plugin is excecuted
    Extends: sublime_plugin.EventListener
    """

    def __init__(self):
        """
        Checks if platformIO is installed
        """
        if(not PlatformioCLI().platformioCheck()):
            return None

        super(DeviotListener, self).__init__()

    def on_activated(self, view):
        """
        Set the current version of Deviot

        Arguments: view {ST object} -- Sublime Text Object
        """
        PlatformioCLI(view, command=False).checkInitFile()
        Tools.setStatus(view)

    def on_close(self, view):
        """
        When a sketch is closed, temp files are deleted

        Arguments: view {ST object} -- Sublime Text Object
        """
        file_path = Tools.getPathFromView(view)
        if(not file_path):
            return
        file_name = Tools.getFileNameFromPath(file_path, ext=False)
        tmp_path = Paths.getDeviotTmpPath()
        tmp_all = os.path.join(tmp_path, '*')
        tmp_all = glob.glob(tmp_all)

        for content in tmp_all:
            if file_name in content:
                tmp_path = os.path.join(tmp_path, content)
                rmtree(tmp_path, ignore_errors=False)
                Preferences().set('builded_sketch', False)


class PlatformioInstallCommand(sublime_plugin.WindowCommand):
    """
        This command send the user to a website with platformio install
        instructions
    """

    def run(self):
        sublime.run_command('open_url', {'url': 'http://goo.gl/66BHnk'})


class CheckRequirementsCommand(sublime_plugin.TextCommand):
    """
        Check the if minimum requirements has been established
        detailed information in libs/PlatformioCLI.py
    """

    def run(self, edit):
        view = self.view
        console_name = 'Deviot|Check' + str(time.time())
        console = Console(view.window(), name=console_name)
        PlatformioCLI(view, console, True).platformioCheck()


class SelectBoardCommand(sublime_plugin.WindowCommand):
    """
    This class trigger two methods to know what board(s)
    were chosen and to store it in a preference file.

    Extends: sublime_plugin.WindowCommand
    """

    def run(self, board_id):
        """
        Get the ID of the board selected and store it in a
        preference file.

        Arguments: board_id {string} -- id of the board selected
        """
        native = Preferences().get('native', False)
        remove = Preferences().boardSelected(board_id)
        if(remove):
            PlatformioCLI().removeEnvFromFile(board_id)
        if(native and not remove):
            Preferences().set('init_queue', board_id)
            PlatformioCLI().openInThread('init')
        Menu().createEnvironmentMenu()

    def is_checked(self, board_id):
        """
        Check if the node in the menu is check or not, this
        function need to return always a bolean

        Arguments: board_id {string} -- id of the board selected
        """
        check = Preferences().checkBoard(board_id)
        return check

    def is_enabled(self):
        return Preferences().get('enable_menu', False)


{'fraction_non_alphanumeric': 0.08738556652003329, 'fraction_numerical': 0.0008322434906669837, 'mean_word_length': 2.5918018787361228, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2045871', 'n_tokens_mistral': 2390, 'n_tokens_neox': 2297, 'n_words': 687}