idx
int64
0
63k
question
stringlengths
61
4.03k
target
stringlengths
6
1.23k
40,000
def in_8 ( library , session , space , offset , extended = False ) : value_8 = ViUInt8 ( ) if extended : ret = library . viIn8Ex ( session , space , offset , byref ( value_8 ) ) else : ret = library . viIn8 ( session , space , offset , byref ( value_8 ) ) return value_8 . value , ret
Reads in an 8 - bit value from the specified memory space and offset .
40,001
def in_16 ( library , session , space , offset , extended = False ) : value_16 = ViUInt16 ( ) if extended : ret = library . viIn16Ex ( session , space , offset , byref ( value_16 ) ) else : ret = library . viIn16 ( session , space , offset , byref ( value_16 ) ) return value_16 . value , ret
Reads in an 16 - bit value from the specified memory space and offset .
40,002
def in_32 ( library , session , space , offset , extended = False ) : value_32 = ViUInt32 ( ) if extended : ret = library . viIn32Ex ( session , space , offset , byref ( value_32 ) ) else : ret = library . viIn32 ( session , space , offset , byref ( value_32 ) ) return value_32 . value , ret
Reads in an 32 - bit value from the specified memory space and offset .
40,003
def in_64 ( library , session , space , offset , extended = False ) : value_64 = ViUInt64 ( ) if extended : ret = library . viIn64Ex ( session , space , offset , byref ( value_64 ) ) else : ret = library . viIn64 ( session , space , offset , byref ( value_64 ) ) return value_64 . value , ret
Reads in an 64 - bit value from the specified memory space and offset .
40,004
def map_trigger ( library , session , trigger_source , trigger_destination , mode ) : return library . viMapTrigger ( session , trigger_source , trigger_destination , mode )
Map the specified trigger source line to the specified destination line .
40,005
def memory_allocation ( library , session , size , extended = False ) : offset = ViBusAddress ( ) if extended : ret = library . viMemAllocEx ( session , size , byref ( offset ) ) else : ret = library . viMemAlloc ( session , size , byref ( offset ) ) return offset , ret
Allocates memory from a resource s memory region .
40,006
def move_asynchronously ( library , session , source_space , source_offset , source_width , destination_space , destination_offset , destination_width , length ) : job_id = ViJobId ( ) ret = library . viMoveAsync ( session , source_space , source_offset , source_width , destination_space , destination_offset , destinat...
Moves a block of data asynchronously .
40,007
def move_in_8 ( library , session , space , offset , length , extended = False ) : buffer_8 = ( ViUInt8 * length ) ( ) if extended : ret = library . viMoveIn8Ex ( session , space , offset , length , buffer_8 ) else : ret = library . viMoveIn8 ( session , space , offset , length , buffer_8 ) return list ( buffer_8 ) , r...
Moves an 8 - bit block of data from the specified address space and offset to local memory .
40,008
def move_in_16 ( library , session , space , offset , length , extended = False ) : buffer_16 = ( ViUInt16 * length ) ( ) if extended : ret = library . viMoveIn16Ex ( session , space , offset , length , buffer_16 ) else : ret = library . viMoveIn16 ( session , space , offset , length , buffer_16 ) return list ( buffer_...
Moves an 16 - bit block of data from the specified address space and offset to local memory .
40,009
def move_in_32 ( library , session , space , offset , length , extended = False ) : buffer_32 = ( ViUInt32 * length ) ( ) if extended : ret = library . viMoveIn32Ex ( session , space , offset , length , buffer_32 ) else : ret = library . viMoveIn32 ( session , space , offset , length , buffer_32 ) return list ( buffer_...
Moves an 32 - bit block of data from the specified address space and offset to local memory .
40,010
def move_in_64 ( library , session , space , offset , length , extended = False ) : buffer_64 = ( ViUInt64 * length ) ( ) if extended : ret = library . viMoveIn64Ex ( session , space , offset , length , buffer_64 ) else : ret = library . viMoveIn64 ( session , space , offset , length , buffer_64 ) return list ( buffer_...
Moves an 64 - bit block of data from the specified address space and offset to local memory .
40,011
def move_out_16 ( library , session , space , offset , length , data , extended = False ) : converted_buffer = ( ViUInt16 * length ) ( * tuple ( data ) ) if extended : return library . viMoveOut16Ex ( session , space , offset , length , converted_buffer ) else : return library . viMoveOut16 ( session , space , offset ,...
Moves an 16 - bit block of data from local memory to the specified address space and offset .
40,012
def move_out_32 ( library , session , space , offset , length , data , extended = False ) : converted_buffer = ( ViUInt32 * length ) ( * tuple ( data ) ) if extended : return library . viMoveOut32Ex ( session , space , offset , length , converted_buffer ) else : return library . viMoveOut32 ( session , space , offset ,...
Moves an 32 - bit block of data from local memory to the specified address space and offset .
40,013
def move_out_64 ( library , session , space , offset , length , data , extended = False ) : converted_buffer = ( ViUInt64 * length ) ( * tuple ( data ) ) if extended : return library . viMoveOut64Ex ( session , space , offset , length , converted_buffer ) else : return library . viMoveOut64 ( session , space , offset ,...
Moves an 64 - bit block of data from local memory to the specified address space and offset .
40,014
def open_default_resource_manager ( library ) : session = ViSession ( ) ret = library . viOpenDefaultRM ( byref ( session ) ) return session . value , ret
This function returns a session to the Default Resource Manager resource .
40,015
def out_8 ( library , session , space , offset , data , extended = False ) : if extended : return library . viOut8Ex ( session , space , offset , data ) else : return library . viOut8 ( session , space , offset , data )
Write in an 8 - bit value from the specified memory space and offset .
40,016
def out_16 ( library , session , space , offset , data , extended = False ) : if extended : return library . viOut16Ex ( session , space , offset , data , extended = False ) else : return library . viOut16 ( session , space , offset , data , extended = False )
Write in an 16 - bit value from the specified memory space and offset .
40,017
def out_32 ( library , session , space , offset , data , extended = False ) : if extended : return library . viOut32Ex ( session , space , offset , data ) else : return library . viOut32 ( session , space , offset , data )
Write in an 32 - bit value from the specified memory space and offset .
40,018
def out_64 ( library , session , space , offset , data , extended = False ) : if extended : return library . viOut64Ex ( session , space , offset , data ) else : return library . viOut64 ( session , space , offset , data )
Write in an 64 - bit value from the specified memory space and offset .
40,019
def parse_resource ( library , session , resource_name ) : interface_type = ViUInt16 ( ) interface_board_number = ViUInt16 ( ) ret = library . viParseRsrc ( session , resource_name , byref ( interface_type ) , byref ( interface_board_number ) ) return ResourceInfo ( constants . InterfaceType ( interface_type . value ) ...
Parse a resource string to get the interface information .
40,020
def peek ( library , session , address , width ) : if width == 8 : return peek_8 ( library , session , address ) elif width == 16 : return peek_16 ( library , session , address ) elif width == 32 : return peek_32 ( library , session , address ) elif width == 64 : return peek_64 ( library , session , address ) raise Val...
Read an 8 16 or 32 - bit value from the specified address .
40,021
def peek_8 ( library , session , address ) : value_8 = ViUInt8 ( ) ret = library . viPeek8 ( session , address , byref ( value_8 ) ) return value_8 . value , ret
Read an 8 - bit value from the specified address .
40,022
def peek_16 ( library , session , address ) : value_16 = ViUInt16 ( ) ret = library . viPeek16 ( session , address , byref ( value_16 ) ) return value_16 . value , ret
Read an 16 - bit value from the specified address .
40,023
def peek_32 ( library , session , address ) : value_32 = ViUInt32 ( ) ret = library . viPeek32 ( session , address , byref ( value_32 ) ) return value_32 . value , ret
Read an 32 - bit value from the specified address .
40,024
def peek_64 ( library , session , address ) : value_64 = ViUInt64 ( ) ret = library . viPeek64 ( session , address , byref ( value_64 ) ) return value_64 . value , ret
Read an 64 - bit value from the specified address .
40,025
def poke ( library , session , address , width , data ) : if width == 8 : return poke_8 ( library , session , address , data ) elif width == 16 : return poke_16 ( library , session , address , data ) elif width == 32 : return poke_32 ( library , session , address , data ) raise ValueError ( '%s is not a valid size. Val...
Writes an 8 16 or 32 - bit value from the specified address .
40,026
def poke_8 ( library , session , address , data ) : return library . viPoke8 ( session , address , data )
Write an 8 - bit value from the specified address .
40,027
def poke_16 ( library , session , address , data ) : return library . viPoke16 ( session , address , data )
Write an 16 - bit value from the specified address .
40,028
def poke_32 ( library , session , address , data ) : return library . viPoke32 ( session , address , data )
Write an 32 - bit value from the specified address .
40,029
def poke_64 ( library , session , address , data ) : return library . viPoke64 ( session , address , data )
Write an 64 - bit value from the specified address .
40,030
def read_asynchronously ( library , session , count ) : buffer = create_string_buffer ( count ) job_id = ViJobId ( ) ret = library . viReadAsync ( session , buffer , count , byref ( job_id ) ) return buffer , job_id , ret
Reads data from device or interface asynchronously .
40,031
def read_stb ( library , session ) : status = ViUInt16 ( ) ret = library . viReadSTB ( session , byref ( status ) ) return status . value , ret
Reads a status byte of the service request .
40,032
def read_to_file ( library , session , filename , count ) : return_count = ViUInt32 ( ) ret = library . viReadToFile ( session , filename , count , return_count ) return return_count , ret
Read data synchronously and store the transferred data in a file .
40,033
def status_description ( library , session , status ) : description = create_string_buffer ( 256 ) ret = library . viStatusDesc ( session , status , description ) return buffer_to_text ( description ) , ret
Returns a user - readable description of the status code passed to the operation .
40,034
def terminate ( library , session , degree , job_id ) : return library . viTerminate ( session , degree , job_id )
Requests a VISA session to terminate normal execution of an operation .
40,035
def unmap_trigger ( library , session , trigger_source , trigger_destination ) : return library . viUnmapTrigger ( session , trigger_source , trigger_destination )
Undo a previous map from the specified trigger source line to the specified destination line .
40,036
def usb_control_in ( library , session , request_type_bitmap_field , request_id , request_value , index , length = 0 ) : buffer = create_string_buffer ( length ) return_count = ViUInt16 ( ) ret = library . viUsbControlIn ( session , request_type_bitmap_field , request_id , request_value , index , length , buffer , byre...
Performs a USB control pipe transfer from the device .
40,037
def usb_control_out ( library , session , request_type_bitmap_field , request_id , request_value , index , data = "" ) : length = len ( data ) return library . viUsbControlOut ( session , request_type_bitmap_field , request_id , request_value , index , length , data )
Performs a USB control pipe transfer to the device .
40,038
def wait_on_event ( library , session , in_event_type , timeout ) : out_event_type = ViEventType ( ) out_context = ViEvent ( ) ret = library . viWaitOnEvent ( session , in_event_type , timeout , byref ( out_event_type ) , byref ( out_context ) ) return out_event_type . value , out_context , ret
Waits for an occurrence of the specified event for a given session .
40,039
def write_asynchronously ( library , session , data ) : job_id = ViJobId ( ) ret = library . viWriteAsync ( session , data , len ( data ) , byref ( job_id ) ) return job_id , ret
Writes data to device or interface asynchronously .
40,040
def write_from_file ( library , session , filename , count ) : return_count = ViUInt32 ( ) ret = library . viWriteFromFile ( session , filename , count , return_count ) return return_count , ret
Take data from a file and write it out synchronously .
40,041
def in_resource ( cls , session_type ) : if cls . resources is AllSessionTypes : return True return session_type in cls . resources
Returns True if the attribute is part of a given session type .
40,042
def do_list ( self , args ) : try : resources = self . resource_manager . list_resources_info ( ) except Exception as e : print ( e ) else : self . resources = [ ] for ndx , ( resource_name , value ) in enumerate ( resources . items ( ) ) : if not args : print ( '({0:2d}) {1}' . format ( ndx , resource_name ) ) if valu...
List all connected resources .
40,043
def do_close ( self , args ) : if not self . current : print ( 'There are no resources in use. Use the command "open".' ) return try : self . current . close ( ) except Exception as e : print ( e ) else : print ( 'The resource has been closed.' ) self . current = None self . prompt = self . default_prompt
Close resource in use .
40,044
def do_read ( self , args ) : if not self . current : print ( 'There are no resources in use. Use the command "open".' ) return try : print ( self . current . read ( ) ) except Exception as e : print ( e )
Receive from the resource in use .
40,045
def do_attr ( self , args ) : if not self . current : print ( 'There are no resources in use. Use the command "open".' ) return args = args . strip ( ) if not args : self . print_attribute_list ( ) return args = args . split ( ' ' ) if len ( args ) > 2 : print ( 'Invalid syntax, use `attr <name>` to get; or `attr <name...
Get or set the state for a visa attribute .
40,046
def do_exit ( self , arg ) : if self . current : self . current . close ( ) self . resource_manager . close ( ) del self . resource_manager return True
Exit the shell session .
40,047
def resource_info ( self ) : return self . visalib . parse_resource_extended ( self . _resource_manager . session , self . resource_name )
Get the extended information of this resource .
40,048
def interface_type ( self ) : return self . visalib . parse_resource ( self . _resource_manager . session , self . resource_name ) [ 0 ] . interface_type
The interface type of the resource as a number .
40,049
def close ( self ) : try : logger . debug ( '%s - closing' , self . _resource_name , extra = self . _logging_extra ) self . before_close ( ) self . visalib . close ( self . session ) logger . debug ( '%s - is closed' , self . _resource_name , extra = self . _logging_extra ) self . session = None except errors . Invalid...
Closes the VISA session and marks the handle as invalid .
40,050
def install_handler ( self , event_type , handler , user_handle = None ) : return self . visalib . install_visa_handler ( self . session , event_type , handler , user_handle )
Installs handlers for event callbacks in this resource .
40,051
def uninstall_handler ( self , event_type , handler , user_handle = None ) : self . visalib . uninstall_visa_handler ( self . session , event_type , handler , user_handle )
Uninstalls handlers for events in this resource .
40,052
def discard_events ( self , event_type , mechanism ) : self . visalib . discard_events ( self . session , event_type , mechanism )
Discards event occurrences for specified event types and mechanisms in this resource .
40,053
def enable_event ( self , event_type , mechanism , context = None ) : self . visalib . enable_event ( self . session , event_type , mechanism , context )
Enable event occurrences for specified event types and mechanisms in this resource .
40,054
def wait_on_event ( self , in_event_type , timeout , capture_timeout = False ) : try : event_type , context , ret = self . visalib . wait_on_event ( self . session , in_event_type , timeout ) except errors . VisaIOError as exc : if capture_timeout and exc . error_code == constants . StatusCode . error_timeout : return ...
Waits for an occurrence of the specified event in this resource .
40,055
def lock ( self , timeout = 'default' , requested_key = None ) : timeout = self . timeout if timeout == 'default' else timeout timeout = self . _cleanup_timeout ( timeout ) return self . visalib . lock ( self . session , constants . AccessModes . shared_lock , timeout , requested_key ) [ 0 ]
Establish a shared lock to the resource .
40,056
def lock_excl ( self , timeout = 'default' ) : timeout = self . timeout if timeout == 'default' else timeout timeout = self . _cleanup_timeout ( timeout ) self . visalib . lock ( self . session , constants . AccessModes . exclusive_lock , timeout , None )
Establish an exclusive lock to the resource .
40,057
def lock_context ( self , timeout = 'default' , requested_key = 'exclusive' ) : if requested_key == 'exclusive' : self . lock_excl ( timeout ) access_key = None else : access_key = self . lock ( timeout , requested_key ) try : yield access_key finally : self . unlock ( )
A context that locks
40,058
def del_row ( self , row_index ) : if row_index > len ( self . _rows ) - 1 : raise Exception ( "Cant delete row at index %d, table only has %d rows!" % ( row_index , len ( self . _rows ) ) ) del self . _rows [ row_index ]
Delete a row to the table
40,059
def get_html_string ( self , ** kwargs ) : options = self . _get_options ( kwargs ) if options [ "format" ] : string = self . _get_formatted_html_string ( options ) else : string = self . _get_simple_html_string ( options ) return string
Return string representation of HTML formatted version of table in current state .
40,060
def make_fields_unique ( self , fields ) : for i in range ( 0 , len ( fields ) ) : for j in range ( i + 1 , len ( fields ) ) : if fields [ i ] == fields [ j ] : fields [ j ] += "'"
iterates over the row and make each field unique
40,061
def meta_request ( func ) : def inner ( self , resource , * args , ** kwargs ) : serialize_response = kwargs . pop ( 'serialize' , True ) try : resp = func ( self , resource , * args , ** kwargs ) except ApiException as e : raise api_exception ( e ) if serialize_response : return serialize ( resource , resp ) return re...
Handles parsing response structure and translating API Exceptions
40,062
def watch ( self , resource , namespace = None , name = None , label_selector = None , field_selector = None , resource_version = None , timeout = None ) : watcher = watch . Watch ( ) for event in watcher . stream ( resource . get , namespace = namespace , name = name , field_selector = field_selector , label_selector ...
Stream events for a resource from the Kubernetes API
40,063
def validate ( self , definition , version = None , strict = False ) : if not HAS_KUBERNETES_VALIDATE : raise KubernetesValidateMissing ( ) errors = list ( ) warnings = list ( ) try : if version is None : try : version = self . version [ 'kubernetes' ] [ 'gitVersion' ] except KeyError : version = kubernetes_validate . ...
validate checks a kubernetes resource definition
40,064
def parse_api_groups ( self , request_resources = False , update = False ) : if not self . _cache . get ( 'resources' ) or update : self . _cache [ 'resources' ] = self . _cache . get ( 'resources' , { } ) groups_response = load_json ( self . client . request ( 'GET' , '/{}' . format ( DISCOVERY_PREFIX ) ) ) [ 'groups'...
Discovers all API groups present in the cluster
40,065
def get ( self , ** kwargs ) : results = self . search ( ** kwargs ) if len ( results ) > 1 and kwargs . get ( 'api_version' ) : results = [ result for result in results if result . group_version == kwargs [ 'api_version' ] ] if len ( results ) > 1 and not all ( [ isinstance ( x , ResourceList ) for x in results ] ) : ...
Same as search but will throw an error if there are multiple or no results . If there are multiple results and only one is an exact match on api_version that resource will be returned .
40,066
def add_device ( dev ) : global DEV_IDX , DEFAULT_DEV with DEV_LOCK : for idx in range ( len ( DEVS ) ) : test_dev = DEVS [ idx ] if test_dev . dev_name_short == dev . dev_name_short : if test_dev is DEFAULT_DEV : DEFAULT_DEV = None del DEVS [ idx ] break if find_device_by_name ( dev . name ) : dev . name += '-%d' % DE...
Adds a device to the list of devices we know about .
40,067
def find_device_by_name ( name ) : if not name : return DEFAULT_DEV with DEV_LOCK : for dev in DEVS : if dev . name == name : return dev return None
Tries to find a board by board name .
40,068
def is_micropython_usb_device ( port ) : if type ( port ) . __name__ == 'Device' : if ( 'ID_BUS' not in port or port [ 'ID_BUS' ] != 'usb' or 'SUBSYSTEM' not in port or port [ 'SUBSYSTEM' ] != 'tty' ) : return False usb_id = 'usb vid:pid={}:{}' . format ( port [ 'ID_VENDOR_ID' ] , port [ 'ID_MODEL_ID' ] ) else : usb_id...
Checks a USB device to see if it looks like a MicroPython device .
40,069
def is_micropython_usb_port ( portName ) : for port in serial . tools . list_ports . comports ( ) : if port . device == portName : return is_micropython_usb_device ( port ) return False
Checks to see if the indicated portname is a MicroPython device or not .
40,070
def autoconnect ( ) : if not USE_AUTOCONNECT : return try : import pyudev except ImportError : return context = pyudev . Context ( ) monitor = pyudev . Monitor . from_netlink ( context ) connect_thread = threading . Thread ( target = autoconnect_thread , args = ( monitor , ) , name = 'AutoConnect' ) connect_thread . da...
Sets up a thread to detect when USB devices are plugged and unplugged . If the device looks like a MicroPython board then it will automatically connect to it .
40,071
def autoconnect_thread ( monitor ) : monitor . start ( ) monitor . filter_by ( 'tty' ) epoll = select . epoll ( ) epoll . register ( monitor . fileno ( ) , select . POLLIN ) while True : try : events = epoll . poll ( ) except InterruptedError : continue for fileno , _ in events : if fileno == monitor . fileno ( ) : usb...
Thread which detects USB Serial devices connecting and disconnecting .
40,072
def extra_info ( port ) : extra_items = [ ] if port . manufacturer : extra_items . append ( "vendor '{}'" . format ( port . manufacturer ) ) if port . serial_number : extra_items . append ( "serial '{}'" . format ( port . serial_number ) ) if port . interface : extra_items . append ( "intf '{}'" . format ( port . inter...
Collects the serial nunber and manufacturer into a string if the fields are available .
40,073
def listports ( ) : detected = False for port in serial . tools . list_ports . comports ( ) : detected = True if port . vid : micropythonPort = '' if is_micropython_usb_device ( port ) : micropythonPort = ' *' print ( 'USB Serial Device {:04x}:{:04x}{} found @{}{}\r' . format ( port . vid , port . pid , extra_info ( po...
listports will display a list of all of the serial ports .
40,074
def escape ( str ) : out = '' for char in str : if char in '\\ ' : out += '\\' out += char return out
Precede all special characters with a backslash .
40,075
def align_cell ( fmt , elem , width ) : if fmt == "<" : return elem + ' ' * ( width - len ( elem ) ) if fmt == ">" : return ' ' * ( width - len ( elem ) ) + elem return elem
Returns an aligned element .
40,076
def print_err ( * args , end = '\n' ) : print ( * args , end = end , file = sys . stderr ) sys . stderr . flush ( )
Similar to print but prints to stderr .
40,077
def validate_pattern ( fn ) : directory , pattern = parse_pattern ( fn ) if directory is None : print_err ( "Invalid pattern {}." . format ( fn ) ) return None , None target = resolve_path ( directory ) mode = auto ( get_mode , target ) if not mode_exists ( mode ) : print_err ( "cannot access '{}': No such file or dire...
On success return an absolute path and a pattern . Otherwise print a message and return None None
40,078
def resolve_path ( path ) : if path [ 0 ] == '~' : path = os . path . expanduser ( path ) if path [ 0 ] != '/' : if cur_dir [ - 1 ] == '/' : path = cur_dir + path else : path = cur_dir + '/' + path comps = path . split ( '/' ) new_comps = [ ] for comp in comps : if comp == '.' or ( comp == '' and len ( new_comps ) > 0 ...
Resolves path and converts it into an absolute path .
40,079
def print_bytes ( byte_str ) : if isinstance ( byte_str , str ) : print ( byte_str ) else : print ( str ( byte_str , encoding = 'utf8' ) )
Prints a string or converts bytes to a string and then prints .
40,080
def extra_funcs ( * funcs ) : def extra_funcs_decorator ( real_func ) : def wrapper ( * args , ** kwargs ) : return real_func ( * args , ** kwargs ) wrapper . extra_funcs = list ( funcs ) wrapper . source = inspect . getsource ( real_func ) wrapper . name = real_func . __name__ return wrapper return extra_funcs_decorat...
Decorator which adds extra functions to be downloaded to the pyboard .
40,081
def auto ( func , filename , * args , ** kwargs ) : dev , dev_filename = get_dev_and_path ( filename ) if dev is None : if len ( dev_filename ) > 0 and dev_filename [ 0 ] == '~' : dev_filename = os . path . expanduser ( dev_filename ) return func ( dev_filename , * args , ** kwargs ) return dev . remote_eval ( func , d...
If filename is a remote file then this function calls func on the micropython board otherwise it calls it locally .
40,082
def cat ( src_filename , dst_file ) : ( dev , dev_filename ) = get_dev_and_path ( src_filename ) if dev is None : with open ( dev_filename , 'rb' ) as txtfile : for line in txtfile : dst_file . write ( line ) else : filesize = dev . remote_eval ( get_filesize , dev_filename ) return dev . remote ( send_file_to_host , d...
Copies the contents of the indicated file to an already opened file .
40,083
def copy_file ( src_filename , dst_filename ) : try : with open ( src_filename , 'rb' ) as src_file : with open ( dst_filename , 'wb' ) as dst_file : while True : buf = src_file . read ( BUFFER_SIZE ) if len ( buf ) > 0 : dst_file . write ( buf ) if len ( buf ) < BUFFER_SIZE : break return True except : return False
Copies a file from one place to another . Both the source and destination files must exist on the same machine .
40,084
def cp ( src_filename , dst_filename ) : src_dev , src_dev_filename = get_dev_and_path ( src_filename ) dst_dev , dst_dev_filename = get_dev_and_path ( dst_filename ) if src_dev is dst_dev : return auto ( copy_file , src_filename , dst_dev_filename ) filesize = auto ( get_filesize , src_filename ) if dst_dev is None : ...
Copies one file to another . The source file may be local or remote and the destination file may be local or remote .
40,085
def stat ( filename ) : import os try : rstat = os . lstat ( filename ) except : rstat = os . stat ( filename ) return rstat [ : 7 ] + tuple ( tim + TIME_OFFSET for tim in rstat [ 7 : ] )
Returns os . stat for a given file adjusting the timestamps as appropriate .
40,086
def listdir_matches ( match ) : import os last_slash = match . rfind ( '/' ) if last_slash == - 1 : dirname = '.' match_prefix = match result_prefix = '' else : match_prefix = match [ last_slash + 1 : ] if last_slash == 0 : dirname = '/' result_prefix = '/' else : dirname = match [ 0 : last_slash ] result_prefix = dirn...
Returns a list of filenames contained in the named directory . Only filenames which start with match will be returned . Directories will have a trailing slash .
40,087
def listdir_stat ( dirname , show_hidden = True ) : import os try : files = os . listdir ( dirname ) except OSError : return None if dirname == '/' : return list ( ( file , stat ( '/' + file ) ) for file in files if is_visible ( file ) or show_hidden ) return list ( ( file , stat ( dirname + '/' + file ) ) for file in ...
Returns a list of tuples for each file contained in the named directory or None if the directory does not exist . Each tuple contains the filename followed by the tuple returned by calling os . stat on the filename .
40,088
def remove_file ( filename , recursive = False , force = False ) : import os try : mode = os . stat ( filename ) [ 0 ] if mode & 0x4000 != 0 : if recursive : for file in os . listdir ( filename ) : success = remove_file ( filename + '/' + file , recursive , force ) if not success and not force : return False os . rmdir...
Removes a file or directory .
40,089
def rm ( filename , recursive = False , force = False ) : return auto ( remove_file , filename , recursive , force )
Removes a file or directory tree .
40,090
def make_dir ( dst_dir , dry_run , print_func , recursed ) : parent = os . path . split ( dst_dir . rstrip ( '/' ) ) [ 0 ] parent_files = auto ( listdir_stat , parent ) if parent else True if dry_run : if recursed : print_func ( "Creating directory {}" . format ( dst_dir ) ) elif parent_files is None : print_func ( "Un...
Creates a directory . Produces information in case of dry run . Issues error where necessary .
40,091
def recv_file_from_host ( src_file , dst_filename , filesize , dst_mode = 'wb' ) : import sys import ubinascii if HAS_BUFFER : try : import pyb usb = pyb . USB_VCP ( ) except : try : import machine usb = machine . USB_VCP ( ) except : usb = None if usb and usb . isconnected ( ) : usb . setinterrupt ( - 1 ) try : with o...
Function which runs on the pyboard . Matches up with send_file_to_remote .
40,092
def send_file_to_remote ( dev , src_file , dst_filename , filesize , dst_mode = 'wb' ) : bytes_remaining = filesize save_timeout = dev . timeout dev . timeout = 1 while bytes_remaining > 0 : ack = dev . read ( 1 ) if ack is None or ack != b'\x06' : sys . stderr . write ( "timed out or error in transfer to remote\n" ) s...
Intended to be passed to the remote function as the xfer_func argument . Matches up with recv_file_from_host .
40,093
def recv_file_from_remote ( dev , src_filename , dst_file , filesize ) : bytes_remaining = filesize if not HAS_BUFFER : bytes_remaining *= 2 buf_size = BUFFER_SIZE write_buf = bytearray ( buf_size ) while bytes_remaining > 0 : read_size = min ( bytes_remaining , buf_size ) buf_remaining = read_size buf_index = 0 while ...
Intended to be passed to the remote function as the xfer_func argument . Matches up with send_file_to_host .
40,094
def send_file_to_host ( src_filename , dst_file , filesize ) : import sys import ubinascii try : with open ( src_filename , 'rb' ) as src_file : bytes_remaining = filesize if HAS_BUFFER : buf_size = BUFFER_SIZE else : buf_size = BUFFER_SIZE // 2 while bytes_remaining > 0 : read_size = min ( bytes_remaining , buf_size )...
Function which runs on the pyboard . Matches up with recv_file_from_remote .
40,095
def print_cols ( words , print_func , termwidth = 79 ) : width = max ( [ word_len ( word ) for word in words ] ) nwords = len ( words ) ncols = max ( 1 , ( termwidth + 1 ) // ( width + 1 ) ) nrows = ( nwords + ncols - 1 ) // ncols for row in range ( nrows ) : for i in range ( row , nwords , nrows ) : word = words [ i ]...
Takes a single column of words and prints it as multiple columns that will fit in termwidth columns .
40,096
def print_long ( filename , stat , print_func ) : size = stat_size ( stat ) mtime = stat_mtime ( stat ) file_mtime = time . localtime ( mtime ) curr_time = time . time ( ) if mtime > ( curr_time + SIX_MONTHS ) or mtime < ( curr_time - SIX_MONTHS ) : print_func ( '%6d %s %2d %04d %s' % ( size , MONTH [ file_mtime [ 1 ]...
Prints detailed information about the file passed in .
40,097
def connect ( port , baud = 115200 , user = 'micro' , password = 'python' , wait = 0 ) : try : ip_address = socket . gethostbyname ( port ) connect_telnet ( port , ip_address , user = user , password = password ) except socket . gaierror : connect_serial ( port , baud = baud , wait = wait )
Tries to connect automagically via network or serial .
40,098
def connect_telnet ( name , ip_address = None , user = 'micro' , password = 'python' ) : if ip_address is None : try : ip_address = socket . gethostbyname ( name ) except socket . gaierror : ip_address = name if not QUIET : if name == ip_address : print ( 'Connecting to (%s) ...' % ip_address ) else : print ( 'Connecti...
Connect to a MicroPython board via telnet .
40,099
def connect_serial ( port , baud = 115200 , wait = 0 ) : if not QUIET : print ( 'Connecting to %s (buffer-size %d)...' % ( port , BUFFER_SIZE ) ) try : dev = DeviceSerial ( port , baud , wait ) except DeviceError as err : sys . stderr . write ( str ( err ) ) sys . stderr . write ( '\n' ) return False add_device ( dev )...
Connect to a MicroPython board via a serial port .