Beispiel #1
0
def createSyntaxFile():
    """
    Generate the syntax file based in the installed libraries
    """
    try:
        from . import Paths
        from .JSONFile import JSONFile
    except:
        from libs import Paths
        from libs.JSONFile import JSONFile

    keywords = getKeywords()

    LITERAL1s = []
    KEYWORD1s = []
    KEYWORD2s = []
    KEYWORD3s = []

    # set keywords
    for k in keywords:
        for w in k.get_keywords():
            if 'LITERAL1' in w.get_type():
                LITERAL1s.append(w.get_id())
            if 'KEYWORD1' in w.get_type():
                KEYWORD1s.append(w.get_id())
            if 'KEYWORD2' in w.get_type():
                KEYWORD2s.append(w.get_id())
            if 'KEYWORD3' in w.get_type():
                KEYWORD3s.append(w.get_id())

    # formating
    LITERAL1s = set(LITERAL1s)
    LITERAL1s = '|'.join(LITERAL1s)
    KEYWORD1s = set(KEYWORD1s)
    KEYWORD1s = '|'.join(KEYWORD1s)
    KEYWORD2s = set(KEYWORD2s)
    KEYWORD2s = '|'.join(KEYWORD2s)
    KEYWORD3s = set(KEYWORD3s)
    KEYWORD3s = '|'.join(KEYWORD3s)

    # get sintax preset
    sintax_path = Paths.getSyntaxPath()
    sintax_file = JSONFile(sintax_path)
    sintax = sintax_file.readFile()

    # replace words in sintax file
    sintax = sintax.replace('${LITERAL1}', LITERAL1s)
    sintax = sintax.replace('${KEYWORD1}', KEYWORD1s)
    sintax = sintax.replace('${KEYWORD2}', KEYWORD2s)
    sintax = sintax.replace('${KEYWORD3}', KEYWORD3s)

    # Save File
    file_path = Paths.getTmLanguage()
    language_file = JSONFile(file_path)
    language_file.writeFile(sintax)
Beispiel #2
0
def createCompletions():
    """
    Generate the completions file
    """
    try:
        from . import Paths
        from .JSONFile import JSONFile
    except:
        from libs import Paths
        from libs.JSONFile import JSONFile

    keywords = getKeywords()
    keyword_ids = []
    user_path = Paths.getDeviotUserPath()
    completion_path = os.path.join(user_path, 'Deviot.sublime-completions')

    cpp_keywords = ['define', 'error', 'include', 'elif', 'endif']
    cpp_keywords += ['ifdef', 'ifndef', 'undef', 'line', 'pragma']

    for k in keywords:
        for w in k.get_keywords():
            keyword_ids += [w.get_id() for w in k.get_keywords()]

    keyword_ids = set(keyword_ids)
    keyword_ids = [word for word in keyword_ids]

    completions_dict = {'scope': 'source.iot'}
    completions_dict['completions'] = keyword_ids

    file = JSONFile(completion_path)
    file.setData(completions_dict)
Beispiel #3
0
    def saveCodeInFile(self, view):
        """
        If the sketch in the current view has been not saved, it generate
        a random name and stores in a temp folder.

        Arguments: view {ST Object} -- Object with multiples options of ST
        """
        ext = '.ino'

        tmp_path = Paths.getTempPath()
        file_name = str(time.time()).split('.')[0]
        file_path = os.path.join(tmp_path, file_name)
        file_path = os.path.join(file_path, 'src')
        os.makedirs(file_path)

        full_path = file_name + ext
        full_path = os.path.join(file_path, full_path)

        region = sublime.Region(0, view.size())
        text = view.substr(region)
        file = JSONFile(full_path)
        file.writeFile(text)

        view.set_scratch(True)
        window = view.window()
        window.run_command('close')
        view = window.open_file(full_path)

        return (True, view)
Beispiel #4
0
    def listIds(self):
        language_list_path = Paths.getLanguageList()
        self.lang_params = JSONFile(language_list_path).getData()
        language_path = Paths.getLanguagePath()

        lang_file_paths = glob.glob(language_path + '/*.lang')
        lang_file_names = [os.path.basename(p) for p in lang_file_paths]
        self.ids_lang += [os.path.splitext(nam)[0] for nam in lang_file_names]
        self.id_path_dict.update(dict(zip(self.ids_lang, lang_file_paths)))
        self.ids_lang.sort(key=lambda _id: self.lang_params.get(_id)[1])
Beispiel #5
0
    def getSublimeMenu(self, user_path=False):
        """
        Get the data of the different files that make up the main menu

        Keyword Arguments:
        user_path {boolean} -- True: get file from Packages/Deviot/Preset
                            --False: get file from Packages/User/Deviot/Preset
                              (Defaul:False)
        """
        menu_path = Paths.getSublimeMenuPath(user_path)
        menu_file = JSONFile(menu_path)
        menu_data = menu_file.getData()
        return menu_data
