示例#1
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)
示例#2
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)
示例#3
0
    def on_close(self, view):
        """
        When a sketch is closed, temp files are deleted

        Arguments: view {ST object} -- Sublime Text Object
        """
        # Serial Monitor
        monitor_module = Serial
        if Messages.isMonitorView(view):
            name = view.name()
            serial_port = name.split('-')[1].strip()
            if serial_port in monitor_module.serials_in_use:
                cur_serial_monitor = monitor_module.serial_monitor_dict.get(
                    serial_port, None)
                if cur_serial_monitor:
                    cur_serial_monitor.stop()
                monitor_module.serials_in_use.remove(serial_port)

        # Remove cache
        keep_cache = Preferences().get('keep_cache', True)
        if(keep_cache):
            return

        file_path = Tools.getPathFromView(view)
        if(not file_path):
            return
        file_name = Tools.getFileNameFromPath(file_path, ext=False)
        tmp_path = Paths.getTempPath()
        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)

        # Empty enviroment menu
        Menu().createEnvironmentMenu(empty=True)
示例#4
0
    def on_close(self, view):
        """
        When a sketch is closed, temp files are deleted

        Arguments: view {ST object} -- Sublime Text Object
        """
        # Serial Monitor
        monitor_module = Serial
        if Messages.isMonitorView(view):
            name = view.name()
            serial_port = name.split('-')[1].strip()
            if serial_port in monitor_module.serials_in_use:
                cur_serial_monitor = monitor_module.serial_monitor_dict.get(
                    serial_port, None)
                if cur_serial_monitor:
                    cur_serial_monitor.stop()
                monitor_module.serials_in_use.remove(serial_port)

        # Remove cache
        keep_cache = Preferences().get('keep_cache', True)
        if (keep_cache):
            return

        file_path = Tools.getPathFromView(view)
        if (not file_path):
            return
        file_name = Tools.getFileNameFromPath(file_path, ext=False)
        tmp_path = Paths.getTempPath()
        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)

        # Empty enviroment menu
        Menu().createEnvironmentMenu(empty=True)
示例#5
0
    def __init__(self, view=False, console=False, install=False, command=True):
        '''
        Initialize the command and preferences classes, to check
        if the current work file is an IoT type it received the view
        parameter (ST parameter). This parameter is necessary only in
        the options like build or upload.

        Keyword Arguments:
        view {st object} -- stores many info related with ST (default: False)
        '''
        self.Preferences = Preferences()
        self.Menu = Menu()

        # user console
        if(console):
            current_time = time.strftime('%H:%M:%S')
            self.message_queue = MessageQueue(console)
            self.message_queue.startPrint()

        # For installing purposes
        if(install):
            self.Commands = CommandsPy(console=console)
            return

        self.view = view
        self.execute = True
        self.is_native = False
        self.is_iot = False

        if(view):
            # avoid to do anything with a monitor view
            view_name = view.name()
            sketch_size = view.size()
            file_path = Tools.getPathFromView(view)

            if(not file_path and 'monitor' in view_name.lower()):
                try:
                    current_time = time.strftime('%H:%M:%S')
                    self.message_queue.put('invalid_file_{0}', current_time)
                except:
                    pass
                self.execute = False
                return

            # unsaved file
            if(command and not file_path and sketch_size > 0):
                saved_file = self.saveCodeInFile(view)
                view = saved_file[1]
                file_path = Tools.getPathFromView(view)

            if(command and not sketch_size):
                self.message_queue.put('not_empty_sketch_{0}', current_time)

            # current file / view
            current_path = Paths.getCurrentFilePath(view)
            if(not current_path):
                return
            self.is_iot = Tools.isIOTFile(view)
            current_dir = Paths.getCWD(current_path)
            parent_dir = Paths.getParentCWD(current_path)
            file_name = Tools.getFileNameFromPath(file_path)
            temp_name = Tools.getFileNameFromPath(current_path, ext=False)

            if(not self.is_iot):
                self.execute = False

            # check IoT type file
            if(console and not self.is_iot and not self.execute):
                current_time = time.strftime('%H:%M:%S')
                msg = 'not_iot_{0}{1}'
                if(not file_name):
                    msg = 'not_empty_sketch_{0}'
                self.message_queue.put(msg, current_time, file_name)
                self.execute = False
                return

            if(not command and not self.is_iot):
                return

            # Check native project
            for file in os.listdir(parent_dir):
                if(file.endswith('platformio.ini')):
                    self.dir = parent_dir
                    self.src = False
                    self.is_native = True
                    break

            # set native paths
            if(not self.is_native):
                build_dir = self.Preferences.get('build_dir', False)
                if(not build_dir):
                    build_dir = Paths.getTempPath(temp_name)
                self.src = current_dir
                self.dir = build_dir

            # unsaved changes
            if (command and view.is_dirty()):
                view.run_command('save')

            if(console):
                self.message_queue.put(
                    '[ Deviot {0} ] {1}\\n', version, file_name)
                time.sleep(0.02)

            # Initilized commands
            self.Commands = CommandsPy(console=console, cwd=self.dir)
