def run(self, options, args): ser = SerialUtils() if options.port == "": port, desc, hwid, isbootloader = ser.getAvailableBoard() else: port = options.port if port == "None": print("\033[93mplease plug in a ArduPy Board!\033[0m") print("<usage> aip get -p, --port <port> <remote_file> <local_file>") return ERROR _board = Pyboard(port) board_files = Files(_board) directory = "/" if len(args) > 0: directory = args[0] for f in board_files.ls(directory, options.long_format, options.recursive): print(f) return SUCCESS
def run(self, options, args): ser = SerialUtils() if options.port == "": port, desc, hwid, isbootloader = ser.getAvailableBoard() else: port = options.port if port == "None": print("\033[93mplease plug in a ArduPy Board!\033[0m") print( "<usage> aip rmdir -p, --port <port> -m --missing <directory>") return ERROR _board = Pyboard(port) if len(args) == 0: print("directory is necessary!") print( "<usage> aip rmdir -p, --port <port> -m --missing <directory>") return ERROR directory = args[0] _board = Pyboard(port) board_files = Files(_board) board_files.rmdir(directory, missing_okay=options.missing_okay) return SUCCESS
def run(self, options, args): ser = SerialUtils() if options.port == "": port, desc, hwid, isbootloader = ser.getAvailableBoard() else: port = options.port if port == "None": print("\033[93mplease plug in a ArduPy Board!\033[0m") print( "<usage> aip run -p, --port <port> <local_file>") return ERROR if len(args) == 0: print("local file is necessary!") print( "<usage> aip run -p, --port <port> <local_file>") return ERROR local_file_name = args[0] _board = Pyboard(port) board_files = Files(_board) try: output = board_files.run( local_file_name, not options.no_output, not options.no_output) if output is not None: print(output.decode("utf-8"), end="") except IOError: print("Failed to find or read input file: {0}".format( local_file), err=True) return SUCCESS
def run(self, options, args): ser = SerialUtils() if options.port == "": port, desc, hwid, isbootloader = ser.getAvailableBoard() else: port = options.port if port == "None": print("\033[93mplease plug in a ArduPy Board!\033[0m") print( "<usage> aip rm -p, --port <port> <remote_file>") return ERROR _board = Pyboard(port) if len(args) == 0: print("remote file is necessary!") print( "<usage> aip rm -p, --port <port> <remote_file>") return ERROR remote_file_name = args[0] board_files = Files(_board) board_files.rm(remote_file_name) return SUCCESS
def run(self, options, args): ser = SerialUtils() if options.list == True: print(ser.listBoard()) return SUCCESS if options.board == "": print(ser.listAvailableBoard()) else: print(ser.listDesignatedBoard(options.board)) return SUCCESS
def run(self, options, args): ser = SerialUtils() if options.port == "": port, desc, hwid, isbootloader = ser.getAvailableBoard() else: port = options.port if port == "None": print("\033[93mplease plug in a ArduPy Board!\033[0m") print( "<usage> aip run -p, --port <port> <local_file>") return ERROR _board = Pyboard(port) print(_board.get_version()) return SUCCESS
def __init__(self, *args, **kw): super(flashCommand, self).__init__(*args, **kw) self.cmd_opts.add_option('-p', '--port', dest='port', action='store', default="", help='The port of the ArduPy board.') self.parser.insert_option_group(0, self.cmd_opts) index_opts = cmdoptions.make_option_group( cmdoptions.index_group, self.parser, ) self.parser.insert_option_group(0, index_opts) self.serial = SerialUtils()
def run(self, options, args): ser = SerialUtils() if options.port == "": port, desc, hwid, isbootloader = ser.getAvailableBoard() else: port = options.port if port == "None": print("\033[93mplease plug in a ArduPy Board!\033[0m") print("<usage> aip get -p, --port <port> <remote_file> <local_file>") return ERROR _board = Pyboard(port) if len(args) == 0: print("remote_file is necessary!") print("<usage> aip get -p, --port <port> <remote_file> <local_file>") return ERROR remote_file_name = args[0] local_file_name = "" if len(args) >= 2: local_file_name = args[1] board_files = Files(_board) remote_file = board_files.get(remote_file_name) if local_file_name != "": local_file = open(local_file_name, mode="wb", newline=None) local_file.write(remote_file) local_file.close() else: print(remote_file.decode("utf-8")) return SUCCESS
def run(self, options, args): ser = SerialUtils() if options.port == "": port, desc, hwid, isbootloader = ser.getAvailableBoard() else: port = options.port if port == "None": print("\033[93mplease plug in a ArduPy Board!\033[0m") print( "<usage> aip put -p, --port <port> <local_file> <remote_file>") return ERROR _board = Pyboard(port) if len(args) == 0: print("local file is necessary!") print("<usage> aip put -p, --port <port> <local_file> <remote_file>") return ERROR local_file_name = args[0] remote_file_name = "" if len(args) >= 2: remote_file_name = args[1] # Use the local filename if no remote filename is provided. if remote_file_name == "": remote_file_name = os.path.basename( os.path.abspath(local_file_name)) board_files = Files(_board) if os.path.isdir(local_file_name): # Directory copy, create the directory and walk all children to copy # over the files. board_files = Files(_board) for parent, child_dirs, child_files in os.walk(local_file_name, followlinks=True): # Create board filesystem absolute path to parent directory. remote_parent = posixpath.normpath( posixpath.join(remote_file_name, os.path.relpath( parent, local_file_name)) ) try: # Create remote parent directory. board_files.mkdir(remote_parent) except DirectoryExistsError: # Ignore errors for directories that already exist. pass # Loop through all the files and put them on the board too. for filename in child_files: with open(os.path.join(parent, filename), "rb") as infile: remote_filename = posixpath.join( remote_parent, filename) board_files.put(remote_filename, infile.read()) else: # File copy, open the file and copy its contents to the board. # Put the file on the board. with open(local_file_name, "rb") as infile: board_files = Files(_board) board_files.put(remote_file_name, infile.read()) return SUCCESS
class flashCommand(RequirementCommand): """ Show information about one or more installed packages. The output is in RFC-compliant mail header format. """ name = 'flash' usage = """ %prog [options] <package> ...""" summary = "flash all of package" ignore_require_venv = True def __init__(self, *args, **kw): super(flashCommand, self).__init__(*args, **kw) self.cmd_opts.add_option('-p', '--port', dest='port', action='store', default="", help='The port of the ArduPy board.') self.parser.insert_option_group(0, self.cmd_opts) index_opts = cmdoptions.make_option_group( cmdoptions.index_group, self.parser, ) self.parser.insert_option_group(0, index_opts) self.serial = SerialUtils() @property def stty(self): if self.port == "": port, desc, hwid, isbootloader = self.serial.getAvailableBoard() self.port = port if self.port == "None": print("\033[93mplease plug in a ArduPy Board!\033[0m") 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): self.port = options.port bossacdir = Path(user_data_dir + "/ardupycore/Seeeduino/tools/bossac") print(str(bossacdir)) if not os.path.exists(bossacdir): os.makedirs(bossacdir) session = self.get_default_session(options) if sys.platform == "linux": link = Link( "http://files.seeedstudio.com/arduino/tools/i686-linux-gnu/bossac-1.9.1-seeeduino-linux.tar.gz" ) if sys.platform == "win32": link = Link( "http://files.seeedstudio.com/arduino/tools/i686-mingw32/bossac-1.9.1-seeeduino-windows.tar.bz2" ) if sys.platform == "darwin": link = Link( "http://files.seeedstudio.com/arduino/tools/i386-apple-darwin11/bossac-1.9.1-arduino1-osx.tar.gz" ) bossac = "" if platform.system() == "Windows": bossac = Path(bossacdir, "bossac.exe") else: bossac = Path(bossacdir, "bossac") if not os.path.exists(bossac): downloader = Downloader(session, progress_bar="on") unpack_url( link, bossacdir, downloader=downloader, download_dir=None, ) 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") port, desc, hwid, isbootloader = self.serial.getBootloaderBoard() print(port) time.sleep(1) if isbootloader == True: break try_count = try_count + 1 if try_count == 5: do_bossac = False break name, version, url = self.serial.getBoardByPort(port) ardupybin = "" if len(args) > 0: ardupybin = args[0] if not os.path.exists(ardupybin): print('\033[31m The path of firmware didn\'t exists!\033[0m') return ERROR else: firmwaredir = Path(user_data_dir + "/deploy/firmware/" + name.replace(' ', '_')) if not os.path.exists(firmwaredir): os.makedirs(firmwaredir) ardupybin = str(Path(firmwaredir, "ardupy_laster.bin")) if not os.path.exists(ardupybin): downloader = Downloader(session, progress_bar="on") _download_http_url(link=Link(url), downloader=downloader, temp_dir=firmwaredir, hashes=None) if do_bossac == True: print((str(bossac) + grove_ui_flashParam) % (port, ardupybin)) os.system((str(bossac) + grove_ui_flashParam) % (port, ardupybin)) else: print( "\033[93mSorry, the device you should have is not plugged in.[0m" ) return SUCCESS
def __init__(self, *args, **kw): super(rshellCommand, self).__init__(*args, **kw) default_baud = 115200 default_port = os.getenv('RSHELL_PORT') default_rts = os.getenv('RSHELL_RTS') or rsh.RTS default_dtr = os.getenv('RSHELL_DTR') or rsh.DTR default_user = os.getenv('RSHELL_USER') or 'micro' default_password = os.getenv('RSHELL_PASSWORD') or 'python' default_editor = os.getenv('RSHELL_EDITOR') or os.getenv( 'VISUAL') or os.getenv('EDITOR') or 'vi' default_color = sys.stdout.isatty() default_nocolor = not default_color self.cmd_opts.add_option("-b", "--baud", dest="baud", action="store", type=int, help="Set the baudrate used (default = %d)" % default_baud, default=default_baud) self.cmd_opts.add_option( "--buffer-size", dest="buffer_size", action="store", type=int, help="Set the buffer size used for transfers " "(default = %d for USB, %d for UART)" % (rsh.USB_BUFFER_SIZE, rsh.UART_BUFFER_SIZE), ) self.cmd_opts.add_option( "-p", "--port", dest="port", help="Set the serial port to use (default '%s')" % default_port, default=default_port) self.cmd_opts.add_option("--rts", dest="rts", help="Set the RTS state (default '%s')" % default_rts, default=default_rts) self.cmd_opts.add_option("--dtr", dest="dtr", help="Set the DTR state (default '%s')" % default_dtr, default=default_dtr) self.cmd_opts.add_option("-u", "--user", dest="user", help="Set username to use (default '%s')" % default_user, default=default_user) self.cmd_opts.add_option("-w", "--password", dest="password", help="Set password to use (default '%s')" % default_password, default=default_password) self.cmd_opts.add_option("-e", "--editor", dest="editor", help="Set the editor to use (default '%s')" % default_editor, default=default_editor) self.cmd_opts.add_option( "--file", dest="filename", help="Specifies a file of commands to process.") self.cmd_opts.add_option("-d", "--debug", dest="debug", action="store_true", help="Enable debug features", default=False) self.cmd_opts.add_option("-n", "--nocolor", dest="nocolor", action="store_true", help="Turn off colorized output", default=default_nocolor) self.cmd_opts.add_option("-l", "--list", dest="list", action="store_true", help="Display serial ports", default=False) self.cmd_opts.add_option("-a", "--ascii", dest="ascii_xfer", action="store_true", help="ASCII encode binary files for transfer", default=False) self.cmd_opts.add_option("--wait", dest="wait", type=int, action="store", help="Seconds to wait for serial port", default=0) self.cmd_opts.add_option( "--timing", dest="timing", action="store_true", help="Print timing information about each command", default=False) self.cmd_opts.add_option("--cmd", dest="cmd", type=str, action="store", help="Optional command to execute") self.parser.insert_option_group(0, self.cmd_opts) index_opts = cmdoptions.make_option_group( cmdoptions.index_group, self.parser, ) self.parser.insert_option_group(0, index_opts) self.serial = SerialUtils()
class rshellCommand(RequirementCommand): """ Show information about one or more installed packages. The output is in RFC-compliant mail header format. """ name = 'rshell' usage = """ %prog [options] <package> ...""" summary = "" ignore_require_venv = True port = "" def __init__(self, *args, **kw): super(rshellCommand, self).__init__(*args, **kw) default_baud = 115200 default_port = os.getenv('RSHELL_PORT') default_rts = os.getenv('RSHELL_RTS') or rsh.RTS default_dtr = os.getenv('RSHELL_DTR') or rsh.DTR default_user = os.getenv('RSHELL_USER') or 'micro' default_password = os.getenv('RSHELL_PASSWORD') or 'python' default_editor = os.getenv('RSHELL_EDITOR') or os.getenv( 'VISUAL') or os.getenv('EDITOR') or 'vi' default_color = sys.stdout.isatty() default_nocolor = not default_color self.cmd_opts.add_option("-b", "--baud", dest="baud", action="store", type=int, help="Set the baudrate used (default = %d)" % default_baud, default=default_baud) self.cmd_opts.add_option( "--buffer-size", dest="buffer_size", action="store", type=int, help="Set the buffer size used for transfers " "(default = %d for USB, %d for UART)" % (rsh.USB_BUFFER_SIZE, rsh.UART_BUFFER_SIZE), ) self.cmd_opts.add_option( "-p", "--port", dest="port", help="Set the serial port to use (default '%s')" % default_port, default=default_port) self.cmd_opts.add_option("--rts", dest="rts", help="Set the RTS state (default '%s')" % default_rts, default=default_rts) self.cmd_opts.add_option("--dtr", dest="dtr", help="Set the DTR state (default '%s')" % default_dtr, default=default_dtr) self.cmd_opts.add_option("-u", "--user", dest="user", help="Set username to use (default '%s')" % default_user, default=default_user) self.cmd_opts.add_option("-w", "--password", dest="password", help="Set password to use (default '%s')" % default_password, default=default_password) self.cmd_opts.add_option("-e", "--editor", dest="editor", help="Set the editor to use (default '%s')" % default_editor, default=default_editor) self.cmd_opts.add_option( "--file", dest="filename", help="Specifies a file of commands to process.") self.cmd_opts.add_option("-d", "--debug", dest="debug", action="store_true", help="Enable debug features", default=False) self.cmd_opts.add_option("-n", "--nocolor", dest="nocolor", action="store_true", help="Turn off colorized output", default=default_nocolor) self.cmd_opts.add_option("-l", "--list", dest="list", action="store_true", help="Display serial ports", default=False) self.cmd_opts.add_option("-a", "--ascii", dest="ascii_xfer", action="store_true", help="ASCII encode binary files for transfer", default=False) self.cmd_opts.add_option("--wait", dest="wait", type=int, action="store", help="Seconds to wait for serial port", default=0) self.cmd_opts.add_option( "--timing", dest="timing", action="store_true", help="Print timing information about each command", default=False) self.cmd_opts.add_option("--cmd", dest="cmd", type=str, action="store", help="Optional command to execute") self.parser.insert_option_group(0, self.cmd_opts) index_opts = cmdoptions.make_option_group( cmdoptions.index_group, self.parser, ) self.parser.insert_option_group(0, index_opts) self.serial = SerialUtils() def run(self, options, args): save_settings = None stdin_fd = -1 try: import termios stdin_fd = sys.stdin.fileno() save_settings = termios.tcgetattr(stdin_fd) except: pass BUFFER_SIZE = 512 if options.buffer_size is not None: BUFFER_SIZE = options.buffer_size try: print("Debug = %s" % options.debug) print("Port = %s" % options.port) print("Baud = %d" % options.baud) print("User = %s" % options.user) print("Password = %s" % options.password) print("Wait = %d" % options.wait) print("List = %d" % options.list) print("nocolor = %d" % options.nocolor) print("ascii = %d" % options.ascii_xfer) print("Timing = %d" % options.timing) print("Quiet = %d" % options.quiet) print("BUFFER_SIZE = %d" % BUFFER_SIZE) print("Cmd = [%s]" % options.cmd) global ASCII_XFER ASCII_XFER = options.ascii_xfer RTS = options.rts DTR = options.dtr if options.list: rsh.listports() return if options.port: self.port = options.port else: port, desc, hwid, isbootloader = self.serial.getAvailableBoard( ) self.port = port rsh.ASCII_XFER = True try: rsh.connect(self.port, baud=options.baud, wait=options.wait, user=options.user, password=options.password) except rsh.DeviceError as err: print(err) rsh.autoconnect() if options.filename: with open(options.filename) as cmd_file: shell = rsh.Shell(stdin=cmd_file, filename=options.filename, timing=options.timing) shell.cmdloop('') else: cmd_line = options.cmd if cmd_line == None: print('Welcome to rshell.', rsh.EXIT_STR) if rsh.num_devices() == 0: print('') print( 'No MicroPython boards connected - use the connect command to add one' ) print('') shell = rsh.Shell(timing=options.timing) try: shell.cmdloop(cmd_line) except KeyboardInterrupt: print('') finally: if save_settings: termios.tcsetattr(stdin_fd, termios.TCSANOW, save_settings)