# Path: libraries/file.py
# class File(object):
# 
#     def __init__(self, file_name):
#         self.file_name = file_name
# 
#     def write(self, text):
#         """Write File
# 
#         Writes the content of text in the file set in self.file_name
# 
#         Arguments:
#             text {str} -- text to write
# 
#         Returns:
#             bool -- true if was writed succesuflly
#         """
#         encoding = 'utf-8'
#         with codecs.open(self.file_name, 'w', encoding) as file:
#             file.write(text)
#             return True
# 
#     def read(self):
#         """Read File
# 
#         returns the content of the file set in self.file_name
# 
#         Returns:
#             str -- string from file
#         """
#         encoding = 'utf-8'
#         text = ''
# 
#         try:
#             with codecs.open(self.file_name, 'r', encoding) as file:
#                 text = file.read()
#         except(IOError, UnicodeError):
#             pass
#         return text
# 
#     def read_json(self):
#         """read JSON
#         serialize the content of the file and transform it in
#         a json format type
# 
#         Returns:
#             JSON -- serialized json data
#         """
# 
#         file = self.read()
# 
#         if(file):
#             return json.loads(file)
# 
#         return []
# 
#     def save_json(self, text):
#         """Save JSON
# 
#         Stores JSON data in a file, before do it deserialize
# 
#         Arguments:
#             text {str} -- json data to stored
#         """
#         text = json.dumps(text, sort_keys=True, indent=4)
#         self.write(text)
# 
# Path: libraries/I18n.py
# class I18n(object):
#     def __init__(self):
#         self.sys_lang = None
#         self.lang_list = {}
#         self.lang_params = {}
#         self.ids_lang = []
#         self.id_name_dict = {}
#         self.translations = {}
#         self.lang_list = {}
# 
#         self.get_system_lang()
#         self.set_lang()
# 
#     def translate(self, text, *params):
#         """Trnaslate string
# 
#         Translate the text string in the selected language (in the UI
#         of the plugin) and return it
# 
#         Arguments:
#             text {str} -- text to translate
#             *params {[type]} -- [description]
# 
#         Returns:
#             str -- text translated
#         """
#         translated = self.translations.get(text, text)
# 
#         for seq, param in enumerate(params):
#             seq_text = '{%d}' % seq
#             translated = translated.replace(seq_text, str(param))
# 
#         return translated
# 
#     def set_lang(self):
#         """Set Language
# 
#         Sets the language that will be used in the plugin. If there is none
#         option in the preferences file, the system language will be used
# 
#         Arguments:
#             selection {str} -- ISO 639*1 language string
#         """
#         selection = get_setting('lang_id', self.sys_lang)
# 
#         self.get_lang_files()
# 
#         lang = selection if(self.sys_lang in self.id_name_dict) else 'en'
#         file_path = self.id_name_dict[lang]
#         lang_file = TranslatedLines(file_path)
# 
#         self.translations = lang_file.translte_text()
#         save_setting('lang_id', lang)
# 
#     def get_lang_ids(self):
#         """Language ids lists
# 
#         List of the language ids (en, es, fr, etc)
# 
#         Returns:
#             list -- list with ids
#         """
#         return self.ids_lang
# 
#     def get_lang_name(self, lang_id):
#         """Full Language Name
# 
#         Given the ISO 639*1 language name, it will return the name of the
#         language firs in english and the second in the language itself
# 
#         Arguments:
#             lang_id {str} -- ISO 639*1 language name
# 
#         Returns:
#             list -- names of the language
#         """
#         self.get_lang_list()
# 
#         return self.lang_list.get(lang_id, ['Unknown', 'Unknown'])
# 
#     def get_lang_list(self):
#         """Language List
# 
#         Get a list with all languages, the main file is located in
#         deviot/presets/language.list
#         """
#         file_path = deviot.lang_list_path()
#         file = File(file_path)
# 
#         self.lang_list = file.read_json()
# 
#     def get_lang_files(self):
#         """Available Languages
# 
#         Finds all the languages availables in deviot, the language (translated)
#         files are located in Deviot/languages/nn.lang.
# 
#         NOTE: the language file MUST be in the ISO 639*1 format (two letters)
#         and must have the extension .lang
#         """
#         lang_path = deviot.lang_path()
#         lang_paths = glob(lang_path + '/*.lang')
#         lang_file_names = [path.basename(file_path)
#                            for file_path in lang_paths]  # es.lang
#         ids_lang = [path.splitext(name)[0] for name in lang_file_names]  # es
#         self.id_name_dict.update(dict(zip(ids_lang, lang_paths))
#                                  )  # {"es": 'path/es.lang'}
#         ids_lang.sort()  # order list
#         self.ids_lang = ids_lang
# 
#     def get_system_lang(self):
#         """System Language
# 
#         Get the language of the system (O.S)
#         """
#         from locale import getdefaultlocale
# 
#         sys_language = getdefaultlocale()[0]
#         if not sys_language:
#             sys_language = 'en'
#         else:
#             sys_language = sys_language.lower()
# 
#         self.sys_lang = sys_language[:2]


import os
from ..api import deviot
from .file import File
from ..platformio.pio_bridge import PioBridge
from .I18n import I18n
        from json import dumps
#!/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




class MenuFiles(PioBridge):
    def __init__(self):
        super(MenuFiles, self).__init__()

