def initSketchProject(self, chosen): ''' command to initialize the board(s) selected by the user. This function can only be use if the workig file is an IoT type (checked by isIOTFile) ''' # check if it was already initialized ini_path = Paths.getFullIniPath(self.dir) if(os.path.isfile(ini_path)): with open(ini_path) as file: if(chosen in file.read()): return init_board = '--board=%s ' % chosen if(not init_board): current_time = time.strftime('%H:%M:%S') msg = 'none_board_sel_{0}' self.message_queue.put(msg, current_time) self.Commands.error_running = True return command = ['init', '%s' % (init_board)] self.Commands.runCommand(command) if(not self.Commands.error_running): if(self.is_native): self.Preferences.set('init_queue', '') if(not self.is_native and self.src): self.overrideSrc(self.dir, self.src)
def removeEnvFromFile(self, env): """ Removes the environment select from the platformio.ini file Arguments: env {string} -- environment to remove """ ini_path = self.Preferences.get('ini_path', False) if(not ini_path): return found = False write = False buffer = "" # exclude environment selected ini_path = Paths.getFullIniPath(ini_path) if(not os.path.isfile(ini_path)): return with open(ini_path) as file: for line in file: if(env in line and not found): found = True write = True if(not found): buffer += line if(found and line == '\n'): found = False # save new platformio.ini if(write): with open(ini_path, 'w') as file: file.write(buffer)
def initSketchProject(self, chosen): ''' command to initialize the board(s) selected by the user. This function can only be use if the workig file is an IoT type (checked by isIOTFile) ''' # check if it was already initialized ini_path = Paths.getFullIniPath(self.dir) if (os.path.isfile(ini_path)): with open(ini_path) as file: if (chosen in file.read()): return init_board = '--board=%s ' % chosen if (not init_board): current_time = time.strftime('%H:%M:%S') msg = 'none_board_sel_{0}' self.message_queue.put(msg, current_time) self.Commands.error_running = True return command = ['init', '%s' % (init_board)] self.Commands.runCommand(command) if (not self.Commands.error_running): if (self.is_native): self.Preferences.set('init_queue', '') if (not self.is_native and self.src): self.overrideSrc(self.dir, self.src)
def removeEnvFromFile(self, env): """ Removes the environment select from the platformio.ini file Arguments: env {string} -- environment to remove """ ini_path = self.Preferences.get('ini_path', False) if (not ini_path): return found = False write = False buffer = "" # exclude environment selected ini_path = Paths.getFullIniPath(ini_path) if (not os.path.isfile(ini_path)): return with open(ini_path) as file: for line in file: if (env in line and not found): found = True write = True if (not found): buffer += line if (found and line == '\n'): found = False # save new platformio.ini if (write): with open(ini_path, 'w') as file: file.write(buffer)
def overrideSrc(self, ini_path, src_dir): """ Append in the platformio.ini file, the src_dir option to override the source folder where the sketch is stored Arguments: ini_path {string} -- path of the platformio.ini file src_dir {string} -- path where source folder the is located """ header = '[platformio]' ini_path = Paths.getFullIniPath(self.dir) with open(ini_path) as file: if header not in file.read(): with open(ini_path, 'a+') as new_file: new_file.write("\n%s\n" % header) new_file.write("src_dir=%s\n" % src_dir)
def checkInitFile(self): """ Check each platformio.ini file and loads the environments already initialized. """ protected = self.Preferences.get('protected', False) if(not protected): return # Empy menu if it's not a IoT file if(not self.is_iot): if(Tools.getPythonVersion() > 2): self.Menu.createEnvironmentMenu(empty=True) return ini_path = Paths.getFullIniPath(self.dir) # show non native data if(not self.is_native): self.Preferences.set('native', False) self.Preferences.set('ini_path', self.dir) self.Menu.createEnvironmentMenu() return else: self.Preferences.set('native', True) self.Preferences.set('ini_path', self.dir) # get data from platformio.ini file ini_list = [] with open(ini_path, 'r') as file: pattern = compile(r'\[(\w+)\W(\w+)\]') for line in file: if pattern.findall(line): if('#' not in line): line = match(r"\[\w+:(\w+)\]", line).group(1) ini_list.append(line) # save preferences, update menu data type = 'board_id' if not self.is_native else 'found_ini' self.Preferences.set(type, ini_list) self.Menu.createEnvironmentMenu()
def checkInitFile(self): """ Check each platformio.ini file and loads the environments already initialized. """ protected = self.Preferences.get('protected', False) if (not protected): return # Empy menu if it's not a IoT file if (not self.is_iot): return ini_path = Paths.getFullIniPath(self.dir) # show non native data if (not self.is_native): self.Preferences.set('native', False) self.Preferences.set('ini_path', self.dir) self.Menu.createEnvironmentMenu() return else: self.Preferences.set('native', True) self.Preferences.set('ini_path', self.dir) # get data from platformio.ini file ini_list = [] with open(ini_path, 'r') as file: pattern = compile(r'\[(\w+)\W(\w+)\]') for line in file: if pattern.findall(line): if ('#' not in line): line = match(r"\[\w+:(\w+)\]", line).group(1) ini_list.append(line) # save preferences, update menu data type = 'board_id' if not self.is_native else 'found_ini' self.Preferences.set(type, ini_list) self.Menu.createEnvironmentMenu()