Changeset 762


Ignore:
Timestamp:
Sep 23, 2012 4:57:51 PM (9 years ago)
Author:
toby
Message:

update py files to use native line ends, add update from svn to help menu when svn or svn.exe is in path or ./svn/bin

Location:
trunk
Files:
33 edited

Legend:

Unmodified
Added
Removed
  • trunk/ElementTable.py

    • Property svn:eol-style set to native
  • trunk/FormFactors.py

    • Property svn:eol-style set to native
  • trunk/GSASII.py

    • Property svn:eol-style set to native
  • trunk/GSASIIElem.py

    • Property svn:eol-style set to native
  • trunk/GSASIIElemGUI.py

    • Property svn:eol-style set to native
  • trunk/GSASIIIO.py

    • Property svn:eol-style set to native
  • trunk/GSASIIgrid.py

    • Property svn:eol-style set to native
    r752 r762  
    165165            text='&About GSAS-II')
    166166        frame.Bind(wx.EVT_MENU, self.OnHelpAbout, id=wx.ID_ABOUT)
    167 
     167        if GSASIIpath.whichsvn():
     168            helpobj = self.Append(
     169                help='', id=wx.ID_ANY, kind=wx.ITEM_NORMAL,
     170                text='&Check for updates')
     171            frame.Bind(wx.EVT_MENU, self.OnCheckUpdates, helpobj)
     172       
    168173    def OnHelpById(self,event):
    169174        '''Called when Help on... is pressed in a menu. Brings up
     
    194199        wx.AboutBox(info)
    195200
     201    def OnCheckUpdates(self,event):
     202        '''Check if the GSAS-II repository has an update for the current source files
     203        and perform that update if requested.
     204        '''
     205        if not GSASIIpath.whichsvn():
     206            dlg = wx.MessageDialog(self,'No Subversion','Cannot update GSAS-II because subversion (svn) '+
     207                                   'was not found.'
     208                                   ,wx.OK)
     209            dlg.ShowModal()
     210            return
     211        wx.BeginBusyCursor()
     212        local = GSASIIpath.svnGetRev()
     213        if local is None:
     214            wx.EndBusyCursor()
     215            dlg = wx.MessageDialog(self.frame,
     216                                   'Unable to run subversion on the GSAS-II current directory. Is GSAS-II installed correctly?',
     217                                   'Subversion error',
     218                                   wx.OK)
     219            dlg.ShowModal()
     220            return
     221        print 'Installed GSAS-II version: '+local
     222        repos = GSASIIpath.svnGetRev(local=False)
     223        wx.EndBusyCursor()
     224        if repos is None:
     225            dlg = wx.MessageDialog(self.frame,
     226                                   'Unable to access the GSAS-II server. Is this computer on the internet?',
     227                                   'Server unavailable',
     228                                   wx.OK)
     229            dlg.ShowModal()
     230            return
     231        print 'GSAS-II version on server: '+repos
     232        if local == repos:
     233            dlg = wx.MessageDialog(self.frame,
     234                                   'GSAS-II is up-to-date. Version '+local+' is already loaded.',
     235                                   'GSAS-II Up-to-date',
     236                                   wx.OK)
     237            dlg.ShowModal()
     238            return
     239        mods = GSASIIpath.svnFindLocalChanges()
     240        if mods:
     241            dlg = wx.MessageDialog(self.frame,
     242                                   'You have version '+local+
     243                                   ' of GSAS-II installed, but the current version is '+repos+
     244                                   'However, you have modified '+str(len(mods))+
     245                                   ' file(s) on your local computer have been modified.'
     246                                   ' Updating could wipe out your local changes. Press OK to start an update:',
     247                                   'Local GSAS-II Mods',
     248                                   wx.OK|wx.CANCEL)
     249            if dlg.ShowModal() != wx.ID_OK: return
     250        else:
     251            dlg = wx.MessageDialog(self.frame,
     252                                   'You have version '+local+
     253                                   ' of GSAS-II installed, but the current version is '+repos+
     254                                   '. Press OK to start an update:',
     255                                   'GSAS-II Updates',
     256                                   wx.OK|wx.CANCEL)
     257            if dlg.ShowModal() != wx.ID_OK: return
     258        print 'start updates'
     259        wx.BeginBusyCursor()
     260        moddict = GSASIIpath.svnUpdateDir()
     261        wx.EndBusyCursor()
     262        if moddict is None:
     263            dlg = wx.MessageDialog(self.frame,
     264                                   'Error accessing the GSAS-II server or performing the update. '+
     265                                   'Try again later or perform a manual update',
     266                                   'Update Error',
     267                                   wx.OK)
     268            dlg.ShowModal()
     269            return
     270        modsbytype = {}
     271        for key in moddict:
     272            typ = moddict[key]
     273            if modsbytype.get(typ) is None:
     274                modsbytype[typ] = []
     275            modsbytype[typ].append(key)
     276        msg = 'Update was completed. Changes will take effect when GSAS-II is next updated. The following files were updated, ordered by status:'
     277        for key in modsbytype:
     278            msg += '\n' + key + ':\n\t'
     279            for fil in modsbytype:
     280                msg += fil + ', '
     281        dlg = wx.MessageDialog(self.frame,msg, 'Update Completed', wx.OK)
     282        dlg.ShowModal()
     283        return
     284 
    196285class MyHtmlPanel(wx.Panel):
    197286    '''Defines a panel to display Help information'''
  • trunk/GSASIIimage.py

    • Property svn:eol-style set to native
  • trunk/GSASIIimgGUI.py

    • Property svn:eol-style set to native
  • trunk/GSASIIindex.py

    • Property svn:eol-style set to native
  • trunk/GSASIIlattice.py

    • Property svn:eol-style set to native
  • trunk/GSASIImapvars.py

    • Property svn:eol-style set to native
  • trunk/GSASIImath.py

    • Property svn:eol-style set to native
  • trunk/GSASIIpath.py

    • Property svn:eol-style set to native
    r660 r762  
    11# -*- coding: utf-8 -*-
     2'''Routines for dealing with file locations, etc.
     3'''
     4import os
     5import sys
     6import platform
    27# determine a binary path for the pyd files based on the host OS and the python version, 
    38# path is relative to location of the script that is called as well as this file
    49# this must be imported before anything that imports any .pyd/.so file for GSASII
    5 import os.path as ospath
    6 import sys
    7 import platform
    810bindir = None
    911if sys.platform == "win32":
     
    2224    else:
    2325        bindir = 'binlinux%d.%d' % sys.version_info[0:2]
    24 for loc in sys.path[0],ospath.split(__file__)[0]:
     26for loc in sys.path[0],os.path.split(__file__)[0]:
    2527    if bindir:
    26         if ospath.exists(ospath.join(loc,bindir)) and ospath.join(loc,bindir) not in sys.path:
    27             sys.path.insert(0,ospath.join(loc,bindir))
     28        if os.path.exists(os.path.join(loc,bindir)) and os.path.join(loc,bindir) not in sys.path:
     29            sys.path.insert(0,os.path.join(loc,bindir))
    2830        # is there a bin directory? (created by a local compile), if so put
    2931        # that at the top of the path
    30     if ospath.exists(ospath.join(loc,'bin')):
     32    if os.path.exists(os.path.join(loc,'bin')):
    3133        bindir = 'bin'
    32         if ospath.join(loc,'bin') not in sys.path:
    33             sys.path.insert(0,ospath.join(loc,bindir))
     34        if os.path.join(loc,'bin') not in sys.path:
     35            sys.path.insert(0,os.path.join(loc,bindir))
    3436if bindir == None:
    3537    print "Warning GSAS-II binary libraries not found, some sections of code will not function"
    3638
    37 # track the latest version number here
     39# routines for looking a version numbers in files
    3840version = -1
    3941def SetVersionNumber(RevString):
     
    5052def GetVersionNumber():
    5153    return version
     54
     55# routines to interface with subversion
     56def whichsvn():
     57    '''Returns a path to the subversion exe file, if any is found.
     58    Searches the current path as well as subdirectory "svn" and
     59    "svn/bin" in the location of the GSASII source files.
     60    returns None if svn is not found.
     61    '''
     62    def is_exe(fpath):
     63        return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
     64    svnprog = 'svn'
     65    if sys.platform == "win32": svnprog += '.exe'
     66    pathlist = os.environ["PATH"].split(os.pathsep)
     67    pathlist.insert(0,os.path.join(os.path.split(__file__)[0],'svn'))
     68    pathlist.insert(1,os.path.join(os.path.split(__file__)[0],'svn','bin'))
     69    for path in pathlist:
     70        exe_file = os.path.join(path, svnprog)
     71        if is_exe(exe_file):
     72            return exe_file
     73
     74def svnGetRev(fpath=os.path.split(__file__)[0],local=True):
     75    '''This obtains the version number for the either the latest local last update
     76    or contacts the subversion server to get the latest update version (# of Head).
     77
     78    parameters:
     79     fpath: path to repository dictionary, defaults to directory where
     80       the current file is located
     81     local: determines the type of version number, where
     82       True (default): returns the latest installed update
     83       False: returns the version number of Head on the server
     84
     85    Returns that number as an str.
     86
     87    Returns None if there is a subversion error (likely because the path is
     88       not a repository or svn is not found)
     89    '''
     90
     91    import subprocess
     92    import xml.etree.ElementTree as ET
     93    svn = whichsvn()
     94    if not svn: return
     95    if local:
     96        cmd = [svn,'info',fpath,'--xml']
     97    else:
     98        cmd = [svn,'info',fpath,'--xml','-rHEAD']
     99    s = subprocess.Popen(cmd,
     100                         stdout=subprocess.PIPE,stderr=subprocess.PIPE)
     101    out,err = s.communicate()
     102    if err:
     103        print 'out=',out
     104        print 'err=',err
     105        return None
     106    x = ET.fromstring(out)
     107    for i in x.iter('entry'):
     108        rev = i.attrib.get('revision')
     109        if rev: return rev
     110
     111def svnFindLocalChanges(fpath=os.path.split(__file__)[0]):
     112    '''Returns a list of files that were changed locally. If no files are changed,
     113       the list has length 0
     114
     115    parameter:
     116     fpath: path to repository dictionary, defaults to directory where
     117       the current file is located
     118
     119    Returns None if there is a subversion error (likely because the path is
     120       not a repository or svn is not found)
     121    '''
     122    import subprocess
     123    import xml.etree.ElementTree as ET
     124    svn = whichsvn()
     125    if not svn: return
     126    s = subprocess.Popen([svn,'status',fpath,'--xml'],
     127                         stdout=subprocess.PIPE,stderr=subprocess.PIPE)
     128    out,err = s.communicate()
     129    if err: return None
     130    x = ET.fromstring(out)
     131    changed = []
     132    for i in x.iter('entry'):
     133        if i.find('wc-status').attrib.get('item') == 'modified':
     134            changed.append(i.attrib.get('path'))
     135    return changed
     136
     137def svnUpdateDir(fpath=os.path.split(__file__)[0]):
     138    '''This performs an update of the files in a local directory from a server.
     139
     140    parameter:
     141     fpath: path to repository dictionary, defaults to directory where
     142       the current file is located
     143
     144    Returns:
     145       A dictionary with the files that have been changed/added and
     146          a code describing how they have been updated (see changetype)
     147         
     148       None if there is a subversion error (likely because the path is
     149          not a repository or svn is not found)
     150    '''
     151    import subprocess
     152    changetype = {'A': 'Added', 'D': 'Deleted', 'U': 'Updated',
     153                  'C': 'Conflict', 'G': 'Merged', 'E': 'Replaced'}
     154    svn = whichsvn()
     155    if not svn: return
     156    cmd = [svn,'update',fpath,'-rHEAD',
     157           '--non-interactive',
     158           '--accept','theirs-conflict','--force']
     159    s = subprocess.Popen(cmd,
     160                         stdout=subprocess.PIPE,stderr=subprocess.PIPE)
     161    out,err = s.communicate()
     162    if err: return
     163    l = out.split()
     164    updates = {}
     165    for i,j in zip(l[::2],l[1::2]):
     166        if i == 'Updated': break
     167        if i == 'At': break
     168        t = changetype.get(i[0])
     169        if not t: continue
     170        updates[j] = t
     171    return updates
  • trunk/GSASIIphsGUI.py

    • Property svn:eol-style set to native
  • trunk/GSASIIplot.py

    • Property svn:eol-style set to native
  • trunk/GSASIIpwd.py

    • Property svn:eol-style set to native
  • trunk/GSASIIsolve.py

    • Property svn:eol-style set to native
  • trunk/GSASIIspc.py

    • Property svn:eol-style set to native
  • trunk/GSASIIstruct.py

    • Property svn:eol-style set to native
  • trunk/GSASIItestplot.py

    • Property svn:eol-style set to native
  • trunk/ImageCalibrants.py

    • Property svn:eol-style set to native
  • trunk/imports/G2phase.py

    • Property svn:eol-style set to native
  • trunk/imports/G2phase_CIF.py

    • Property svn:eol-style set to native
  • trunk/imports/G2phase_GPX.py

    • Property svn:eol-style set to native
  • trunk/imports/G2pwd_CIF.py

    • Property svn:eol-style set to native
  • trunk/imports/G2pwd_fxye.py

    • Property svn:eol-style set to native
  • trunk/imports/G2pwd_xye.py

    • Property svn:eol-style set to native
  • trunk/imports/G2sfact.py

    • Property svn:eol-style set to native
  • trunk/imports/G2sfact_CIF.py

    • Property svn:eol-style set to native
  • trunk/scanCCD.py

    • Property svn:eol-style set to native
  • trunk/testGSASIIstruct.py

    • Property svn:eol-style set to native
  • trunk/unit_tests.py

    • Property svn:eol-style set to native
Note: See TracChangeset for help on using the changeset viewer.