idx int64 0 252k | question stringlengths 48 5.28k | target stringlengths 5 1.23k |
|---|---|---|
244,100 | def get_width ( ) : ws = struct . pack ( "HHHH" , 0 , 0 , 0 , 0 ) ws = fcntl . ioctl ( sys . stdout . fileno ( ) , termios . TIOCGWINSZ , ws ) lines , columns , x , y = struct . unpack ( "HHHH" , ws ) width = min ( columns * 39 // 40 , columns - 2 ) return width | Get terminal width |
244,101 | def groff2man ( data ) : width = get_width ( ) cmd = 'groff -t -Tascii -m man -rLL=%dn -rLT=%dn' % ( width , width ) handle = subprocess . Popen ( cmd , shell = True , stdin = subprocess . PIPE , stdout = subprocess . PIPE , stderr = subprocess . PIPE ) man_text , stderr = handle . communicate ( data ) return man_text | Read groff - formatted text and output man pages . |
244,102 | def extract_name ( self , data ) : name = re . search ( '<h1[^>]*>(.+?)</h1>' , data ) . group ( 1 ) name = re . sub ( r'<([^>]+)>' , r'' , name ) name = re . sub ( r'>' , r'>' , name ) name = re . sub ( r'<' , r'<' , name ) return name | Extract man page name from web page . |
244,103 | def cache_all ( self ) : respond = input ( 'By default, cppman fetches pages on-the-fly if corresponding ' 'page is not found in the cache. The "cache-all" option is only ' 'useful if you want to view man pages offline. ' 'Caching all contents will take several minutes, ' 'do you want to continue [y/N]? ' ) if not ( re... | Cache all available man pages |
244,104 | def cache_man_page ( self , source , url , name ) : outname = self . get_page_path ( source , name ) if os . path . exists ( outname ) and not self . forced : return try : os . makedirs ( os . path . join ( environ . cache_dir , source ) ) except OSError : pass data = util . fixupHTML ( urllib . request . urlopen ( url... | callback to cache new man page |
244,105 | def man ( self , pattern ) : try : avail = os . listdir ( os . path . join ( environ . cache_dir , environ . source ) ) except OSError : avail = [ ] if not os . path . exists ( environ . index_db ) : raise RuntimeError ( "can't find index.db" ) conn = sqlite3 . connect ( environ . index_db ) cursor = conn . cursor ( ) ... | Call viewer . sh to view man page |
244,106 | def find ( self , pattern ) : if not os . path . exists ( environ . index_db ) : raise RuntimeError ( "can't find index.db" ) conn = sqlite3 . connect ( environ . index_db ) cursor = conn . cursor ( ) selected = cursor . execute ( 'SELECT * FROM "%s" WHERE name ' 'LIKE "%%%s%%" ORDER BY LENGTH(name)' % ( environ . sour... | Find pages in database . |
244,107 | def update_mandb ( self , quiet = True ) : if not environ . config . UpdateManPath : return print ( '\nrunning mandb...' ) cmd = 'mandb %s' % ( ' -q' if quiet else '' ) subprocess . Popen ( cmd , shell = True ) . wait ( ) | Update mandb . |
244,108 | def set_default ( self ) : try : os . makedirs ( os . path . dirname ( self . _configfile ) ) except : pass self . _config = configparser . RawConfigParser ( ) self . _config . add_section ( 'Settings' ) for key , val in self . DEFAULTS . items ( ) : self . _config . set ( 'Settings' , key , val ) with open ( self . _c... | Set config to default . |
244,109 | def save ( self ) : try : os . makedirs ( os . path . dirname ( self . _configfile ) ) except : pass with open ( self . _configfile , 'w' ) as f : self . _config . write ( f ) | Store config back to file . |
244,110 | def get_free_gpus ( max_procs = 0 ) : logger = logging . getLogger ( __name__ ) try : py3nvml . nvmlInit ( ) except : str_ = warnings . warn ( str_ , RuntimeWarning ) logger . warn ( str_ ) return [ ] num_gpus = py3nvml . nvmlDeviceGetCount ( ) gpu_free = [ False ] * num_gpus for i in range ( num_gpus ) : try : h = py3... | Checks the number of processes running on your GPUs . |
244,111 | def get_num_procs ( ) : logger = logging . getLogger ( __name__ ) try : py3nvml . nvmlInit ( ) except : str_ = warnings . warn ( str_ , RuntimeWarning ) logger . warn ( str_ ) return [ ] num_gpus = py3nvml . nvmlDeviceGetCount ( ) gpu_procs = [ - 1 ] * num_gpus for i in range ( num_gpus ) : try : h = py3nvml . nvmlDevi... | Gets the number of processes running on each gpu |
244,112 | def _extractNVMLErrorsAsClasses ( ) : this_module = sys . modules [ __name__ ] nvmlErrorsNames = [ x for x in dir ( this_module ) if x . startswith ( "NVML_ERROR_" ) ] for err_name in nvmlErrorsNames : class_name = "NVMLError_" + string . capwords ( err_name . replace ( "NVML_ERROR_" , "" ) , "_" ) . replace ( "_" , ""... | Generates a hierarchy of classes on top of NVMLError class . |
244,113 | def _LoadNvmlLibrary ( ) : global nvmlLib if ( nvmlLib is None ) : libLoadLock . acquire ( ) try : if ( nvmlLib is None ) : try : if ( sys . platform [ : 3 ] == "win" ) : searchPaths = [ os . path . join ( os . getenv ( "ProgramFiles" , r"C:\Program Files" ) , r"NVIDIA Corporation\NVSMI\nvml.dll" ) , os . path . join (... | Load the library if it isn t loaded already |
244,114 | def encode_notifications ( tokens , notifications ) : fmt = "!BH32sH%ds" structify = lambda t , p : struct . pack ( fmt % len ( p ) , 0 , 32 , t , len ( p ) , p ) binaryify = lambda t : t . decode ( 'hex' ) if type ( notifications ) is dict and type ( tokens ) in ( str , unicode ) : tokens , notifications = ( [ tokens ... | Returns the encoded bytes of tokens and notifications tokens a list of tokens or a string of only one token notifications a list of notifications or a dictionary of only one |
244,115 | def write ( self , notifications ) : "Connect to the APNS service and send notifications" if not self . factory : log . msg ( 'APNSService write (connecting)' ) server , port = ( ( APNS_SERVER_SANDBOX_HOSTNAME if self . environment == 'sandbox' else APNS_SERVER_HOSTNAME ) , APNS_SERVER_PORT ) self . factory = self . cl... | Connect to the APNS service and send notifications |
244,116 | def read ( self ) : "Connect to the feedback service and read all data." log . msg ( 'APNSService read (connecting)' ) try : server , port = ( ( FEEDBACK_SERVER_SANDBOX_HOSTNAME if self . environment == 'sandbox' else FEEDBACK_SERVER_HOSTNAME ) , FEEDBACK_SERVER_PORT ) factory = self . feedbackProtocolFactory ( ) conte... | Connect to the feedback service and read all data . |
244,117 | def reprovision_and_retry ( func ) : @ functools . wraps ( func ) def wrapper ( * a , ** kw ) : errback = kw . get ( 'errback' , None ) if errback is None : def errback ( e ) : raise e def errback_wrapper ( e ) : if isinstance ( e , UnknownAppID ) and 'INITIAL' in OPTIONS : try : for initial in OPTIONS [ 'INITIAL' ] : ... | Wraps the errback callback of the API functions automatically trying to re - provision if the app ID can not be found during the operation . If that s unsuccessful it will raise the UnknownAppID error . |
244,118 | def pop ( self ) : char = self . code [ self . index ] self . index += 1 return char | removes the current character then moves to the next one returning the current character |
244,119 | def characters ( self , numberOfCharacters ) : return self . code [ self . index : self . index + numberOfCharacters ] | Returns characters at index + number of characters |
244,120 | def next_content ( self , start , amount = 1 ) : while start < len ( self . code ) and self . code [ start ] in ( ' ' , '\t' , '\n' ) : start += 1 return self . code [ start : start + amount ] | Returns the next non - whitespace characters |
244,121 | def prev_content ( self , start , amount = 1 ) : while start > 0 and self . code [ start ] in ( ' ' , '\t' , '\n' ) : start -= 1 return self . code [ ( start or amount ) - amount : start ] | Returns the prev non - whitespace characters |
244,122 | def parse_mapping ( mapping_file : Optional [ str ] ) -> configparser . ConfigParser : LOGGER . debug ( 'Parsing mapping file. Command line: %s' , mapping_file ) def parse ( mapping_file ) : config = configparser . ConfigParser ( ) config . read_file ( mapping_file ) return config if mapping_file is not None : LOGGER .... | Parse the file containing the mappings from hosts to pass entries . |
244,123 | def parse_request ( ) -> Dict [ str , str ] : in_lines = sys . stdin . readlines ( ) LOGGER . debug ( 'Received request "%s"' , in_lines ) request = { } for line in in_lines : if not line . strip ( ) : continue parts = line . split ( '=' , 1 ) assert len ( parts ) == 2 request [ parts [ 0 ] . strip ( ) ] = parts [ 1 ] ... | Parse the request of the git credential API from stdin . |
244,124 | def get_password ( request , mapping ) -> None : LOGGER . debug ( 'Received request "%s"' , request ) if 'host' not in request : LOGGER . error ( 'host= entry missing in request. ' 'Cannot query without a host' ) return host = request [ 'host' ] if 'path' in request : host = '/' . join ( [ host , request [ 'path' ] ] )... | Resolve the given credential request in the provided mapping definition . |
244,125 | def main ( argv : Optional [ Sequence [ str ] ] = None ) -> None : args = parse_arguments ( argv = argv ) if args . logging : logging . basicConfig ( level = logging . DEBUG ) handle_skip ( ) action = args . action request = parse_request ( ) LOGGER . debug ( 'Received action %s with request:\n%s' , action , request ) ... | Start the pass - git - helper script . |
244,126 | def configure ( self , config ) : self . _prefix_length = config . getint ( 'skip{suffix}' . format ( suffix = self . _option_suffix ) , fallback = self . _prefix_length ) | Configure the amount of characters to skip . |
244,127 | def insert_metric_changes ( db , metrics , metric_mapping , commit ) : values = [ [ commit . sha , metric_mapping [ metric . name ] , metric . value ] for metric in metrics if metric . value != 0 ] db . executemany ( 'INSERT INTO metric_changes (sha, metric_id, value) VALUES (?, ?, ?)' , values , ) | Insert into the metric_changes tables . |
244,128 | def get_commits ( self , since_sha = None ) : assert self . tempdir cmd = [ 'git' , 'log' , '--first-parent' , '--reverse' , COMMIT_FORMAT ] if since_sha : commits = [ self . get_commit ( since_sha ) ] cmd . append ( '{}..HEAD' . format ( since_sha ) ) else : commits = [ ] cmd . append ( 'HEAD' ) output = cmd_output ( ... | Returns a list of Commit objects . |
244,129 | def discover ( package , cls_match_func ) : matched_classes = set ( ) for _ , module_name , _ in pkgutil . walk_packages ( package . __path__ , prefix = package . __name__ + '.' , ) : module = __import__ ( module_name , fromlist = [ str ( '__trash' ) ] , level = 0 ) for _ , imported_class in inspect . getmembers ( modu... | Returns a set of classes in the directory matched by cls_match_func |
244,130 | def chunk_iter ( iterable , n ) : assert n > 0 iterable = iter ( iterable ) chunk = tuple ( itertools . islice ( iterable , n ) ) while chunk : yield chunk chunk = tuple ( itertools . islice ( iterable , n ) ) | Yields an iterator in chunks |
244,131 | def get_metric_parsers ( metric_packages = tuple ( ) , include_defaults = True ) : metric_parsers = set ( ) if include_defaults : import git_code_debt . metrics metric_parsers . update ( discover ( git_code_debt . metrics , is_metric_cls ) ) for metric_package in metric_packages : metric_parsers . update ( discover ( m... | Gets all of the metric parsers . |
244,132 | def timeago_template ( locale , index , ago_in ) : try : LOCALE = __import__ ( 'timeago.locales.' + locale ) LOCALE = locale_module ( LOCALE , locale ) except : locale = setting . DEFAULT_LOCALE LOCALE = __import__ ( 'timeago.locales.' + locale ) LOCALE = locale_module ( LOCALE , locale ) if isinstance ( LOCALE , list ... | simple locale implement |
244,133 | def parse ( input ) : if isinstance ( input , datetime ) : return input if isinstance ( input , date ) : return date_to_datetime ( input ) if isinstance ( input , time ) : return time_to_datetime ( input ) if isinstance ( input , ( int , float ) ) : return timestamp_to_datetime ( input ) if isinstance ( input , ( str )... | parse input to datetime |
244,134 | def format ( date , now = None , locale = 'en' ) : if not isinstance ( date , timedelta ) : if now is None : now = datetime . now ( ) date = parser . parse ( date ) now = parser . parse ( now ) if date is None : raise ParameterUnvalid ( 'the parameter `date` should be datetime ' '/ timedelta, or datetime formated strin... | the entry method |
244,135 | def _is_parent_of ( parent , child ) : if child . is_partition : return child . partition_slave == parent if child . is_toplevel : return child . drive == parent and child != parent return False | Check whether the first device is the parent of the second device . |
244,136 | def prune_empty_node ( node , seen ) : if node . methods : return False if id ( node ) in seen : return True seen = seen | { id ( node ) } for branch in list ( node . branches ) : if prune_empty_node ( branch , seen ) : node . branches . remove ( branch ) else : return False return True | Recursively remove empty branches and return whether this makes the node itself empty . |
244,137 | async def browse ( self , device ) : device = self . _find_device ( device ) if not device . is_mounted : self . _log . error ( _ ( "not browsing {0}: not mounted" , device ) ) return False if not self . _browser : self . _log . error ( _ ( "not browsing {0}: no program" , device ) ) return False self . _log . debug ( ... | Launch file manager on the mount path of the specified device . |
244,138 | async def terminal ( self , device ) : device = self . _find_device ( device ) if not device . is_mounted : self . _log . error ( _ ( "not opening terminal {0}: not mounted" , device ) ) return False if not self . _terminal : self . _log . error ( _ ( "not opening terminal {0}: no program" , device ) ) return False sel... | Launch terminal on the mount path of the specified device . |
244,139 | async def mount ( self , device ) : device = self . _find_device ( device ) if not self . is_handleable ( device ) or not device . is_filesystem : self . _log . warn ( _ ( 'not mounting {0}: unhandled device' , device ) ) return False if device . is_mounted : self . _log . info ( _ ( 'not mounting {0}: already mounted'... | Mount the device if not already mounted . |
244,140 | async def unmount ( self , device ) : device = self . _find_device ( device ) if not self . is_handleable ( device ) or not device . is_filesystem : self . _log . warn ( _ ( 'not unmounting {0}: unhandled device' , device ) ) return False if not device . is_mounted : self . _log . info ( _ ( 'not unmounting {0}: not mo... | Unmount a Device if mounted . |
244,141 | async def unlock ( self , device ) : device = self . _find_device ( device ) if not self . is_handleable ( device ) or not device . is_crypto : self . _log . warn ( _ ( 'not unlocking {0}: unhandled device' , device ) ) return False if device . is_unlocked : self . _log . info ( _ ( 'not unlocking {0}: already unlocked... | Unlock the device if not already unlocked . |
244,142 | async def lock ( self , device ) : device = self . _find_device ( device ) if not self . is_handleable ( device ) or not device . is_crypto : self . _log . warn ( _ ( 'not locking {0}: unhandled device' , device ) ) return False if not device . is_unlocked : self . _log . info ( _ ( 'not locking {0}: not unlocked' , de... | Lock device if unlocked . |
244,143 | async def add ( self , device , recursive = None ) : device , created = await self . _find_device_losetup ( device ) if created and recursive is False : return device if device . is_filesystem : success = await self . mount ( device ) elif device . is_crypto : success = await self . unlock ( device ) if success and rec... | Mount or unlock the device depending on its type . |
244,144 | async def auto_add ( self , device , recursive = None , automount = True ) : device , created = await self . _find_device_losetup ( device ) if created and recursive is False : return device if device . is_luks_cleartext and self . udisks . version_info >= ( 2 , 7 , 0 ) : await sleep ( 1.5 ) success = True if not self ... | Automatically attempt to mount or unlock a device but be quiet if the device is not supported . |
244,145 | async def remove ( self , device , force = False , detach = False , eject = False , lock = False ) : device = self . _find_device ( device ) if device . is_filesystem : if device . is_mounted or not device . is_loop or detach is False : success = await self . unmount ( device ) elif device . is_crypto : if force and de... | Unmount or lock the device depending on device type . |
244,146 | async def eject ( self , device , force = False ) : device = self . _find_device ( device ) if not self . is_handleable ( device ) : self . _log . warn ( _ ( 'not ejecting {0}: unhandled device' ) ) return False drive = device . drive if not ( drive . is_drive and drive . is_ejectable ) : self . _log . warn ( _ ( 'not ... | Eject a device after unmounting all its mounted filesystems . |
244,147 | async def detach ( self , device , force = False ) : device = self . _find_device ( device ) if not self . is_handleable ( device ) : self . _log . warn ( _ ( 'not detaching {0}: unhandled device' , device ) ) return False drive = device . root if not drive . is_detachable : self . _log . warn ( _ ( 'not detaching {0}:... | Detach a device after unmounting all its mounted filesystems . |
244,148 | async def add_all ( self , recursive = False ) : tasks = [ self . auto_add ( device , recursive = recursive ) for device in self . get_all_handleable_leaves ( ) ] results = await gather ( * tasks ) success = all ( results ) return success | Add all handleable devices that available at start . |
244,149 | async def remove_all ( self , detach = False , eject = False , lock = False ) : kw = dict ( force = True , detach = detach , eject = eject , lock = lock ) tasks = [ self . auto_remove ( device , ** kw ) for device in self . get_all_handleable_roots ( ) ] results = await gather ( * tasks ) success = all ( results ) retu... | Remove all filesystems handleable by udiskie . |
244,150 | async def losetup ( self , image , read_only = True , offset = None , size = None , no_part_scan = None ) : try : device = self . udisks . find ( image ) except FileNotFoundError : pass else : self . _log . info ( _ ( 'not setting up {0}: already up' , device ) ) return device if not os . path . isfile ( image ) : self... | Setup a loop device . |
244,151 | async def delete ( self , device , remove = True ) : device = self . _find_device ( device ) if not self . is_handleable ( device ) or not device . is_loop : self . _log . warn ( _ ( 'not deleting {0}: unhandled device' , device ) ) return False if remove : await self . auto_remove ( device , force = True ) self . _log... | Detach the loop device . |
244,152 | def is_handleable ( self , device ) : ignored = self . _ignore_device ( device ) if ignored is None and device is not None : return self . is_handleable ( _get_parent ( device ) ) return not ignored | Check whether this device should be handled by udiskie . |
244,153 | def is_addable ( self , device , automount = True ) : if not self . is_automount ( device , automount ) : return False if device . is_filesystem : return not device . is_mounted if device . is_crypto : return self . _prompt and not device . is_unlocked if device . is_partition_table : return any ( self . is_addable ( d... | Check if device can be added with auto_add . |
244,154 | def is_removable ( self , device ) : if not self . is_handleable ( device ) : return False if device . is_filesystem : return device . is_mounted if device . is_crypto : return device . is_unlocked if device . is_partition_table or device . is_drive : return any ( self . is_removable ( dev ) for dev in self . get_all_h... | Check if device can be removed with auto_remove . |
244,155 | def get_all_handleable ( self ) : nodes = self . get_device_tree ( ) return [ node . device for node in sorted ( nodes . values ( ) , key = DevNode . _sort_key ) if not node . ignored and node . device ] | Get list of all known handleable devices . |
244,156 | def get_all_handleable_roots ( self ) : nodes = self . get_device_tree ( ) return [ node . device for node in sorted ( nodes . values ( ) , key = DevNode . _sort_key ) if not node . ignored and node . device and ( node . root == '/' or nodes [ node . root ] . ignored ) ] | Get list of all handleable devices return only those that represent root nodes within the filtered device tree . |
244,157 | def get_all_handleable_leaves ( self ) : nodes = self . get_device_tree ( ) return [ node . device for node in sorted ( nodes . values ( ) , key = DevNode . _sort_key ) if not node . ignored and node . device and all ( child . ignored for child in node . children ) ] | Get list of all handleable devices return only those that represent leaf nodes within the filtered device tree . |
244,158 | def get_device_tree ( self ) : root = DevNode ( None , None , [ ] , None ) device_nodes = { dev . object_path : DevNode ( dev , dev . parent_object_path , [ ] , self . _ignore_device ( dev ) ) for dev in self . udisks } for node in device_nodes . values ( ) : device_nodes . get ( node . root , root ) . children . appen... | Get a tree of all devices . |
244,159 | def detect ( self , root_device = '/' ) : root = Device ( None , [ ] , None , "" , [ ] ) device_nodes = dict ( map ( self . _device_node , self . _mounter . get_all_handleable ( ) ) ) for node in device_nodes . values ( ) : device_nodes . get ( node . root , root ) . branches . append ( node ) device_nodes [ '/' ] = ro... | Detect all currently known devices . |
244,160 | def _get_device_methods ( self , device ) : if device . is_filesystem : if device . is_mounted : if self . _mounter . _browser : yield 'browse' if self . _mounter . _terminal : yield 'terminal' yield 'unmount' else : yield 'mount' elif device . is_crypto : if device . is_unlocked : yield 'lock' else : yield 'unlock' ca... | Return an iterable over all available methods the device has . |
244,161 | def _device_node ( self , device ) : label = device . ui_label dev_label = device . ui_device_label methods = [ Action ( method , device , self . _labels [ method ] . format ( label , dev_label ) , partial ( self . _actions [ method ] , device ) ) for method in self . _get_device_methods ( device ) ] root = device . pa... | Create an empty menu node for the specified device . |
244,162 | def samefile ( a : str , b : str ) -> bool : try : return os . path . samefile ( a , b ) except OSError : return os . path . normpath ( a ) == os . path . normpath ( b ) | Check if two pathes represent the same file . |
244,163 | def sameuuid ( a : str , b : str ) -> bool : return a and b and a . lower ( ) == b . lower ( ) | Compare two UUIDs . |
244,164 | def extend ( a : dict , b : dict ) -> dict : res = a . copy ( ) res . update ( b ) return res | Merge two dicts and return a new dict . Much like subclassing works . |
244,165 | def decode_ay ( ay ) : if ay is None : return '' elif isinstance ( ay , str ) : return ay elif isinstance ( ay , bytes ) : return ay . decode ( 'utf-8' ) else : return bytearray ( ay ) . rstrip ( bytearray ( ( 0 , ) ) ) . decode ( 'utf-8' ) | Convert binary blob from DBus queries to strings . |
244,166 | def format_exc ( * exc_info ) : typ , exc , tb = exc_info or sys . exc_info ( ) error = traceback . format_exception ( typ , exc , tb ) return "" . join ( error ) | Show exception with traceback . |
244,167 | def trigger ( self , event , * args ) : for handler in self . _event_handlers [ event ] : handler ( * args ) | Trigger event by name . |
244,168 | def _check ( self , args ) : if sum ( bool ( args [ arg ] ) for arg in self . _mapping ) > 1 : raise DocoptExit ( _ ( 'These options are mutually exclusive: {0}' , ', ' . join ( self . _mapping ) ) ) | Exit in case of multiple exclusive arguments . |
244,169 | def program_options ( self , args ) : options = { } for name , rule in self . option_rules . items ( ) : val = rule ( args ) if val is not None : options [ name ] = val return options | Get program options from docopt parsed options . |
244,170 | def run ( self ) : self . exit_code = 1 self . mainloop = GLib . MainLoop ( ) try : future = ensure_future ( self . _start_async_tasks ( ) ) future . callbacks . append ( self . set_exit_code ) self . mainloop . run ( ) return self . exit_code except KeyboardInterrupt : return 1 | Run the main loop . Returns exit code . |
244,171 | async def _start_async_tasks ( self ) : try : self . udisks = await udiskie . udisks2 . Daemon . create ( ) results = await self . _init ( ) return 0 if all ( results ) else 1 except Exception : traceback . print_exc ( ) return 1 finally : self . mainloop . quit ( ) | Start asynchronous operations . |
244,172 | def device_changed ( self , old_state , new_state ) : if ( self . _mounter . is_addable ( new_state ) and not self . _mounter . is_addable ( old_state ) and not self . _mounter . is_removable ( old_state ) ) : self . auto_add ( new_state ) | Mount newly mountable devices . |
244,173 | async def connect_service ( bus_name , object_path , interface ) : proxy = await proxy_new_for_bus ( Gio . BusType . SYSTEM , Gio . DBusProxyFlags . DO_NOT_LOAD_PROPERTIES | Gio . DBusProxyFlags . DO_NOT_CONNECT_SIGNALS , info = None , name = bus_name , object_path = object_path , interface_name = interface , ) return ... | Connect to the service object on DBus return InterfaceProxy . |
244,174 | def object ( self ) : proxy = self . _proxy return ObjectProxy ( proxy . get_connection ( ) , proxy . get_name ( ) , proxy . get_object_path ( ) ) | Get an ObjectProxy instanec for the underlying object . |
244,175 | def connect ( self , interface , event , object_path , handler ) : if object_path : def callback ( connection , sender_name , object_path , interface_name , signal_name , parameters ) : return handler ( * unpack_variant ( parameters ) ) else : def callback ( connection , sender_name , object_path , interface_name , sig... | Connect to a DBus signal . If object_path is None subscribe for all objects and invoke the callback with the object_path as its first argument . |
244,176 | def require_Gtk ( min_version = 2 ) : if not _in_X : raise RuntimeError ( 'Not in X session.' ) if _has_Gtk < min_version : raise RuntimeError ( 'Module gi.repository.Gtk not available!' ) if _has_Gtk == 2 : logging . getLogger ( __name__ ) . warn ( _ ( "Missing runtime dependency GTK 3. Falling back to GTK 2 " "for pa... | Make sure Gtk is properly initialized . |
244,177 | def _ ( text , * args , ** kwargs ) : msg = _t . gettext ( text ) if args or kwargs : return msg . format ( * args , ** kwargs ) else : return msg | Translate and then and format the text with str . format . |
244,178 | def filter_opt ( opt ) : return { k : GLib . Variant ( * v ) for k , v in opt . items ( ) if v [ 1 ] is not None } | Remove None values from a dictionary . |
244,179 | def eject ( self , auth_no_user_interaction = None ) : return self . _assocdrive . _M . Drive . Eject ( '(a{sv})' , filter_opt ( { 'auth.no_user_interaction' : ( 'b' , auth_no_user_interaction ) , } ) ) | Eject media from the device . |
244,180 | def device_id ( self ) : if self . is_block : for filename in self . _P . Block . Symlinks : parts = decode_ay ( filename ) . split ( '/' ) if parts [ - 2 ] == 'by-id' : return parts [ - 1 ] elif self . is_drive : return self . _assocdrive . _P . Drive . Id return '' | Return a unique and persistent identifier for the device . |
244,181 | def is_external ( self ) : if self . _P . Block . HintSystem == False : return True if self . is_luks_cleartext and self . luks_cleartext_slave . is_external : return True if self . is_partition and self . partition_slave . is_external : return True return False | Check if the device is external . |
244,182 | def drive ( self ) : if self . is_drive : return self cleartext = self . luks_cleartext_slave if cleartext : return cleartext . drive if self . is_block : return self . _daemon [ self . _P . Block . Drive ] return None | Get wrapper to the drive containing this device . |
244,183 | def root ( self ) : drive = self . drive for device in self . _daemon : if device . is_drive : continue if device . is_toplevel and device . drive == drive : return device return None | Get the top level block device in the ancestry of this device . |
244,184 | def symlinks ( self ) : if not self . _P . Block . Symlinks : return [ ] return [ decode_ay ( path ) for path in self . _P . Block . Symlinks ] | Known symlinks of the block device . |
244,185 | def mount ( self , fstype = None , options = None , auth_no_user_interaction = None ) : return self . _M . Filesystem . Mount ( '(a{sv})' , filter_opt ( { 'fstype' : ( 's' , fstype ) , 'options' : ( 's' , ',' . join ( options or [ ] ) ) , 'auth.no_user_interaction' : ( 'b' , auth_no_user_interaction ) , } ) ) | Mount filesystem . |
244,186 | def unmount ( self , force = None , auth_no_user_interaction = None ) : return self . _M . Filesystem . Unmount ( '(a{sv})' , filter_opt ( { 'force' : ( 'b' , force ) , 'auth.no_user_interaction' : ( 'b' , auth_no_user_interaction ) , } ) ) | Unmount filesystem . |
244,187 | def luks_cleartext_holder ( self ) : if not self . is_luks : return None for device in self . _daemon : if device . luks_cleartext_slave == self : return device return None | Get wrapper to the unlocked luks cleartext device . |
244,188 | def unlock ( self , password , auth_no_user_interaction = None ) : return self . _M . Encrypted . Unlock ( '(sa{sv})' , password , filter_opt ( { 'auth.no_user_interaction' : ( 'b' , auth_no_user_interaction ) , } ) ) | Unlock Luks device . |
244,189 | def set_autoclear ( self , value , auth_no_user_interaction = None ) : return self . _M . Loop . SetAutoclear ( '(ba{sv})' , value , filter_opt ( { 'auth.no_user_interaction' : ( 'b' , auth_no_user_interaction ) , } ) ) | Set autoclear flag for loop partition . |
244,190 | def is_file ( self , path ) : return ( samefile ( path , self . device_file ) or samefile ( path , self . loop_file ) or any ( samefile ( path , mp ) for mp in self . mount_paths ) or sameuuid ( path , self . id_uuid ) or sameuuid ( path , self . partition_uuid ) ) | Comparison by mount and device file path . |
244,191 | def in_use ( self ) : if self . is_mounted or self . is_unlocked : return True if self . is_partition_table : for device in self . _daemon : if device . partition_slave == self and device . in_use : return True return False | Check whether this device is in use i . e . mounted or unlocked . |
244,192 | def ui_label ( self ) : return ': ' . join ( filter ( None , [ self . ui_device_presentation , self . ui_id_label or self . ui_id_uuid or self . drive_label ] ) ) | UI string identifying the partition if possible . |
244,193 | def find ( self , path ) : if isinstance ( path , Device ) : return path for device in self : if device . is_file ( path ) : self . _log . debug ( _ ( 'found device owning "{0}": "{1}"' , path , device ) ) return device raise FileNotFoundError ( _ ( 'no device found owning "{0}"' , path ) ) | Get a device proxy by device name or any mount path of the device . |
244,194 | def get ( self , object_path , interfaces_and_properties = None ) : if not interfaces_and_properties : interfaces_and_properties = self . _objects . get ( object_path ) if not interfaces_and_properties : return None property_hub = PropertyHub ( interfaces_and_properties ) method_hub = MethodHub ( self . _proxy . object... | Create a Device instance from object path . |
244,195 | def device_mounted ( self , device ) : if not self . _mounter . is_handleable ( device ) : return browse_action = ( 'browse' , _ ( 'Browse directory' ) , self . _mounter . browse , device ) terminal_action = ( 'terminal' , _ ( 'Open terminal' ) , self . _mounter . terminal , device ) self . _show_notification ( 'device... | Show mount notification for specified device object . |
244,196 | def device_unmounted ( self , device ) : if not self . _mounter . is_handleable ( device ) : return self . _show_notification ( 'device_unmounted' , _ ( 'Device unmounted' ) , _ ( '{0.ui_label} unmounted' , device ) , device . icon_name ) | Show unmount notification for specified device object . |
244,197 | def device_locked ( self , device ) : if not self . _mounter . is_handleable ( device ) : return self . _show_notification ( 'device_locked' , _ ( 'Device locked' ) , _ ( '{0.device_presentation} locked' , device ) , device . icon_name ) | Show lock notification for specified device object . |
244,198 | def device_unlocked ( self , device ) : if not self . _mounter . is_handleable ( device ) : return self . _show_notification ( 'device_unlocked' , _ ( 'Device unlocked' ) , _ ( '{0.device_presentation} unlocked' , device ) , device . icon_name ) | Show unlock notification for specified device object . |
244,199 | def device_added ( self , device ) : if not self . _mounter . is_handleable ( device ) : return if self . _has_actions ( 'device_added' ) : GLib . timeout_add ( 500 , self . _device_added , device ) else : self . _device_added ( device ) | Show discovery notification for specified device object . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.