Changeset 3089

Show
Ignore:
Timestamp:
07/05/08 16:38:36 (5 years ago)
Author:
nopper
Message:

Fixing lock atomic operations

Location:
branch/UmitPlugins/umitPlugin
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • branch/UmitPlugins/umitPlugin/Network.py

    r3001 r3089  
    3636    def proxy(*args, **kwargs): 
    3737        thread = Thread(target=func, args=args, kwargs=kwargs) 
    38         #thread.setDaemon(True) 
     38        thread.setDaemon(True) 
    3939        thread.start() 
    4040        return thread 
     
    158158    data = list() 
    159159    Network.get_url( \ 
    160             "http://localhost/~stack/plugins/systeminfo/SystemInfo-2.0.0.ump", \ 
     160            "http://localhost/~stack/plugins/systeminfo/SystemInfo.ump", \ 
    161161            callback, data) 
    162162 
  • branch/UmitPlugins/umitPlugin/PluginPage.py

    r3087 r3089  
    3232from higwidgets.higrichlists import HIGRichList, PluginRow 
    3333 
    34 from Update import FILE_GETTING 
     34from Update import FILE_GETTING, FILE_CHECKING 
    3535from Update import LATEST_GETTED, LATEST_ERROR, LATEST_GETTING 
    3636 
     
    4040 
    4141        self.p_window = parent 
     42        self.menu_enabled = True 
    4243 
    4344        self.__create_widgets() 
     
    128129        self.install_updates_btn.hide() 
    129130        self.find_updates_btn.show() 
     131 
     132        self.menu_enabled = True 
    130133     
    131134    def __on_install_updates(self, widget): 
     
    170173        for obj in self.p_window.update_eng.list: 
    171174            with obj.lock: 
    172                 if obj.status == FILE_GETTING: 
     175                if obj.status == FILE_GETTING or \ 
     176                   obj.status == FILE_CHECKING: 
    173177                    working = True 
    174178                     
     
    212216 
    213217        self.find_updates_btn.set_sensitive(False) 
     218        self.menu_enabled = False 
    214219         
    215220        lst = [] 
     
    295300                self.populate() 
    296301 
     302                self.menu_enabled = True 
    297303            else: 
    298304                # Now prepare the download page 
     
    330336        "Popup menu" 
    331337 
     338        if not self.menu_enabled: 
     339            return 
     340 
    332341        menu = gtk.Menu() 
    333342 
  • branch/UmitPlugins/umitPlugin/Update.py

    r3087 r3089  
    3131 
    3232from umitPlugin.Network import * 
     33from umitPlugin.Atoms import Version 
    3334 
    3435STATUS_IDLE = 0 
     
    144145     
    145146    def __process_plugin(self, file, data, exc, obj): 
    146         with obj.lock: 
    147             self.__process_plugin_cb(file, data, exc, obj) 
    148  
    149     def __process_plugin_cb(self, file, data, exc, obj): 
    150147        if isinstance(exc, ErrorNetException): 
    151             obj.status = FILE_ERROR 
    152             obj.label = exc.reason 
    153             obj.fract = 1 
    154              
    155             self.__process_next_download() 
    156             return 
     148 
     149            with obj.lock: 
     150                obj.status = FILE_ERROR 
     151                obj.label = exc.reason 
     152                obj.fract = 1 
     153                 
     154                self.__process_next_download() 
     155                return 
    157156         
    158157        elif isinstance(exc, StopNetException): 
    159158            if obj.hash: 
    160                 obj.label = _('Checking validity ...') 
    161                 obj.status = FILE_CHECKING 
    162                  
    163                 obj.fd.flush() 
    164                 obj.fd.seek(0) 
    165                  
     159 
     160                data = "" 
     161 
     162                with obj.lock: 
     163                    obj.label = _('Checking validity ...') 
     164                    obj.status = FILE_CHECKING 
     165                 
     166                    obj.fd.flush() 
     167                    obj.fd.seek(0) 
     168 
     169                    data = obj.fd.read() 
     170                 
     171                # Not locked it could freeze the ui 
    166172                hasher = md5.new() 
    167                 hasher.update(obj.fd.read()) 
    168                  
    169                 if hasher.hexdigest() == obj.hash: 
     173                hasher.update(data) 
     174                 
     175                with obj.lock: 
     176                    if hasher.hexdigest() == obj.hash: 
     177                        obj.label = _('Updated. Restart to take effect') 
     178                        obj.status = FILE_GETTED 
     179                    else: 
     180                        obj.label = _('Corrupted file.') 
     181                        obj.status = FILE_ERROR 
     182            else: 
     183                with obj.lock: 
    170184                    obj.label = _('Updated. Restart to take effect') 
    171185                    obj.status = FILE_GETTED 
    172                 else: 
    173                     obj.label = _('Corrupted file.') 
    174                     obj.status = FILE_ERROR 
    175             else: 
    176                 obj.label = _('Updated. Restart to take effect') 
    177                 obj.status = FILE_GETTED 
    178                  
    179             obj.fd.close() 
    180             obj.fract = 1 
     186             
     187            with obj.lock: 
     188                obj.fd.close() 
     189                obj.fract = 1 
    181190             
    182191            # TODO: try/except here 
     
    190199         
    191200        elif isinstance(exc, StartNetException): 
    192             try: 
    193                 obj.status = FILE_GETTING 
    194                 obj.size = 0 
    195                 obj.total = int(file.info()['Content-Length']) 
    196             except: 
    197                 pass 
    198              
    199             obj.label = _('Downloading ...') 
     201            with obj.lock: 
     202                try: 
     203                    obj.status = FILE_GETTING 
     204                    obj.size = 0 
     205                    obj.total = int(file.info()['Content-Length']) 
     206                except: 
     207                    pass 
     208             
     209                obj.label = _('Downloading ...') 
    200210 
    201211        elif not exc: 
     
    218228 
    219229    def __process_manifest(self, file, data, exc, obj): 
    220         with obj.lock: 
    221             self.__process_manifest_cb(file, data, exc, obj) 
    222  
    223     def __process_manifest_cb(self, file, data, exc, obj): 
    224230        """ 
    225231        Callback to parse latest.xml file containing meta information about 
     
    228234 
    229235        if isinstance(exc, ErrorNetException): 
    230             obj.status = LATEST_ERROR 
    231             obj.label = _('Cannot find newer version (%s)') % exc.reason 
    232              
    233             self.__process_next() 
    234             return 
     236            with obj.lock: 
     237                obj.status = LATEST_ERROR 
     238                obj.label = _('Cannot find newer version (%s)') % exc.reason 
     239                 
     240                self.__process_next() 
     241                return 
    235242         
    236243        if isinstance(exc, StopNetException): 
     
    238245 
    239246            new_v = Version(version) 
    240             cur_v = Version(obj.object.version) 
     247            cur_v = Version(obj.object.reader.version) 
    241248 
    242249            type = -1 # -1 no action / 0 update / 1 downgrade 
     
    246253            elif cur_v < new_v: 
    247254                type = 1 
    248              
    249             if url and version and type >= 0: 
    250  
    251                 # We check if the path is the plugins in config_dir 
    252  
    253                 plug_dir = os.path.join(Path.config_dir, 'plugins') 
    254  
    255                 if os.path.dirname(obj.object.reader.get_path()) != plug_dir and \ 
    256                    os.access(plug_dir, os.O_RDWR): 
    257  
     255 
     256            with obj.lock: 
     257                if url and version and type >= 0: 
     258 
     259                    # We check if the path is the plugins in config_dir 
     260 
     261                    plug_dir = os.path.join(Path.config_dir, 'plugins') 
     262 
     263                    if os.path.dirname(obj.object.reader.get_path()) != plug_dir and \ 
     264                       os.access(plug_dir, os.O_RDWR): 
     265 
     266                        obj.status = LATEST_ERROR 
     267 
     268                        if not type: 
     269                            obj.label = _('Version %s avaiable but need manual update.') % version 
     270                        else: 
     271                            obj.label = _('Version %s avaiable but need manual downgrade.') % version 
     272                    else: 
     273                        obj.status = LATEST_GETTED 
     274                        obj.label = _('Version %s avaiable.') % version 
     275                     
     276                    obj.version = version 
     277                    obj.url = url 
     278                    obj.hash = hash 
     279                else: 
    258280                    obj.status = LATEST_ERROR 
    259281 
    260                     if not type: 
    261                         obj.label = _('Version %s avaiable but need manual update.') % version 
     282                    if type < 0: 
     283                        obj.label = _('Unable to parse latest.xml') 
    262284                    else: 
    263                         obj.label = _('Version %s avaiable but need manual downgrade.') % version 
    264                 else: 
    265                     obj.status = LATEST_GETTED 
    266                     obj.label = _('Version %s avaiable.') % version 
    267                  
    268                 obj.version = version 
    269                 obj.url = url 
    270                 obj.hash = hash 
    271             else: 
    272                 obj.status = LATEST_ERROR 
    273  
    274                 if type < 0: 
    275                     obj.label = _('Unable to parse latest.xml') 
    276                 else: 
    277                     obj.label = _('No applicable updates found') 
    278  
    279             self.__process_next() 
     285                        obj.label = _('No applicable updates found') 
     286 
     287                self.__process_next() 
    280288 
    281289        if not exc: