idx int64 0 63k | question stringlengths 53 5.28k | target stringlengths 5 805 |
|---|---|---|
22,200 | def _exception_raise ( self ) : exc = self . exc_info ( ) [ : ] try : exc_type , exc_value , exc_traceback = exc except ValueError : exc_type , exc_value = exc exc_traceback = None if sys . version_info [ 0 ] == 2 : exec ( "raise exc_type, exc_value, exc_traceback" ) else : if isinstance ( exc_value , Exception ) : exe... | Raises a pending exception that was recorded while getting a Task ready for execution . |
22,201 | def no_next_candidate ( self ) : while self . candidates : candidates = self . candidates self . candidates = [ ] self . will_not_build ( candidates ) return None | Stops Taskmaster processing by not returning a next candidate . |
22,202 | def _validate_pending_children ( self ) : for n in self . pending_children : assert n . state in ( NODE_PENDING , NODE_EXECUTING ) , ( str ( n ) , StateString [ n . state ] ) assert len ( n . waiting_parents ) != 0 , ( str ( n ) , len ( n . waiting_parents ) ) for p in n . waiting_parents : assert p . ref_count > 0 , (... | Validate the content of the pending_children set . Assert if an internal error is found . |
22,203 | def next_task ( self ) : node = self . _find_next_ready_node ( ) if node is None : return None executor = node . get_executor ( ) if executor is None : return None tlist = executor . get_all_targets ( ) task = self . tasker ( self , tlist , node in self . original_top , node ) try : task . make_ready ( ) except Excepti... | Returns the next task to be executed . |
22,204 | def cleanup ( self ) : if not self . pending_children : return nclist = [ ( n , find_cycle ( [ n ] , set ( ) ) ) for n in self . pending_children ] genuine_cycles = [ node for node , cycle in nclist if cycle or node . get_state ( ) != NODE_EXECUTED ] if not genuine_cycles : return desc = 'Found dependency cycle(s):\n' ... | Check for dependency cycles . |
22,205 | def instantiate_resolver ( self , name , args ) : if name not in self . _known_resolvers : raise ArgumentError ( "Attempting to instantiate unknown dependency resolver" , name = name ) return self . _known_resolvers [ name ] ( args ) | Directly instantiate a dependency resolver by name with the given arguments |
22,206 | def pull_release ( self , name , version , destfolder = "." , force = False ) : unique_id = name . replace ( '/' , '_' ) depdict = { 'name' : name , 'unique_id' : unique_id , 'required_version' : version , 'required_version_string' : str ( version ) } destdir = os . path . join ( destfolder , unique_id ) if os . path .... | Download and unpack a released iotile component by name and version range |
22,207 | def update_dependency ( self , tile , depinfo , destdir = None ) : if destdir is None : destdir = os . path . join ( tile . folder , 'build' , 'deps' , depinfo [ 'unique_id' ] ) has_version = False had_version = False if os . path . exists ( destdir ) : has_version = True had_version = True for priority , rule in self ... | Attempt to install or update a dependency to the latest version . |
22,208 | def _check_dep ( self , depinfo , deptile , resolver ) : try : settings = self . _load_depsettings ( deptile ) except IOError : return False if settings [ 'resolver' ] != resolver . __class__ . __name__ : return None resolver_settings = { } if 'settings' in settings : resolver_settings = settings [ 'settings' ] return ... | Check if a dependency tile is up to date |
22,209 | def _log_future_exception ( future , logger ) : if not future . done ( ) : return try : future . result ( ) except : logger . warning ( "Exception in ignored future: %s" , future , exc_info = True ) | Log any exception raised by future . |
22,210 | def create_subtask ( self , cor , name = None , stop_timeout = 1.0 ) : if self . stopped : raise InternalError ( "Cannot add a subtask to a parent that is already stopped" ) subtask = BackgroundTask ( cor , name , loop = self . _loop , stop_timeout = stop_timeout ) self . add_subtask ( subtask ) return subtask | Create and add a subtask from a coroutine . |
22,211 | def add_subtask ( self , subtask ) : if self . stopped : raise InternalError ( "Cannot add a subtask to a parent that is already stopped" ) if not isinstance ( subtask , BackgroundTask ) : raise ArgumentError ( "Subtasks must inherit from BackgroundTask, task={}" . format ( subtask ) ) if subtask . _loop != self . _loo... | Link a subtask to this parent task . |
22,212 | async def stop ( self ) : if self . stopped : return self . _logger . debug ( "Stopping task %s" , self . name ) if self . _finalizer is not None : try : result = self . _finalizer ( self ) if inspect . isawaitable ( result ) : await result except : self . _logger . exception ( "Error running finalizer for task %s" , s... | Stop this task and wait until it and all its subtasks end . |
22,213 | def stop_threadsafe ( self ) : if self . stopped : return try : self . _loop . run_coroutine ( self . stop ( ) ) except asyncio . TimeoutError : raise TimeoutExpiredError ( "Timeout stopping task {} with {} subtasks" . format ( self . name , len ( self . subtasks ) ) ) | Stop this task from another thread and wait for it to finish . |
22,214 | def start ( self , aug = 'EventLoopThread' ) : if self . stopping : raise LoopStoppingError ( "Cannot perform action while loop is stopping." ) if not self . loop : self . _logger . debug ( "Starting event loop" ) self . loop = asyncio . new_event_loop ( ) self . thread = threading . Thread ( target = self . _loop_thre... | Ensure the background loop is running . |
22,215 | def wait_for_interrupt ( self , check_interval = 1.0 , max_time = None ) : self . start ( ) wait = max ( check_interval , 0.01 ) accum = 0 try : while max_time is None or accum < max_time : try : time . sleep ( wait ) except IOError : pass accum += wait except KeyboardInterrupt : pass | Run the event loop until we receive a ctrl - c interrupt or max_time passes . |
22,216 | def stop ( self ) : if not self . loop : return if self . inside_loop ( ) : raise InternalError ( "BackgroundEventLoop.stop() called from inside event loop; " "would have deadlocked." ) try : self . run_coroutine ( self . _stop_internal ( ) ) self . thread . join ( ) except : self . _logger . exception ( "Error stoppin... | Synchronously stop the background loop from outside . |
22,217 | async def _stop_internal ( self ) : if self . stopping is True : return self . stopping = True awaitables = [ task . stop ( ) for task in self . tasks ] results = await asyncio . gather ( * awaitables , return_exceptions = True ) for task , result in zip ( self . tasks , results ) : if isinstance ( result , Exception )... | Cleanly stop the event loop after shutting down all tasks . |
22,218 | def _loop_thread_main ( self ) : asyncio . set_event_loop ( self . loop ) self . _loop_check . inside_loop = True try : self . _logger . debug ( "Starting loop in background thread" ) self . loop . run_forever ( ) self . _logger . debug ( "Finished loop in background thread" ) except : self . _logger . exception ( "Exc... | Main background thread running the event loop . |
22,219 | def add_task ( self , cor , name = None , finalizer = None , stop_timeout = 1.0 , parent = None ) : if self . stopping : raise LoopStoppingError ( "Cannot add task because loop is stopping" ) self . start ( ) if parent is not None and parent not in self . tasks : raise ArgumentError ( "Designated parent task {} is not ... | Schedule a task to run on the background event loop . |
22,220 | def run_coroutine ( self , cor , * args , ** kwargs ) : if self . stopping : raise LoopStoppingError ( "Could not launch coroutine because loop is shutting down: %s" % cor ) self . start ( ) cor = _instaniate_coroutine ( cor , args , kwargs ) if self . inside_loop ( ) : raise InternalError ( "BackgroundEventLoop.run_co... | Run a coroutine to completion and return its result . |
22,221 | def log_coroutine ( self , cor , * args , ** kwargs ) : if self . stopping : raise LoopStoppingError ( "Could not launch coroutine because loop is shutting down: %s" % cor ) self . start ( ) cor = _instaniate_coroutine ( cor , args , kwargs ) def _run_and_log ( ) : task = self . loop . create_task ( cor ) task . add_do... | Run a coroutine logging any exception raised . |
22,222 | def link_cloud ( self , username = None , password = None , device_id = None ) : reg = ComponentRegistry ( ) domain = self . get ( 'cloud:server' ) if username is None : prompt_str = "Please enter your IOTile.cloud email: " username = input ( prompt_str ) if password is None : prompt_str = "Please enter your IOTile.clo... | Create and store a token for interacting with the IOTile Cloud API . |
22,223 | def _load_file ( self ) : if not os . path . exists ( self . file ) : return { } with open ( self . file , "r" ) as infile : data = json . load ( infile ) return data | Load all entries from json backing file |
22,224 | def _save_file ( self , data ) : if platform . system ( ) == 'Windows' : with open ( self . file , "w" ) as outfile : json . dump ( data , outfile ) else : newpath = self . file + '.new' with open ( newpath , "w" ) as outfile : json . dump ( data , outfile ) os . rename ( os . path . realpath ( newpath ) , os . path . ... | Attempt to atomically save file by saving and then moving into position |
22,225 | def remove ( self , key ) : data = self . _load_file ( ) del data [ key ] self . _save_file ( data ) | Remove a key from the data store |
22,226 | def set ( self , key , value ) : data = self . _load_file ( ) data [ key ] = value self . _save_file ( data ) | Set the value of a key |
22,227 | def trigger_chain ( self ) : trigger_stream = self . allocator . attach_stream ( self . trigger_stream ) return ( trigger_stream , self . trigger_cond ) | Return a NodeInput tuple for creating a node . |
22,228 | def generate ( env ) : static_obj , shared_obj = SCons . Tool . createObjBuilders ( env ) for suffix in CSuffixes : static_obj . add_action ( suffix , SCons . Defaults . CAction ) shared_obj . add_action ( suffix , SCons . Defaults . ShCAction ) static_obj . add_emitter ( suffix , SCons . Defaults . StaticObjectEmitter... | Add Builders and construction variables for C compilers to an Environment . |
22,229 | def process_mock_rpc ( input_string ) : spec , equals , value = input_string . partition ( u'=' ) if len ( equals ) == 0 : print ( "Could not parse mock RPC argument: {}" . format ( input_string ) ) sys . exit ( 1 ) try : value = int ( value . strip ( ) , 0 ) except ValueError as exc : print ( "Could not parse mock RPC... | Process a mock RPC argument . |
22,230 | def watch_printer ( watch , value ) : print ( "({: 8} s) {}: {}" . format ( value . raw_time , watch , value . value ) ) | Print a watched value . |
22,231 | def main ( argv = None ) : if argv is None : argv = sys . argv [ 1 : ] try : executor = None parser = build_args ( ) args = parser . parse_args ( args = argv ) model = DeviceModel ( ) parser = SensorGraphFileParser ( ) parser . parse_file ( args . sensor_graph ) parser . compile ( model ) if not args . disable_optimize... | Main entry point for iotile sensorgraph simulator . |
22,232 | def _verify_tile_versions ( self , hw ) : for tile , expected_tile_version in self . _tile_versions . items ( ) : actual_tile_version = str ( hw . get ( tile ) . tile_version ( ) ) if expected_tile_version != actual_tile_version : raise ArgumentError ( "Tile has incorrect firmware" , tile = tile , expected_version = ex... | Verify that the tiles have the correct versions |
22,233 | def _verify_realtime_streams ( self , hw ) : print ( " ) time . sleep ( 2.1 ) reports = [ x for x in hw . iter_reports ( ) ] reports_seen = { key : 0 for key in self . _realtime_streams } for report in reports : stream_value = report . visible_readings [ 0 ] . stream if reports_seen . get ( stream_value ) is not None :... | Check that the realtime streams are being produced |
22,234 | def _update_pot_file ( target , source , env ) : import re import os import SCons . Action nop = lambda target , source , env : 0 save_cwd = env . fs . getcwd ( ) save_os_cwd = os . getcwd ( ) chdir = target [ 0 ] . dir chdir_str = repr ( chdir . get_abspath ( ) ) env . Execute ( SCons . Action . Action ( nop , "Enteri... | Action function for POTUpdate builder |
22,235 | def _scan_xgettext_from_files ( target , source , env , files = None , path = None ) : import re import SCons . Util import SCons . Node . FS if files is None : return 0 if not SCons . Util . is_List ( files ) : files = [ files ] if path is None : if 'XGETTEXTPATH' in env : path = env [ 'XGETTEXTPATH' ] else : path = [... | Parses POTFILES . in - like file and returns list of extracted file names . |
22,236 | def _pot_update_emitter ( target , source , env ) : from SCons . Tool . GettextCommon import _POTargetFactory import SCons . Util import SCons . Node . FS if 'XGETTEXTFROM' in env : xfrom = env [ 'XGETTEXTFROM' ] else : return target , source if not SCons . Util . is_List ( xfrom ) : xfrom = [ xfrom ] xfrom = SCons . U... | Emitter function for POTUpdate builder |
22,237 | def _POTUpdateBuilder ( env , ** kw ) : import SCons . Action from SCons . Tool . GettextCommon import _POTargetFactory kw [ 'action' ] = SCons . Action . Action ( _update_pot_file , None ) kw [ 'suffix' ] = '$POTSUFFIX' kw [ 'target_factory' ] = _POTargetFactory ( env , alias = '$POTUPDATE_ALIAS' ) . File kw [ 'emitte... | Creates POTUpdate builder object |
22,238 | def generate ( env , ** kw ) : import SCons . Util from SCons . Tool . GettextCommon import RPaths , _detect_xgettext try : env [ 'XGETTEXT' ] = _detect_xgettext ( env ) except : env [ 'XGETTEXT' ] = 'xgettext' sources = '$( ${_concat( "", SOURCES, "", __env__, XgettextRPaths, TARGET' + ', SOURCES)} $)' xgettextcom = '... | Generate xgettext tool |
22,239 | def generate ( env ) : if 'CC' not in env : env [ 'CC' ] = env . Detect ( compilers ) or compilers [ 0 ] cc . generate ( env ) if env [ 'PLATFORM' ] in [ 'cygwin' , 'win32' ] : env [ 'SHCCFLAGS' ] = SCons . Util . CLVar ( '$CCFLAGS' ) else : env [ 'SHCCFLAGS' ] = SCons . Util . CLVar ( '$CCFLAGS -fPIC' ) version = dete... | Add Builders and construction variables for gcc to an Environment . |
22,240 | def detect_version ( env , cc ) : cc = env . subst ( cc ) if not cc : return None version = None pipe = SCons . Action . _subproc ( env , SCons . Util . CLVar ( cc ) + [ '--version' ] , stdin = 'devnull' , stderr = 'devnull' , stdout = subprocess . PIPE ) line = SCons . Util . to_str ( pipe . stdout . readline ( ) ) ma... | Return the version of the GNU compiler or None if it is not a GNU compiler . |
22,241 | def is_dos_short_file_name ( file ) : fname , ext = os . path . splitext ( file ) proper_ext = len ( ext ) == 0 or ( 2 <= len ( ext ) <= 4 ) proper_fname = file . isupper ( ) and len ( fname ) <= 8 return proper_ext and proper_fname | Examine if the given file is in the 8 . 3 form . |
22,242 | def create_feature_dict ( files ) : dict = { } def add_to_dict ( feature , file ) : if not SCons . Util . is_List ( feature ) : feature = [ feature ] for f in feature : if f not in dict : dict [ f ] = [ file ] else : dict [ f ] . append ( file ) for file in files : if hasattr ( file , 'PACKAGING_X_MSI_FEATURE' ) : add_... | X_MSI_FEATURE and doc FileTag s can be used to collect files in a hierarchy . This function collects the files into this hierarchy . |
22,243 | def generate_guids ( root ) : from hashlib import md5 needs_id = { 'Product' : 'Id' , 'Package' : 'Id' , 'Component' : 'Guid' , } for ( key , value ) in needs_id . items ( ) : node_list = root . getElementsByTagName ( key ) attribute = value for node in node_list : hash = md5 ( node . toxml ( ) ) . hexdigest ( ) hash_s... | generates globally unique identifiers for parts of the xml which need them . |
22,244 | def create_default_directory_layout ( root , NAME , VERSION , VENDOR , filename_set ) : doc = Document ( ) d1 = doc . createElement ( 'Directory' ) d1 . attributes [ 'Id' ] = 'TARGETDIR' d1 . attributes [ 'Name' ] = 'SourceDir' d2 = doc . createElement ( 'Directory' ) d2 . attributes [ 'Id' ] = 'ProgramFilesFolder' d2 ... | Create the wix default target directory layout and return the innermost directory . |
22,245 | def build_wxsfile_file_section ( root , files , NAME , VERSION , VENDOR , filename_set , id_set ) : root = create_default_directory_layout ( root , NAME , VERSION , VENDOR , filename_set ) components = create_feature_dict ( files ) factory = Document ( ) def get_directory ( node , dir ) : if dir == '' or not dir : retu... | Builds the Component sections of the wxs file with their included files . |
22,246 | def build_wxsfile_default_gui ( root ) : factory = Document ( ) Product = root . getElementsByTagName ( 'Product' ) [ 0 ] UIRef = factory . createElement ( 'UIRef' ) UIRef . attributes [ 'Id' ] = 'WixUI_Mondo' Product . childNodes . append ( UIRef ) UIRef = factory . createElement ( 'UIRef' ) UIRef . attributes [ 'Id' ... | This function adds a default GUI to the wxs file |
22,247 | def build_license_file ( directory , spec ) : name , text = '' , '' try : name = spec [ 'LICENSE' ] text = spec [ 'X_MSI_LICENSE_TEXT' ] except KeyError : pass if name != '' or text != '' : file = open ( os . path . join ( directory . get_path ( ) , 'License.rtf' ) , 'w' ) file . write ( '{\\rtf' ) if text != '' : file... | Creates a License . rtf file with the content of X_MSI_LICENSE_TEXT in the given directory |
22,248 | def build_wxsfile_header_section ( root , spec ) : factory = Document ( ) Product = factory . createElement ( 'Product' ) Package = factory . createElement ( 'Package' ) root . childNodes . append ( Product ) Product . childNodes . append ( Package ) if 'X_MSI_LANGUAGE' not in spec : spec [ 'X_MSI_LANGUAGE' ] = '1033' ... | Adds the xml file node which define the package meta - data . |
22,249 | def generate ( env ) : path , cxx , shcxx , version = get_cppc ( env ) if path : cxx = os . path . join ( path , cxx ) shcxx = os . path . join ( path , shcxx ) cplusplus . generate ( env ) env [ 'CXX' ] = cxx env [ 'SHCXX' ] = shcxx env [ 'CXXVERSION' ] = version env [ 'SHCXXFLAGS' ] = SCons . Util . CLVar ( '$CXXFLAG... | Add Builders and construction variables for SunPRO C ++ . |
22,250 | def FromReadings ( cls , uuid , readings , events , report_id = IOTileReading . InvalidReadingID , selector = 0xFFFF , streamer = 0x100 , sent_timestamp = 0 , received_time = None ) : lowest_id = IOTileReading . InvalidReadingID highest_id = IOTileReading . InvalidReadingID for item in itertools . chain ( iter ( readin... | Create a flexible dictionary report from a list of readings and events . |
22,251 | def decode ( self ) : report_dict = msgpack . unpackb ( self . raw_report , raw = False ) events = [ IOTileEvent . FromDict ( x ) for x in report_dict . get ( 'events' , [ ] ) ] readings = [ IOTileReading . FromDict ( x ) for x in report_dict . get ( 'data' , [ ] ) ] if 'device' not in report_dict : raise DataError ( "... | Decode this report from a msgpack encoded binary blob . |
22,252 | def _callable_contents ( obj ) : try : return _function_contents ( obj . __func__ ) except AttributeError : try : return _function_contents ( obj . __call__ . __func__ ) except AttributeError : try : return _code_contents ( obj ) except AttributeError : return _function_contents ( obj ) | Return the signature contents of a callable Python object . |
22,253 | def _object_contents ( obj ) : try : return _function_contents ( obj . __func__ ) except AttributeError : try : return _function_contents ( obj . __call__ . __func__ ) except AttributeError : try : return _code_contents ( obj ) except AttributeError : try : return _function_contents ( obj ) except AttributeError as ae ... | Return the signature contents of any Python object . |
22,254 | def _code_contents ( code , docstring = None ) : contents = bytearray ( "{}, {}" . format ( code . co_argcount , len ( code . co_varnames ) ) , 'utf-8' ) contents . extend ( b", " ) contents . extend ( bytearray ( str ( len ( code . co_cellvars ) ) , 'utf-8' ) ) contents . extend ( b", " ) contents . extend ( bytearray... | Return the signature contents of a code object . |
22,255 | def _object_instance_content ( obj ) : retval = bytearray ( ) if obj is None : return b'N.' if isinstance ( obj , SCons . Util . BaseStringTypes ) : return SCons . Util . to_bytes ( obj ) inst_class = obj . __class__ inst_class_name = bytearray ( obj . __class__ . __name__ , 'utf-8' ) inst_class_module = bytearray ( ob... | Returns consistant content for a action class or an instance thereof |
22,256 | def _do_create_keywords ( args , kw ) : v = kw . get ( 'varlist' , ( ) ) if is_String ( v ) : v = ( v , ) kw [ 'varlist' ] = tuple ( v ) if args : cmdstrfunc = args [ 0 ] if cmdstrfunc is None or is_String ( cmdstrfunc ) : kw [ 'cmdstr' ] = cmdstrfunc elif callable ( cmdstrfunc ) : kw [ 'strfunction' ] = cmdstrfunc els... | This converts any arguments after the action argument into their equivalent keywords and adds them to the kw argument . |
22,257 | def _do_create_list_action ( act , kw ) : acts = [ ] for a in act : aa = _do_create_action ( a , kw ) if aa is not None : acts . append ( aa ) if not acts : return ListAction ( [ ] ) elif len ( acts ) == 1 : return acts [ 0 ] else : return ListAction ( acts ) | A factory for list actions . Convert the input list into Actions and then wrap them in a ListAction . |
22,258 | def Action ( act , * args , ** kw ) : _do_create_keywords ( args , kw ) if is_List ( act ) : return _do_create_list_action ( act , kw ) return _do_create_action ( act , kw ) | A factory for action objects . |
22,259 | def _string_from_cmd_list ( cmd_list ) : cl = [ ] for arg in map ( str , cmd_list ) : if ' ' in arg or '\t' in arg : arg = '"' + arg + '"' cl . append ( arg ) return ' ' . join ( cl ) | Takes a list of command line arguments and returns a pretty representation for printing . |
22,260 | def get_default_ENV ( env ) : global default_ENV try : return env [ 'ENV' ] except KeyError : if not default_ENV : import SCons . Environment default_ENV = SCons . Environment . Environment ( ) [ 'ENV' ] return default_ENV | A fiddlin little function that has an import SCons . Environment which can t be moved to the top level without creating an import loop . Since this import creates a local variable named SCons it blocks access to the global variable so we move it here to prevent complaints about local variables being used uninitialized ... |
22,261 | def execute ( self , target , source , env , executor = None ) : escape_list = SCons . Subst . escape_list flatten_sequence = SCons . Util . flatten_sequence try : shell = env [ 'SHELL' ] except KeyError : raise SCons . Errors . UserError ( 'Missing SHELL construction variable.' ) try : spawn = env [ 'SPAWN' ] except K... | Execute a command action . |
22,262 | def get_presig ( self , target , source , env ) : try : return self . gc ( target , source , env ) except AttributeError : return self . funccontents | Return the signature contents of this callable action . |
22,263 | def get_presig ( self , target , source , env ) : return b"" . join ( [ bytes ( x . get_contents ( target , source , env ) ) for x in self . list ] ) | Return the signature contents of this action list . |
22,264 | async def _notify_update ( self , name , change_type , change_info = None , directed_client = None ) : for monitor in self . _monitors : try : result = monitor ( name , change_type , change_info , directed_client = directed_client ) if inspect . isawaitable ( result ) : await result except Exception : self . _logger . ... | Notify updates on a service to anyone who cares . |
22,265 | async def update_state ( self , short_name , state ) : if short_name not in self . services : raise ArgumentError ( "Service name is unknown" , short_name = short_name ) if state not in states . KNOWN_STATES : raise ArgumentError ( "Invalid service state" , state = state ) serv = self . services [ short_name ] [ 'state... | Set the current state of a service . |
22,266 | def add_service ( self , name , long_name , preregistered = False , notify = True ) : if name in self . services : raise ArgumentError ( "Could not add service because the long_name is taken" , long_name = long_name ) serv_state = states . ServiceState ( name , long_name , preregistered ) service = { 'state' : serv_sta... | Add a service to the list of tracked services . |
22,267 | def service_info ( self , short_name ) : if short_name not in self . services : raise ArgumentError ( "Unknown service name" , short_name = short_name ) info = { } info [ 'short_name' ] = short_name info [ 'long_name' ] = self . services [ short_name ] [ 'state' ] . long_name info [ 'preregistered' ] = self . services ... | Get static information about a service . |
22,268 | def service_messages ( self , short_name ) : if short_name not in self . services : raise ArgumentError ( "Unknown service name" , short_name = short_name ) return list ( self . services [ short_name ] [ 'state' ] . messages ) | Get the messages stored for a service . |
22,269 | def service_headline ( self , short_name ) : if short_name not in self . services : raise ArgumentError ( "Unknown service name" , short_name = short_name ) return self . services [ short_name ] [ 'state' ] . headline | Get the headline stored for a service . |
22,270 | def service_status ( self , short_name ) : if short_name not in self . services : raise ArgumentError ( "Unknown service name" , short_name = short_name ) info = { } service = self . services [ short_name ] [ 'state' ] info [ 'heartbeat_age' ] = monotonic ( ) - service . last_heartbeat info [ 'numeric_status' ] = servi... | Get the current status of a service . |
22,271 | async def send_message ( self , name , level , message ) : if name not in self . services : raise ArgumentError ( "Unknown service name" , short_name = name ) msg = self . services [ name ] [ 'state' ] . post_message ( level , message ) await self . _notify_update ( name , 'new_message' , msg . to_dict ( ) ) | Post a message for a service . |
22,272 | async def set_headline ( self , name , level , message ) : if name not in self . services : raise ArgumentError ( "Unknown service name" , short_name = name ) self . services [ name ] [ 'state' ] . set_headline ( level , message ) headline = self . services [ name ] [ 'state' ] . headline . to_dict ( ) await self . _no... | Set the sticky headline for a service . |
22,273 | async def send_heartbeat ( self , short_name ) : if short_name not in self . services : raise ArgumentError ( "Unknown service name" , short_name = short_name ) self . services [ short_name ] [ 'state' ] . heartbeat ( ) await self . _notify_update ( short_name , 'heartbeat' ) | Post a heartbeat for a service . |
22,274 | def set_agent ( self , short_name , client_id ) : if short_name not in self . services : raise ArgumentError ( "Unknown service name" , short_name = short_name ) self . agents [ short_name ] = client_id | Register a client id that handlers commands for a service . |
22,275 | def clear_agent ( self , short_name , client_id ) : if short_name not in self . services : raise ArgumentError ( "Unknown service name" , short_name = short_name ) if short_name not in self . agents : raise ArgumentError ( "No agent registered for service" , short_name = short_name ) if client_id != self . agents [ sho... | Remove a client id from being the command handler for a service . |
22,276 | async def send_rpc_command ( self , short_name , rpc_id , payload , sender_client , timeout = 1.0 ) : rpc_tag = str ( uuid . uuid4 ( ) ) self . rpc_results . declare ( rpc_tag ) if short_name in self . services and short_name in self . agents : agent_tag = self . agents [ short_name ] rpc_message = { 'rpc_id' : rpc_id ... | Send an RPC to a service using its registered agent . |
22,277 | def send_rpc_response ( self , rpc_tag , result , response ) : if rpc_tag not in self . in_flight_rpcs : raise ArgumentError ( "In flight RPC could not be found, it may have timed out" , rpc_tag = rpc_tag ) del self . in_flight_rpcs [ rpc_tag ] response_message = { 'response' : response , 'result' : result } try : self... | Send a response to an RPC . |
22,278 | def periodic_service_rpcs ( self ) : to_remove = [ ] now = monotonic ( ) for rpc_tag , rpc in self . in_flight_rpcs . items ( ) : expiry = rpc . sent_timestamp + rpc . timeout if now > expiry : to_remove . append ( rpc_tag ) for tag in to_remove : del self . in_flight_rpcs [ tag ] | Check if any RPC has expired and remove it from the in flight list . |
22,279 | def settings_directory ( ) : system = platform . system ( ) basedir = None if system == 'Windows' : if 'APPDATA' in os . environ : basedir = os . environ [ 'APPDATA' ] if basedir is None : basedir = os . path . expanduser ( '~' ) basedir = os . path . join ( basedir , '.config' ) settings_dir = os . path . abspath ( os... | Find a per user settings directory that is appropriate for each type of system that we are installed on . |
22,280 | def generate ( env ) : global GhostscriptAction try : if GhostscriptAction is None : GhostscriptAction = SCons . Action . Action ( '$GSCOM' , '$GSCOMSTR' ) from SCons . Tool import pdf pdf . generate ( env ) bld = env [ 'BUILDERS' ] [ 'PDF' ] bld . add_action ( '.ps' , GhostscriptAction ) except ImportError as e : pass... | Add Builders and construction variables for Ghostscript to an Environment . |
22,281 | def resource_path ( relative_path = None , expect = None ) : if expect not in ( None , 'file' , 'folder' ) : raise ArgumentError ( "Invalid expect parameter, must be None, 'file' or 'folder'" , expect = expect ) this_dir = os . path . dirname ( __file__ ) _resource_path = os . path . join ( this_dir , '..' , 'config' )... | Return the absolute path to a resource in iotile - build . |
22,282 | def unpack ( fmt , arg ) : if isinstance ( arg , bytearray ) and not ( sys . version_info >= ( 2 , 7 , 5 ) ) : return struct . unpack ( fmt , str ( arg ) ) return struct . unpack ( fmt , arg ) | A shim around struct . unpack to allow it to work on python 2 . 7 . 3 . |
22,283 | async def initialize ( self , timeout = 2.0 ) : if self . initialized . is_set ( ) : raise InternalError ( "initialize called when already initialized" ) self . _emulator . add_task ( 8 , self . _reset_vector ( ) ) await asyncio . wait_for ( self . initialized . wait ( ) , timeout = timeout ) | Launch any background tasks associated with this subsystem . |
22,284 | def _check_registry_type ( folder = None ) : folder = _registry_folder ( folder ) default_file = os . path . join ( folder , 'registry_type.txt' ) try : with open ( default_file , "r" ) as infile : data = infile . read ( ) data = data . strip ( ) ComponentRegistry . SetBackingStore ( data ) except IOError : pass | Check if the user has placed a registry_type . txt file to choose the registry type |
22,285 | def _ensure_package_loaded ( path , component ) : logger = logging . getLogger ( __name__ ) packages = component . find_products ( 'support_package' ) if len ( packages ) == 0 : return None elif len ( packages ) > 1 : raise ExternalError ( "Component had multiple products declared as 'support_package" , products = pack... | Ensure that the given module is loaded as a submodule . |
22,286 | def _try_load_module ( path , import_name = None ) : logger = logging . getLogger ( __name__ ) obj_name = None if len ( path ) > 2 and ':' in path [ 2 : ] : path , _ , obj_name = path . rpartition ( ":" ) folder , basename = os . path . split ( path ) if folder == '' : folder = './' if basename == '' or not os . path .... | Try to programmatically load a python module by path . |
22,287 | def frozen ( self ) : frozen_path = os . path . join ( _registry_folder ( ) , 'frozen_extensions.json' ) return os . path . isfile ( frozen_path ) | Return whether we have a cached list of all installed entry_points . |
22,288 | def kvstore ( self ) : if self . _kvstore is None : self . _kvstore = self . BackingType ( self . BackingFileName , respect_venv = True ) return self . _kvstore | Lazily load the underlying key - value store backing this registry . |
22,289 | def plugins ( self ) : if self . _plugins is None : self . _plugins = { } for _ , plugin in self . load_extensions ( 'iotile.plugin' ) : links = plugin ( ) for name , value in links : self . _plugins [ name ] = value return self . _plugins | Lazily load iotile plugins only on demand . |
22,290 | def load_extensions ( self , group , name_filter = None , comp_filter = None , class_filter = None , product_name = None , unique = False ) : found_extensions = [ ] if product_name is not None : for comp in self . iter_components ( ) : if comp_filter is not None and comp . name != comp_filter : continue products = comp... | Dynamically load and return extension objects of a given type . |
22,291 | def register_extension ( self , group , name , extension ) : if isinstance ( extension , str ) : name , extension = self . load_extension ( extension ) [ 0 ] if group not in self . _registered_extensions : self . _registered_extensions [ group ] = [ ] self . _registered_extensions [ group ] . append ( ( name , extensio... | Register an extension . |
22,292 | def clear_extensions ( self , group = None ) : if group is None : ComponentRegistry . _registered_extensions = { } return if group in self . _registered_extensions : self . _registered_extensions [ group ] = [ ] | Clear all previously registered extensions . |
22,293 | def freeze_extensions ( self ) : output_path = os . path . join ( _registry_folder ( ) , 'frozen_extensions.json' ) with open ( output_path , "w" ) as outfile : json . dump ( self . _dump_extensions ( ) , outfile ) | Freeze the set of extensions into a single file . |
22,294 | def unfreeze_extensions ( self ) : output_path = os . path . join ( _registry_folder ( ) , 'frozen_extensions.json' ) if not os . path . isfile ( output_path ) : raise ExternalError ( "There is no frozen extension list" ) os . remove ( output_path ) ComponentRegistry . _frozen_extensions = None | Remove a previously frozen list of extensions . |
22,295 | def load_extension ( self , path , name_filter = None , class_filter = None , unique = False , component = None ) : import_name = None if component is not None : import_name = _ensure_package_loaded ( path , component ) name , ext = _try_load_module ( path , import_name = import_name ) if name_filter is not None and na... | Load a single python module extension . |
22,296 | def _filter_nonextensions ( cls , obj ) : if hasattr ( obj , '__dict__' ) and obj . __dict__ . get ( '__NO_EXTENSION__' , False ) is True : return False return True | Remove all classes marked as not extensions . |
22,297 | def SetBackingStore ( cls , backing ) : if backing not in [ 'json' , 'sqlite' , 'memory' ] : raise ArgumentError ( "Unknown backing store type that is not json or sqlite" , backing = backing ) if backing == 'json' : cls . BackingType = JSONKVStore cls . BackingFileName = 'component_registry.json' elif backing == 'memor... | Set the global backing type used by the ComponentRegistry from this point forward |
22,298 | def add_component ( self , component , temporary = False ) : tile = IOTile ( component ) value = os . path . normpath ( os . path . abspath ( component ) ) if temporary is True : self . _component_overlays [ tile . name ] = value else : self . kvstore . set ( tile . name , value ) | Register a component with ComponentRegistry . |
22,299 | def list_plugins ( self ) : vals = self . plugins . items ( ) return { x : y for x , y in vals } | List all of the plugins that have been registerd for the iotile program on this computer |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.