# Path: libraries/file.py
# class File(object):
# 
#     def __init__(self, file_name):
#         self.file_name = file_name
# 
#     def write(self, text):
#         """Write File
# 
#         Writes the content of text in the file set in self.file_name
# 
#         Arguments:
#             text {str} -- text to write
# 
#         Returns:
#             bool -- true if was writed succesuflly
#         """
#         encoding = 'utf-8'
#         with codecs.open(self.file_name, 'w', encoding) as file:
#             file.write(text)
#             return True
# 
#     def read(self):
#         """Read File
# 
#         returns the content of the file set in self.file_name
# 
#         Returns:
#             str -- string from file
#         """
#         encoding = 'utf-8'
#         text = ''
# 
#         try:
#             with codecs.open(self.file_name, 'r', encoding) as file:
#                 text = file.read()
#         except(IOError, UnicodeError):
#             pass
#         return text
# 
#     def read_json(self):
#         """read JSON
#         serialize the content of the file and transform it in
#         a json format type
# 
#         Returns:
#             JSON -- serialized json data
#         """
# 
#         file = self.read()
# 
#         if(file):
#             return json.loads(file)
# 
#         return []
# 
#     def save_json(self, text):
#         """Save JSON
# 
#         Stores JSON data in a file, before do it deserialize
# 
#         Arguments:
#             text {str} -- json data to stored
#         """
#         text = json.dumps(text, sort_keys=True, indent=4)
#         self.write(text)
# 
# Path: libraries/I18n.py
# class I18n(object):
#     def __init__(self):
#         self.sys_lang = None
#         self.lang_list = {}
#         self.lang_params = {}
#         self.ids_lang = []
#         self.id_name_dict = {}
#         self.translations = {}
#         self.lang_list = {}
# 
#         self.get_system_lang()
#         self.set_lang()
# 
#     def translate(self, text, *params):
#         """Trnaslate string
# 
#         Translate the text string in the selected language (in the UI
#         of the plugin) and return it
# 
#         Arguments:
#             text {str} -- text to translate
#             *params {[type]} -- [description]
# 
#         Returns:
#             str -- text translated
#         """
#         translated = self.translations.get(text, text)
# 
#         for seq, param in enumerate(params):
#             seq_text = '{%d}' % seq
#             translated = translated.replace(seq_text, str(param))
# 
#         return translated
# 
#     def set_lang(self):
#         """Set Language
# 
#         Sets the language that will be used in the plugin. If there is none
#         option in the preferences file, the system language will be used
# 
#         Arguments:
#             selection {str} -- ISO 639*1 language string
#         """
#         selection = get_setting('lang_id', self.sys_lang)
# 
#         self.get_lang_files()
# 
#         lang = selection if(self.sys_lang in self.id_name_dict) else 'en'
#         file_path = self.id_name_dict[lang]
#         lang_file = TranslatedLines(file_path)
# 
#         self.translations = lang_file.translte_text()
#         save_setting('lang_id', lang)
# 
#     def get_lang_ids(self):
#         """Language ids lists
# 
#         List of the language ids (en, es, fr, etc)
# 
#         Returns:
#             list -- list with ids
#         """
#         return self.ids_lang
# 
#     def get_lang_name(self, lang_id):
#         """Full Language Name
# 
#         Given the ISO 639*1 language name, it will return the name of the
#         language firs in english and the second in the language itself
# 
#         Arguments:
#             lang_id {str} -- ISO 639*1 language name
# 
#         Returns:
#             list -- names of the language
#         """
#         self.get_lang_list()
# 
#         return self.lang_list.get(lang_id, ['Unknown', 'Unknown'])
# 
#     def get_lang_list(self):
#         """Language List
# 
#         Get a list with all languages, the main file is located in
#         deviot/presets/language.list
#         """
#         file_path = deviot.lang_list_path()
#         file = File(file_path)
# 
#         self.lang_list = file.read_json()
# 
#     def get_lang_files(self):
#         """Available Languages
# 
#         Finds all the languages availables in deviot, the language (translated)
#         files are located in Deviot/languages/nn.lang.
# 
#         NOTE: the language file MUST be in the ISO 639*1 format (two letters)
#         and must have the extension .lang
#         """
#         lang_path = deviot.lang_path()
#         lang_paths = glob(lang_path + '/*.lang')
#         lang_file_names = [path.basename(file_path)
#                            for file_path in lang_paths]  # es.lang
#         ids_lang = [path.splitext(name)[0] for name in lang_file_names]  # es
#         self.id_name_dict.update(dict(zip(ids_lang, lang_paths))
#                                  )  # {"es": 'path/es.lang'}
#         ids_lang.sort()  # order list
#         self.ids_lang = ids_lang
# 
#     def get_system_lang(self):
#         """System Language
# 
#         Get the language of the system (O.S)
#         """
#         from locale import getdefaultlocale
# 
#         sys_language = getdefaultlocale()[0]
#         if not sys_language:
#             sys_language = 'en'
#         else:
#             sys_language = sys_language.lower()
# 
#         self.sys_lang = sys_language[:2]


# Path: libraries/menu_files.py
import os
from ..api import deviot
from .file import File
from ..platformio.pio_bridge import PioBridge
from .I18n import I18n
        from json import dumps

#!/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




class MenuFiles(PioBridge):
    def __init__(self):
        super(MenuFiles, self).__init__()

        self.translate = I18n().translate