Changeset 2921 for branch


Ignore:
Timestamp:
Jul 8, 2017 2:57:13 PM (8 years ago)
Author:
toby
Message:

add switch command to 2frame

Location:
branch/2frame
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified branch/2frame/GSASIIctrlGUI.py

    r2917 r2921  
    35033503                text='&Regress to an old GSAS-II version')
    35043504            frame.Bind(wx.EVT_MENU, self.OnSelectVersion, helpobj)
     3505            if GSASIIpath.svnTestBranch():
     3506                msg = "&Switch to back standard GSAS-II version"
     3507            else:
     3508                msg = "&Switch to test (2frame) GSAS-II version"
     3509            helpobj = self.Append(
     3510                help='', id=wx.ID_ANY, kind=wx.ITEM_NORMAL,text=msg)
     3511            frame.Bind(wx.EVT_MENU, self.OnSelectBranch, helpobj)
    35053512        # provide special help topic names for extra items in help menu
    35063513        for lbl,indx in morehelpitems:
     
    36053612        repos = GSASIIpath.svnGetRev(local=False)
    36063613        wx.EndBusyCursor()
    3607         if repos is None:
     3614        # has the current branch disappeared? If so, switch to the trunk -- not fully tested
     3615        if (repos is None and "not found" in GSASIIpath.svnLastError.lower()
     3616            and "path" in GSASIIpath.svnLastError.lower()):
     3617            print('Repository is gone, will switch to trunk')
     3618            GSASIIpath.svnSwitch2branch()
     3619            return
     3620        elif repos is None:
    36083621            dlg = wx.MessageDialog(self.frame,
    36093622                                   'Unable to access the GSAS-II server. Is this computer on the internet?',
     
    36643677            return
    36653678        dlg.Destroy()
    3666         try:
    3667             self.frame.OnFileSave(event)
    3668             GPX = self.frame.GSASprojectfile
    3669         except AttributeError:
    3670             self.frame.G2frame.OnFileSave(event)
    3671             GPX = self.frame.G2frame.GSASprojectfile
     3679        self.frame.OnFileSave(event)
     3680        GPX = self.frame.GSASprojectfile
    36723681        GSASIIpath.svnUpdateProcess(projectfile=GPX)
    36733682        return
     
    37273736        dlg.Destroy()
    37283737        print('start regress to '+str(ver))
    3729         try:
    3730             self.frame.OnFileSave(event)
    3731             GPX = self.frame.GSASprojectfile
    3732         except AttributeError:
    3733             self.frame.G2frame.OnFileSave(event)
    3734             GPX = self.frame.G2frame.GSASprojectfile
     3738        self.frame.OnFileSave(event)
     3739        GPX = self.frame.GSASprojectfile
    37353740        GSASIIpath.svnUpdateProcess(projectfile=GPX,version=str(ver))
    37363741        return
     3742
     3743    def OnSelectBranch(self,event):
     3744        '''Allow the user to select branch of GSAS-II or return to trunk
     3745        N.B. Name of branch to use is hard-coded here. Must contain a slash
     3746        '''
     3747        testbranch = '/branch/2frame'
     3748        if GSASIIpath.svnTestBranch():
     3749            dlg = wx.MessageDialog(self.frame,
     3750                                   'Switching from test to standard GSAS-II version',
     3751                                   'Confirm Switch',
     3752                                   wx.OK|wx.CANCEL)
     3753            if dlg.ShowModal() != wx.ID_OK: return
     3754            branch = testbranch
     3755        else:
     3756            dlg = wx.MessageDialog(self.frame,
     3757                                   'Switching back to standard GSAS-II version',
     3758                                   'Confirm Switch',
     3759                                   wx.OK|wx.CANCEL)
     3760            if dlg.ShowModal() != wx.ID_OK: return
     3761            branch = 'trunk'
     3762        print('start switch')
     3763        self.frame.OnFileSave(event)
     3764        GPX = self.frame.GSASprojectfile
     3765        GSASIIpath.svnUpdateProcess(projectfile=GPX,branch=branch)
    37373766
    37383767################################################################################
     
    43984427        style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER
    43994428        wx.Dialog.__init__(self, parent, wx.ID_ANY, 'Open Tutorial', style=style)
    4400         self.frame = parent
    4401         # self.frame can be the tree window frame or the data editing window frame, set G2frame to the
    4402         # tree either way
    4403         if hasattr(self.frame,'G2frame'):
    4404             self.G2frame = self.frame.G2frame
    4405         else:
    4406             self.G2frame = self.frame
     4429        self.G2frame = self.frame = parent
    44074430        pnl = wx.Panel(self)
    44084431        sizer = wx.BoxSizer(wx.VERTICAL)
  • TabularUnified branch/2frame/GSASIIpath.py

    r2912 r2921  
    231231    return d
    232232
     233svnLastError = ''
    233234def svnGetRev(fpath=os.path.split(__file__)[0],local=True):
    234235    '''Obtain the version number for the either the last update of the local version
     
    243244    :Returns: the version number as an str or
    244245       None if there is a subversion error (likely because the path is
    245        not a repository or svn is not found)
     246       not a repository or svn is not found). The error message is placed in
     247       global variable svnLastError
    246248    '''
    247249
     
    261263        print 'svn failed\n',out
    262264        print 'err=',err
     265        global svnLastError
     266        svnLastError = err
    263267        return None
    264268    x = ET.fromstring(out)
     
    342346        print err
    343347           
    344 def svnUpdateProcess(version=None,projectfile=None):
     348def svnUpdateProcess(version=None,projectfile=None,branch=None):
    345349    '''perform an update of GSAS-II in a separate python process'''
    346350    if not projectfile:
     
    349353        projectfile = os.path.realpath(projectfile)
    350354        print 'restart using',projectfile
    351     if not version:
     355    if branch:
     356        version = branch
     357    elif not version:
    352358        version = ''
    353359    else:
     
    493499    svnSwitchDir('bindist','',distdir,verbose=verbose)
    494500    return os.path.join(path2GSAS2,'bindist')
     501
     502def svnTestBranch(loc=None):
     503    '''Returns the name of the branch directory if the installation has been switched.
     504    Returns none, if not a branch
     505    the test 2frame branch. False otherwise
     506    '''
     507    if loc is None: loc = path2GSAS2
     508    svn = whichsvn()
     509    if not svn:
     510        print('**** unable to load files: svn not found ****')
     511        return ''
     512    cmd = [svn, 'info', loc]
     513    if proxycmds: cmd += proxycmds
     514    p = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
     515    res,err = p.communicate()
     516    for l in res.split('\n'):
     517        if "Relative URL:" in l: break
     518    if "/branch/" in l:
     519        return l[l.find("/branch/")+8:].strip()
     520    else:
     521        return None
     522   
     523def svnSwitch2branch(branch=None,loc=None,svnHome=None):
     524    '''Switch to a subversion branch if specified. Switches to trunk otherwise.
     525    '''
     526    if svnHome is None: svnHome = g2home
     527    svnURL = svnHome + '/trunk'
     528    if branch:
     529        if svnHome.endswith('/'):
     530            svnURL = svnHome[:-1]
     531        else:
     532            svnURL = svnHome
     533        if branch.startswith('/'):
     534            svnURL += branch
     535        else:
     536            svnURL += '/' + branch
     537    svnSwitchDir('','',svnURL,loadpath=loc)
     538   
    495539
    496540def IPyBreak_base():
     
    708752    project,version = sys.argv[1:3]
    709753    loc = os.path.dirname(__file__)
    710     if version:
     754    if version == 'trunk':
     755        svnSwitch2branch('')
     756    elif '/' in version:
     757        svnSwitch2branch(version)
     758    elif version:
    711759        print("Regress to version "+str(version))
    712760        svnUpdateDir(loc,version=version)
Note: See TracChangeset for help on using the changeset viewer.