def clean(self): ardupycoredir = user_config_dir + "/ardupycore/ArduPy" if os.path.exists(ardupycoredir): try: shutil.rmtree(ardupycoredir) except OSError as error: log.warning("Directory '%s remove failed' " % ardupycoredir) log.warning(error)
def run(self, options, args): moduledir = Path(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) else: log.warning(package[package.find("/") + 1:] + " not exists!") return SUCCESS
def stty(self): if self.port == "": port, desc, hwid, isbootloader = self.serial.getAvailableBoard() self.port = port if self.port == "None": log.warning("please plug in a ArduPy Board!") print("<usage> aip run [-p, --port=<port>] [local_file]") return "echo not support" if os.name == "posix": if platform.uname().system == "Darwin": return "stty -f " + self.port + " %d" return "stty -F " + self.port + " %d" elif os.name == "nt": return "MODE " + self.port + ":BAUD=%d PARITY=N DATA=8" return "echo not support"
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): link = Link("http://files.seeedstudio.com/ardupy/ardupy-core.zip") downloader = Downloader(session, progress_bar="on") ardupycoredir = user_config_dir + "/ardupycore" if not os.path.exists(ardupycoredir + "/ArduPy"): try: if not os.path.exists(ardupycoredir): os.makedirs(ardupycoredir) except OSError as error: log.warning("Directory '%s was exists' " % ardupycoredir) log.warning(error) unpack_url( link, ardupycoredir, downloader=downloader, download_dir=None, ) if not os.path.exists(ardupycoredir + "/Seeeduino/tools/arm-none-eabi-gcc"): if sys.platform == "linux": link = Link( "http://files.seeedstudio.com/arduino/tools/x86_64-pc-linux-gnu/gcc-arm-none-eabi-4.8.3-2014q1-linux64.tar.gz" ) if sys.platform == "win32": link = Link( "http://files.seeedstudio.com/arduino/tools/i686-mingw32/gcc-arm-none-eabi-4.8.3-2014q1-windows.tar.gz" ) if sys.platform == "darwin": link = Link( "http://files.seeedstudio.com/arduino/tools/x86_64-apple-darwin/gcc-arm-none-eabi-4.8.3-2014q1-mac.tar.gz" ) unpack_url( link, ardupycoredir + "/Seeeduino/tools/arm-none-eabi-gcc", downloader=downloader, download_dir=None, )
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): 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
def run(self, options, args): if options.port == "": port, desc, hwid, isbootloader = self.serial.getAvailableBoard() self.port = port else: port = options.port if port == None: log.error("Sorry, the device you should have is not plugged in.") return ERROR board_id = self.serial.getBoardIdByPort(self.port) if parser.get_flash_isTouch_by_id(board_id): try_count = 0 do_bossac = True while True: stty = self.stty print(stty) if stty != "echo not support": os.system(stty % 1200) #os.system(str(bossac)+ " --help") time.sleep(1) port, desc, hwid, isbootloader = self.serial.getBootloaderBoard( ) if isbootloader == True: self.port = port break try_count = try_count + 1 if port == None: continue if try_count == 5: do_bossac = False break if do_bossac == True: flash_tools = parser.get_flash_tool_by_id(board_id) #print(flash_tools) if len(args) != 0: ardupybin = args[0] else: ardupybin = str( Path(parser.get_deploy_dir_by_id(board_id), "Ardupy.bin")) flash_command = parser.get_flash_command_by_id( board_id, self.port, ardupybin) print(flash_tools + "/" + flash_command) os.system(flash_tools + "/" + flash_command) else: log.warning( "Sorry, the device you should have is not plugged in.") return ERROR else: flash_tools = parser.get_flash_tool_by_id(board_id) ardupybin = "" if len(args) != 0: ardupybin = args[0] else: ardupybin = str( Path(parser.get_deploy_dir_by_id(board_id), "Ardupy.bin")) flash_command = parser.get_flash_command_by_id( board_id, self.port, ardupybin) print(flash_tools + "/" + flash_command) os.system(flash_tools + "/" + flash_command) return SUCCESS