示例#6
0
 def run(self, edit):
     temp = Paths.getTempPath()
     url = Paths.getOpenFolderPath(temp)
     sublime.run_command('open_url', {'url': url})
示例#7
0
 def run(self, edit):
     temp = Paths.getTempPath()
     url = Paths.getOpenFolderPath(temp)
     sublime.run_command('open_url', {'url': url})
示例#8
0
    def __init__(self, view=False, console=False, install=False, command=True):
        '''
        Initialize the command and preferences classes, to check
        if the current work file is an IoT type it received the view
        parameter (ST parameter). This parameter is necessary only in
        the options like build or upload.

        Keyword Arguments:
        view {st object} -- stores many info related with ST (default: False)
        '''
        self.Preferences = Preferences()
        self.Menu = Menu()

        # user console
        if (console):
            current_time = time.strftime('%H:%M:%S')
            self.message_queue = MessageQueue(console)
            self.message_queue.startPrint()

        # For installing purposes
        if (install):
            self.Commands = CommandsPy(console=console)
            return

        self.view = view
        self.execute = True
        self.is_native = False
        self.is_iot = False

        if (view):
            # avoid to do anything with a monitor view
            view_name = view.name()
            sketch_size = view.size()
            file_path = Tools.getPathFromView(view)

            if (not file_path and 'monitor' in view_name.lower()):
                try:
                    current_time = time.strftime('%H:%M:%S')
                    self.message_queue.put('invalid_file_{0}', current_time)
                except:
                    pass
                self.execute = False
                return

            # unsaved file
            if (command and not file_path and sketch_size > 0):
                saved_file = self.saveCodeInFile(view)
                view = saved_file[1]
                file_path = Tools.getPathFromView(view)

            if (command and not sketch_size):
                self.message_queue.put('not_empty_sketch_{0}', current_time)

            # current file / view
            current_path = Paths.getCurrentFilePath(view)
            if (not current_path):
                return
            self.is_iot = Tools.isIOTFile(view)
            current_dir = Paths.getCWD(current_path)
            parent_dir = Paths.getParentCWD(current_path)
            file_name = Tools.getFileNameFromPath(file_path)
            temp_name = Tools.getFileNameFromPath(current_path, ext=False)

            if (not self.is_iot):
                self.execute = False

            # check IoT type file
            if (console and not self.is_iot and not self.execute):
                current_time = time.strftime('%H:%M:%S')
                msg = 'not_iot_{0}{1}'
                if (not file_name):
                    msg = 'not_empty_sketch_{0}'
                self.message_queue.put(msg, current_time, file_name)
                self.execute = False
                return

            if (not command and not self.is_iot):
                return

            # Check native project
            for file in os.listdir(parent_dir):
                if (file.endswith('platformio.ini')):
                    self.dir = parent_dir
                    self.src = False
                    self.is_native = True
                    break

            # set native paths
            if (not self.is_native):
                build_dir = Paths.getBuildPath(temp_name)
                if (not build_dir):
                    build_dir = Paths.getTempPath(temp_name)
                self.src = current_dir
                self.dir = build_dir

            # unsaved changes
            if (command and view.is_dirty()):
                view.run_command('save')

            if (console):
                self.message_queue.put('[ Deviot {0} ] {1}\\n', version,
                                       file_name)
                time.sleep(0.02)

            # Initilized commands
            self.Commands = CommandsPy(console=console, cwd=self.dir)