Changeset 6df04e43 in sasview


Ignore:
Timestamp:
Nov 18, 2011 12:43:13 PM (12 years ago)
Author:
Gervaise Alina <gervyh@…>
Branches:
master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
3dc977c
Parents:
930f559
Message:

put back the code for version_checking, replace subprocess with process

Location:
sansguiframe/src/sans/guiframe
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • sansguiframe/src/sans/guiframe/dummyapp.py

    r70ecd530 r6df04e43  
    122122 
    123123if __name__ == "__main__":  
     124    from multiprocessing import freeze_support 
     125    freeze_support() 
    124126    sansview = SansView() 
    125      
  • sansguiframe/src/sans/guiframe/gui_manager.py

    r70ecd530 r6df04e43  
    288288        self.add_icon() 
    289289        # Check for update 
    290         #self._check_update(None) 
     290        self._check_update(None) 
    291291        # Register the close event so it calls our own method 
    292292        wx.EVT_CLOSE(self, self.Close) 
     
    657657        self._setup_extra_custom() 
    658658        #self.Show(True) 
    659         #self._check_update(None) 
     659        self._check_update(None) 
    660660     
    661661    def _setup_extra_custom(self):   
     
    698698        """ 
    699699        number = self.sb.get_msg_position() 
    700         wx.Frame.SetStatusText(number=number, *args, **kwds) 
     700        wx.Frame.SetStatusText(self, number=number, *args, **kwds) 
    701701         
    702702    def PopStatusText(self, *args, **kwds): 
     
    704704        """ 
    705705        field = self.sb.get_msg_position() 
    706         wx.Frame.PopStatusText(field=field) 
     706        wx.Frame.PopStatusText(self, field=field) 
    707707         
    708708    def PushStatusText(self, *args, **kwds): 
     
    12331233        #self._help_menu.Append(id,'&Check for update',  
    12341234        #'Check for the latest version of %s' % config.__appname__) 
    1235         #wx.EVT_MENU(self, id, self._check_update) 
     1235        wx.EVT_MENU(self, id, self._check_update) 
    12361236        self._menubar.Append(self._help_menu, '&Help') 
    12371237             
     
    20852085        a call-back method when the current version number has been obtained. 
    20862086        """ 
     2087         
    20872088        if hasattr(config, "__update_URL__"): 
    20882089            import version 
    2089             checker = version.VersionThread(config.__update_URL__, 
     2090            checker = version.VersionThread2(config.__update_URL__, 
    20902091                                            self._process_version, 
    20912092                                            baggage=event==None) 
     
    21062107        try: 
    21072108            if cmp(version, config.__version__) > 0: 
    2108                 msg = "Version %s is available! See the Help " 
    2109                 msg += "menu to download it." % version 
     2109                msg = "Version %s is available! See the Help " % str(version) 
     2110                msg += "menu to download it."  
    21102111                self.SetStatusText(msg) 
    21112112                if not standalone: 
     
    21152116                if not standalone: 
    21162117                    msg = "You have the latest version" 
    2117                     msg += " of %s" % config.__appname__ 
     2118                    msg += " of %s" % str(config.__appname__) 
    21182119                    self.SetStatusText(msg) 
    21192120        except: 
     
    32063207        self.frame.Show(True) 
    32073208        event.Skip() 
    3208        
     3209 
    32093210if __name__ == "__main__":  
    32103211    app = ViewApp(0) 
  • sansguiframe/src/sans/guiframe/version.py

    r8c347a6 r6df04e43  
    1414import time 
    1515import subprocess 
     16import urllib 
     17import re 
    1618import os 
    1719import getopt 
     
    2224## Local storage file name 
    2325VERSION_FILE  = '.current_version' 
     26 
     27DEFAULT_VERSION = '0.0.0' 
    2428 
    2529class VersionChecker(object): 
     
    7175            return f.read() 
    7276        except: 
    73             return '0.0.0' 
     77            return DEFAULT_VERSION 
    7478 
    7579class VersionThread(Thread): 
     
    96100            time.sleep(1) 
    97101        self._call_back(checker.get_version(), self._baggage) 
     102         
     103   
     104def get_version(url, q=None): 
     105    """ 
     106    """ 
     107    h = urllib.urlopen(url) 
     108    for line in h.readlines(): 
     109        version = line.strip() 
     110        if len(re.findall('\d+\.\d+\.\d+$', version)) > 0: 
     111            if q is not None: 
     112                q.put(version) 
     113            return version 
     114    if q is not None: 
     115        q.put(DEFAULT_VERSION) 
     116    return DEFAULT_VERSION 
     117       
     118class VersionThread2(Thread): 
     119    """ 
     120    Thread used to start the process of reading the current version of an 
     121    application from the deployment server.  
     122    
     123    The VersionChecker is user in a Thread to allow the main application 
     124    to continue dealing with UI requests from the user. The main application 
     125    provides a call-back method for when the version number is obtained.  
     126    """ 
     127    def __init__ (self, url, call_back=None, baggage=None): 
     128        Thread.__init__(self) 
     129        self._url = url 
     130        self._call_back = call_back 
     131        self._baggage = baggage 
     132        self._t_0 = time.time() 
     133       
     134    def run(self): 
     135        """ 
     136        Execute the process of reading the current application version number. 
     137        """ 
     138        def is_complete(p): 
     139            """ 
     140            """ 
     141            if(time.time() - self._t_0 < MAX_WAIT_TIME): 
     142                if p.is_alive(): 
     143                    return True 
     144                return False 
     145            else: 
     146                return False 
     147             
     148        from multiprocessing import Process, Queue 
     149        q = Queue() 
     150        p = Process(target=get_version, args=(self._url, q,)) 
     151        p.start() 
     152        while(not is_complete(p)): 
     153            time.sleep(1) 
     154        version = q.get() 
     155        p.join() 
     156        p.terminate() 
     157        self._call_back(version, self._baggage) 
     158     
    98159             
    99160def write_version(version, filename=VERSION_FILE): 
     
    114175     
    115176    """ 
    116     import urllib 
    117     import re 
    118177    try:  
    119         h = urllib.urlopen(url) 
    120         for line in h.readlines(): 
    121             version = line.strip() 
    122             if len(re.findall('\d+\.\d+\.\d+$', version)) > 0: 
    123                 write_version(version) 
    124                 return        
    125         write_version('0.0.0') 
     178        version = _get_version(url) 
     179        write_version(version) 
    126180    except: 
    127         write_version('0.0.0') 
     181        write_version(DEFAULT_VERSION) 
     182         
     183         
    128184         
    129185if __name__ == "__main__":  
Note: See TracChangeset for help on using the changeset viewer.