def run(self, options, args): if len(args) == 0: log.warning("Please enter the name of the library!") log.info( 'Usage:\n\r aip uninstall seeed-ardupy-ultrasonic-sensor') return ERROR moduledir = Path(parser.user_config_dir, "modules") for package in args: log.debug(package[package.find("/") + 1:]) if os.path.exists( str(Path(moduledir, package[package.find("/") + 1:]))): shutil.rmtree(str( Path(moduledir, package[package.find("/") + 1:])), onerror=readonly_handler) log.info("Uninstall " + package + " succeeded.") else: log.warning(package[package.find("/") + 1:] + " not exists!") return SUCCESS
def downloadAll(self, session): archiveFile = parser.get_archiveFile_by_id(self.board_id) downloader = Downloader(session, progress_bar="on") ardupycoredir = parser.get_core_dir_by_id(self.board_id) if not os.path.exists(ardupycoredir): log.info('Downloading ' + archiveFile['archiveFileName'] + '...') try: unpack_url( Link(archiveFile['url']), ardupycoredir, downloader, download_dir=None, ) except Exception as e: log.error(e) os.remove(ardupycoredir) sys.exit(1) except Exception as e: log.error(e) os.remove(ardupycoredir) sys.exit(1) toolsDependencies = parser.get_toolsDependencies_url_by_id( self.board_id) toolsdir = parser.get_tool_dir_by_id(self.board_id) for tool in toolsDependencies: tooldir = str(Path(toolsdir, tool['name'], tool['version'])) if not os.path.exists(tooldir): log.info('Downloading ' + tool['name'] + '@' + tool['version'] + '...') try: unpack_url( Link(tool['url']), tooldir, downloader, download_dir=None, ) except Exception as e: log.error(e) os.remove(tooldir) sys.exit(1)
def update_loacl_library_json(self): log.info("update local library json...") for url in self.get_library_additional_url(): url = url.strip() log.info(url) url_path = url.split('/')[len(url.split('/')) - 1] try: urllib.request.urlretrieve( url, str(Path(self.user_config_dir, url_path))) except Exception as e: log.error(e) continue else: log.info("done!")
def update_loacl_board_json(self): log.info("update local board json...") self.config_file = open(self.config_file_path, 'r+') self.cp = ConfigParser() self.cp.read(self.config_file_path) for url in self.get_board_additional_url(): url = url.strip() log.info(url) url_path = url.split('/')[len(url.split('/')) - 1] try: urllib.request.urlretrieve( url, str(Path(self.user_config_dir, url_path))) except Exception as e: log.error(e) continue else: self.cp.set("board", 'update time', str(date.today().isoformat())) self.cp.write(self.config_file) log.info("done!")
def run(self, options, args): if options.list == True: ser = SerialUtils() print(ser.listBoard()) return SUCCESS if 'clean' in args: self.clean() return SUCCESS if options.board != "": self.board = options.board session = self.get_default_session(options) # setup deploy dir deploydir = str(Path(user_config_dir, "deploy")) if not os.path.exists(deploydir): os.makedirs(deploydir) # create build dir, This folder will be deleted after compilation builddir = mktemp() os.makedirs(builddir) self.downloadAll(session) self.get_arduinocore_version() # Converts the header file to the absolute path of the current system for h in ardupycore_headers: # add Arduino Core version if h[0:35] == "/ardupycore/Seeeduino/hardware/samd": h = h.format(self.arduinoCoreVersion) self.headerlist.append(str(Path(user_config_dir + h))) self.headerlist.append( str(Path(user_config_dir + board_headers + self.board))) # setup ardupy modules dir moduledir = str(Path(user_config_dir, "modules")) if not os.path.exists(moduledir): os.makedirs(moduledir) modules = os.listdir(moduledir) if modules: for m in modules: # Gets the source files for all modules for f in self.fileEndWith( os.path.join(user_config_dir + "/modules/", m), '.cpp', '.c'): self.srcfile.append(str(Path(f))) # Sets the root directory of the module to be where the header file is found for r, d, f in os.walk( str(Path(user_config_dir + "/modules/" + m))): if r.find('.git') == -1 and r.find("examples") == -1: self.headerlist.append(r) # Convert the necessary files in ardupycore into the absolute path of the system. for mp_file in mp_needful_file: self.srcfile.append(str(Path(user_config_dir + mp_file))) self.generatedInitfile(builddir) # Convert to the required format for GCC self.generatedQstrdefs(builddir) self.headers = "-I" + " -I".join(self.headerlist) # Compile all source files self.buildFarm(builddir) firmware_path = str(Path(str(deploydir) + "/Ardupy.bin")) #remove the old firmware if os.path.exists(firmware_path): os.remove(firmware_path) # Convert ELF files to binary files objcopy_cmd = str(Path(user_config_dir + gcc_48_objcopy)) + "-O binary " \ + str(Path(builddir + "/Ardupy")) + " " \ + firmware_path log.debug(objcopy_cmd) os.system(objcopy_cmd) # Print size information os.system( str(Path(user_config_dir + gcc_48_size)) + " -A " + str(Path(builddir + "/Ardupy"))) # delete build dir shutil.rmtree(builddir) if os.path.exists(firmware_path): log.info('Firmware path: ' + firmware_path) log.info('Usage:\n\r aip flash') else: raise Exception(print('compile error')) #return ERRO return SUCCESS
def main(args=None): # type: (Optional[List[str]]) -> int if args is None: args = sys.argv[1:] # is update package_seeeduino_ardupy_index.json user_config_dir = str(appdirs.user_config_dir(appname="aip")) if not os.path.exists(user_config_dir): os.makedirs(user_config_dir) today = date.today() user_config_dir_files = os.listdir(user_config_dir) current_package_seeeduino_ardupy = "xxxxx" is_update = True for files in user_config_dir_files: if files[0:30] == "package_seeeduino_ardupy_index": file_data = datetime.strptime(files[31:41], '%Y-%m-%d').date() current_package_seeeduino_ardupy = files if file_data == today: is_update = False break if is_update: log.info("update latest package_seeeduino_ardupy_index.json ...") try: urllib.request.urlretrieve( 'https://files.seeedstudio.com/ardupy/package_seeeduino_ardupy_index.json', str( Path( user_config_dir, "package_seeeduino_ardupy_index_" + today.isoformat() + ".json"))) if os.path.exists( str(Path(user_config_dir, current_package_seeeduino_ardupy))): os.remove( str(Path(user_config_dir, current_package_seeeduino_ardupy))) except Exception as e: log.error(e) log.warning( "update latest package_seeeduino_ardupy_index.json Failed! Please check you network connction!" ) sys.exit(1) from aip.command import commands_dict, parse_command # Configure our deprecation warnings to be sent through loggers deprecation.install_warning_logger() autocomplete() try: cmd_name, cmd_args = parse_command(args) except PipError as exc: sys.stderr.write("ERROR: {}".format(exc)) sys.stderr.write(os.linesep) sys.exit(1) # Needed for locale.getpreferredencoding(False) to work # in pip._internal.utils.encoding.auto_decode try: locale.setlocale(locale.LC_ALL, '') except locale.Error as e: # setlocale can apparently crash if locale are uninitialized print("Ignoring error %s when setting locale", e) module = importlib.import_module("aip." + cmd_name) command_class = getattr(module, cmd_name + "Command") command = command_class(name=cmd_name, summary="...") return command.main(cmd_args)
def run(self, options, args): moduledir = Path(user_config_dir, "modules") session = self.get_default_session(options) downloader = Downloader(session, progress_bar="on") for package in args: package_url = self.get_archive_url(options, package) package_location = package_url[:package_url.find('/archive')] package_location = package_location.split('/')[ len(package_location.split('/')) - 1] package_location = str(Path(moduledir, package_location)) # form location if options.Force: if os.path.exists(package_location): # remove the old package shutil.rmtree(package_location, onerror=readonly_handler) try: os.makedirs(package_location) except OSError as error: log.error(error) log.info("Use aip install -F Overwrite previous Library") return ERROR log.info("Downloading library......") try: unpack_url( Link(package_url), package_location, downloader=downloader, download_dir=None, ) except Exception as error: log.error(error) if os.path.exists(package_location): # remove the old package shutil.rmtree(package_location, onerror=readonly_handler) return ERROR # downling dependencies package_json_location = Path(package_location, 'library.json') try: #get library.json from package with open(package_json_location, 'r') as package_json: #get dependencies information from library.json package_json_dict = json.load(package_json) dependencies = package_json_dict["dependencies"] if len(dependencies) != 0: log.info("Downloading dependencies......") for dependency in dependencies: dependency_url = self.get_archive_url( options, dependency["url"]) dependency_location = package_location + '/' + dependency[ "name"] try: unpack_url( Link(dependency_url), dependency_location, downloader=downloader, download_dir=None, ) except Exception as error: log.error(error) if os.path.exists(package_location ): # remove the old package shutil.rmtree(package_location, onerror=readonly_handler) return ERROR except Exception as error: log.error(error) log.error("Bad dependency format, please check library.json") if os.path.exists(package_location): # remove the old package shutil.rmtree(package_location, onerror=readonly_handler) return ERROR
def run(self, options, args): if len(args) == 0: log.warning("Please enter the url of the library!") log.info( 'Usage:\n\r aip install https://github.com/Seeed-Studio/seeed-ardupy-ultrasonic-sensor' ) return ERROR moduledir = Path(parser.user_config_dir, "modules") session = self.get_default_session(options) downloader = Downloader(session, progress_bar="on") for package in args: if options.local: package_location = package.split('/')[len(package.split('/')) - 1] else: package_url = self.get_archive_url(options, package) package_location = package_url[:package_url.find('/archive')] package_location = package_location.split('/')[ len(package_location.split('/')) - 1] package_location = str(Path(moduledir, package_location)) # form location if options.Force: if os.path.exists(package_location): # remove the old package shutil.rmtree(package_location, onerror=readonly_handler) try: os.makedirs(package_location) except OSError as error: log.error(error) log.info("Use aip install -F Overwrite previous Library") return ERROR try: if options.local: log.info("Copying library......") shutil.copytree(package, package_location, dirs_exist_ok=True) else: log.info("Downloading library......") unpack_url( Link(package_url), package_location, downloader=downloader, download_dir=None, ) except Exception as error: log.error(error) if os.path.exists(package_location): # remove the old package shutil.rmtree(package_location, onerror=readonly_handler) return ERROR # downling dependencies package_json_location = Path(package_location, 'library.json') try: #get library.json from package with open(package_json_location, 'r') as package_json: #get dependencies information from library.json package_json_dict = json.load(package_json) dependencies = package_json_dict["dependencies"] if len(dependencies) != 0: log.info("Downloading dependencies......") for dependency in dependencies: dependency_url = self.get_archive_url( options, dependency["url"]) dependency_location = package_location + '/' + dependency[ "name"] try: unpack_url( Link(dependency_url), dependency_location, downloader=downloader, download_dir=None, ) except Exception as error: log.error(error) if os.path.exists(package_location ): # remove the old package shutil.rmtree(package_location, onerror=readonly_handler) return ERROR except Exception as error: log.error(error) log.error("Bad dependency format, please check library.json") if os.path.exists(package_location): # remove the old package shutil.rmtree(package_location, onerror=readonly_handler) return ERROR return SUCCESS
def run(self, options, args): if options.board == "": port, desc, hwid, isbootloader = self.serial.getAvailableBoard() if port != None: _board = self.serial.getBoardByPort(port) if _board != "": self.board = _board[0] else: log.warning( "please plug in a ArduPy Board or specify the board to build!" ) print("<usage> aip build [--board=<board>] ") return else: self.board = options.board self.board_id = self.serial.getBoardIdByName(self.board) if self.board_id == -1: log.error("Unable to find information about '" + self.board + "'") return ERROR self.verbose = options.verbose self.initBoard() seesion = self.get_default_session(options) self.downloadAll(seesion) # setup deploy dir deploydir = parser.get_deploy_dir_by_id(self.board_id) if not os.path.exists(deploydir): os.makedirs(deploydir) # create build dir, This folder will be deleted after compilation builddir = mktemp() os.makedirs(builddir) log.info("|---------------" + " Building Firmware for " + self.board + "---------------|") arduinodir = parser.get_arduino_dir_by_id(self.board_id) arduinocoredir = str(Path(arduinodir, "cores", "arduino")) # Converts the header file to the absolute path of the current system # 1 append Arduino Core PATH self.headerlist.append(arduinocoredir) for file in os.listdir(arduinocoredir): file_path = str(Path(arduinocoredir, file)) if os.path.isdir(file_path): self.headerlist.append(file_path) # 2 append Arduino variants PATH self.headerlist.append(parser.get_variant_dir_by_id(self.board_id)) # 3 append Arduino library PATH librariesdir = str(Path(arduinodir, "libraries")) for library in os.listdir(librariesdir): library_path = str(Path(librariesdir, library)) self.headerlist.append(library_path) if (os.path.exists(str(Path(library_path, "src")))): self.headerlist.append(str(Path(library_path, "src"))) # 4 append Ardupy core PATH self.headerlist.append(parser.get_ardupy_dir_by_id(self.board_id)) self.headerlist.append(parser.get_ardupy_board_by_id(self.board_id)) self.headerlist.append( str(Path(parser.get_ardupy_dir_by_id(self.board_id), "MicroPython"))) # 5 append moudules PATh moduledir = str(Path(parser.user_config_dir, "modules")) if not os.path.exists(moduledir): os.makedirs(moduledir) modules = os.listdir(moduledir) if modules: for m in modules: # Gets the source files for all modules for f in self.fileEndWith( os.path.join(str(Path(moduledir, m))), '.cpp', '.c'): self.srcfile.append(str(Path(f))) # Sets the root directory of the module to be where the header file is found for r, d, f in os.walk(str(Path(moduledir, m))): if r.find('.git') == -1 and r.find("examples") == -1: self.headerlist.append(r) # 6 Convert the necessary files in ardupycore into the absolute path of the system. self.srcfile.append( str( Path(parser.get_ardupy_dir_by_id(self.board_id), "MicroPython", "py", "objmodule.c"))) self.srcfile.append( str( Path(parser.get_ardupy_dir_by_id(self.board_id), "MicroPython", "py", "parse.c"))) self.srcfile.append( str( Path(parser.get_ardupy_dir_by_id(self.board_id), "MicroPython", "py", "qstr.c"))) # 7 generatrd Init file for binding self.generatedInitfile(builddir) # 8 Convert to the required format for GCC self.generatedQstrdefs(builddir) # 9 append build temp dir self.headerlist.append(str(Path(builddir))) # 10 inform headers headerlist self.headers = "-I" + " -I".join(self.headerlist) # 11 build firmware self.buildFirmware(builddir) # 12 remove the old firmware firmware_path = str(Path(str(deploydir), "Ardupy.bin")) if os.path.exists(firmware_path): os.remove(firmware_path) # 13 convert elf to bin self.objcopy_cmd = self.objcopy + " -O binary " \ + str(Path(builddir + "/Ardupy")) + " " \ + firmware_path self.doVerbose(self.objcopy_cmd) os.system(self.objcopy_cmd) # 14 print information self.sizetool_cmd = self.sizetool + \ " -A " + str(Path(builddir + "/Ardupy")) print("") os.system(self.sizetool_cmd) # 15 print information # delete build dir shutil.rmtree(builddir) if os.path.exists(firmware_path): log.info('Firmware path: ' + firmware_path) log.info('Usage:\n\r aip flash') else: raise Exception(print('compile error')) return SUCCESS