Beispiel #6
0
    def getTemplateMenu(self, file_name, user_path=False):
        """
        Get the template menu file to be modified by the different methods

        Arguments
        file_name {string} -name of the file including the extension
        user_path {boolean} -- True: get file from Packages/Deviot/Preset
                            --False: get file from Packages/User/Deviot/Preset
                              (Defaul:False)
        """
        file_path = Paths.getTemplateMenuPath(file_name, user_path)
        preset_file = JSONFile(file_path)
        preset_data = preset_file.getData()
        return preset_data
Beispiel #7
0
    def saveTemplateMenu(self, data, file_name, user_path=False):
        """
        Save the menu template in json format

        Arguments:
        data {json} -- st json object with the data of the menu
        file_name {string} -- name of  the file including the extension
        user_path {boolean} -- True: save file in Packages/Deviot/Preset
                            --False: save file in Packages/User/Deviot/Preset
                              (Defaul:False)
        """
        file_path = Paths.getTemplateMenuPath(file_name, user_path)
        preset_file = JSONFile(file_path)
        preset_file.setData(data)
        preset_file.saveData()
Beispiel #8
0
    def saveLibraryData(self, data, file_name):
        """
        Stores the data of the libraries in a json file

        Arguments:
            data {json}
                json data with the libraries
            file_name {string}
                name of the json file
        """
        libraries_path = Paths.getLibraryPath()
        library_path = os.path.join(libraries_path, file_name)
        libraries = JSONFile(library_path)
        libraries.setData(data)
        libraries.saveData()
Beispiel #9
0
    def getLibrary(self, file_name):
        """
        Get a specific json file and return the data

        Arguments:
            file_name {string}
                Json file name where is stored the library data

        Returns:
            [dict] -- Dictionary with the library data
        """
        plugin_path = Paths.getLibraryPath()
        library_path = os.path.join(plugin_path, file_name)
        libraries = JSONFile(library_path).getData()

        return libraries
Beispiel #10
0
    def saveSublimeMenu(self, data, sub_folder=False, user_path=False):
        """
        Save the data in different files to make up the main menu

        Arguments:
        data {json} -- json st data to create the menu

        Keyword Arguments:
        sub_folder {string/bool} -- name of the sub folder to save the file
                                 -- (default: False)
        user_path {boolean} -- True: Save file in Packages/Deviot/Preset
                            -- False: Save file in Packages/User/Deviot/Preset
                               (Defaul:False)
        """
        menu_file_path = Paths.getSublimeMenuPath(sub_folder, user_path)
        file_menu = JSONFile(menu_file_path)
        file_menu.setData(data)
        file_menu.saveData()
Beispiel #11
0
    def createLibraryImportMenu(self):
        """
        Creates the import library menu
        this method search in the user and core libraries
        """
        library_paths = Paths.getLibraryFolders()
        added_lib = []
        children = []

        # get preset
        menu_import_lib = self.getTemplateMenu(file_name='import_library.json')

        for library_dir in library_paths:
            # add separator
            if 'arduinoteensy' not in library_dir:
                temp_info = {}
                temp_info['caption'] = '-'
                children.append(temp_info)
            sub_path = glob.glob(library_dir)

            # search in sub path
            for library in sub_path:

                # Add core libraries
                if '__cores__' in library:
                    core_subs = os.path.join(library, '*')
                    core_subs = glob.glob(core_subs)
                    for core_sub in core_subs:
                        core_sub_subs = os.path.join(core_sub, '*')
                        core_sub_subs = glob.glob(core_sub_subs)
                        for core_lib in core_sub_subs:
                            caption = os.path.basename(core_lib)
                            if caption not in added_lib:
                                temp_info = {}
                                temp_info['caption'] = caption
                                temp_info['command'] = 'add_library'
                                temp_info['args'] = {'library_path': library}
                                children.append(temp_info)
                                added_lib.append(caption)

                # the rest of the libraries
                caption = os.path.basename(library)

                # get library name from json file
                pio_libs = os.path.join('platformio', 'lib')
                if pio_libs in library:

                    # get library json details
                    library_json = os.path.join(library, 'library.json')
                    if (not os.path.exists(library_json)):
                        library_json = os.path.join(library,
                                                    'library.properties')

                    # when there´s json content, read it
                    json = JSONFile(library_json)
                    json = json.getData()
                    if (json != {}):
                        caption = json['name']

                if caption not in added_lib and '__cores__' not in caption:
                    temp_info = {}
                    temp_info['caption'] = caption
                    temp_info['command'] = 'add_library'
                    temp_info['args'] = {'library_path': library}
                    children.append(temp_info)
                    added_lib.append(caption)

        # save file
        menu_import_lib[0]['children'][0]['children'] = children
        self.saveSublimeMenu(data=menu_import_lib,
                             sub_folder='import_library',
                             user_path=True)