Logo Search packages:      
Sourcecode: samba-gtk version File versions  Download package

def sambagtk::pygwregedit::WinRegPipeManager::ls_key (   self,
  key,
  regedit_window = None,
  progress_bar = True,
  confirm = True 
)
this function gets a list of values and subkeys
NOTE: this function will acquire the pipe manager lock and gdk lock on its own. Do Not Acquire Either Lock Before Calling This Function!
\tThis means you can NOT call this function from the main thread with the regedit_window argument or you will have a deadlock. Calling without the regedit_window argument is fine.

returns (subkey_list, value_list)

Definition at line 58 of file pygwregedit.py.

                                                                               :
        """this function gets a list of values and subkeys
        NOTE: this function will acquire the pipe manager lock and gdk lock on its own. Do Not Acquire Either Lock Before Calling This Function!
        \tThis means you can NOT call this function from the main thread with the regedit_window argument or you will have a deadlock. Calling without the regedit_window argument is fine.
        
        returns (subkey_list, value_list)"""
        subkey_list = []
        value_list = []
        
        update_GUI = (regedit_window != None)
        
        self.lock.acquire()
        try: #this can cause access denied errors
            path_handles = self.open_path(key)
        except Exception as ex:
            raise ex
        finally:
            self.lock.release()
        
        key_handle = path_handles[-1]
        blank_buff = WinRegPipeManager.winreg_string_buf("")
        
        if (update_GUI and progress_bar):
            num_subkeys = 4800.0 #backup value
            self.lock.acquire()
            try:
                num_subkeys = float(self.pipe.QueryInfoKey(key_handle, WinRegPipeManager.winreg_string(""))[1])
            except RuntimeError as re:
                print "Failed to fetch key information for %s: %s." % (key.get_absolute_path(), re.args[1])
            finally:
                self.lock.release()

        index = 0
        while True: #get a list of subkeys
            try:
                self.lock.acquire()
                (subkey_name, subkey_class, subkey_changed_time) = self.pipe.EnumKey(key_handle, 
                                                                                     index, 
                                                                                     blank_buff, 
                                                                                     blank_buff, 
                                                                                     None
                                                                                     )
                self.lock.release() #we want to release the pipe lock before grabbing the gdk lock or else we might cause a deadlock!
                
                subkey = RegistryKey(subkey_name.name, key)
                subkey_list.append(subkey)
                
                if (update_GUI):
                    gtk.gdk.threads_enter()
                    regedit_window.set_status("Fetching key: %s" % (subkey_name.name))
                    if (progress_bar):
                        if (index < num_subkeys): #the value of total was a guess so this may cause a GtkWarning for setting fraction to a value above 1.0
                            regedit_window.progressbar.set_fraction(index/num_subkeys) 
                            regedit_window.progressbar.show() #other threads calling ls_key() may finish and hide the progress bar.
                    gtk.gdk.threads_leave()
                
                index += 1

            except RuntimeError as re:
                self.lock.release()
                if (re.args[0] == 0x103): #0x103 is WERR_NO_MORE_ITEMS, so we're done
                    if (update_GUI and progress_bar):
                        gtk.gdk.threads_enter()
                        regedit_window.progressbar.hide()
                        gtk.gdk.threads_leave()
                    break
                else:
                    raise re

        index = 0
        while True: #get a list of values for the key
            try:
                self.lock.acquire()
                (value_name, value_type, value_data, value_length) = self.pipe.EnumValue(key_handle,
                                                                                         index, 
                                                                                         WinRegPipeManager.winreg_val_name_buf(""), 
                                                                                         0, 
                                                                                         [], 
                                                                                         8192
                                                                                         )
                self.lock.release()
                
                value = RegistryValue(value_name.name, value_type, value_data, key)
                value_list.append(value)
                
                #there's no need to update GUI here since there's usually few Values. 
                #Additionally, many values are named "" which is later changed to "(Default)". 
                #So printing '"fetching: "+value.name' might look like a glitch to the user.
                
                index += 1

            except RuntimeError as re:
                self.lock.release()
                if (re.args[0] == 0x103): #0x103 is WERR_NO_MORE_ITEMS
                    break
                else:
                    raise re

        self.lock.acquire()
        try:
            self.close_path(path_handles)
        finally:
            self.lock.release()
        
        default_value_list = [value for value in value_list if value.name == ""]
        if (len(default_value_list) == 0):
            value = RegistryValue("(Default)", misc.REG_SZ, [], key)
            value_list.append(value)
        else:
            default_value_list[0].name = "(Default)"
        
        if (update_GUI and confirm):
            gtk.gdk.threads_enter()
            regedit_window.set_status("Successfully fetched keys and values of %s." % (key.name))
            gtk.gdk.threads_leave()
            
#        #The reference count to Py_None is still not right: It climbs to infinity!
#        print "Finish ls_key()", sys.getrefcount(None)
        return (subkey_list, value_list)
    

Generated by  Doxygen 1.6.0   Back to index