SVN status

Here’s a little script that checks current SVN status of various files in an OmegaT team project. May not be awfully useful, but sometimes it can help you prevent or solve SVN sync issues. It doesn’t do anything special, just shows you the status of the project’s project_save.tmx, main writable glossary, current file and the whole project folder.
SVN status

  • svn_status.groovy
    /*
     * #Purpose:	Check SVN status of project files 
     * 
     * @author:		Kos Ivantsov
     * @date:		2013-07-13
     * @version:	0.1
     * 
     */ 
    
    import static javax.swing.JOptionPane.*
    import static org.omegat.util.Platform.*
    import org.omegat.core.team.SVNRemoteRepository
    import org.tmatesoft.svn.core.*
    import org.tmatesoft.svn.core.wc.*
    
    def prop = project.getProjectProperties()
    if (!prop) {
    	final def title = 'SVN status'
    	final def msg   = 'Please try again after you open a project.'
    	showMessageDialog null, msg, title, INFORMATION_MESSAGE
    	return
    }
     
    if (project.isProjectLoaded()) {
    	def folder = new File(prop.getProjectRoot())
    	def projsav = new File(prop.getProjectRoot() + "omegat", "project_save.tmx")
    	def glos = new File(prop.writeableGlossary)
    	def curfile = new File(prop.getSourceRoot() + editor.getCurrentFile())
    	def curfile_svn = 'none'
    	if (SVNRemoteRepository.isSVNDirectory(folder)) {
    		def clientManager = SVNClientManager.newInstance();
    		try {
    			folder_status_r = clientManager.getStatusClient().doStatus(folder, true, true);
    		} catch (SVNException e) {
    			if (e.getErrorMessage().getErrorCode().getCode()==175002) {
    						//no connection to host
    						console.println "No connection to host"
    						final def title = 'SVN status'
    						final def msg   = 'No connection to host.'
    						showMessageDialog null, msg, title, INFORMATION_MESSAGE
    						return
    					}else throw ce
    			}
    		projsav_status_r = clientManager.getStatusClient().doStatus(projsav, true, true);
    		glos_status_r  = clientManager.getStatusClient().doStatus(glos, true, true);
    		try {
    			curfile_status_r = clientManager.getStatusClient().doStatus(curfile, true, true);
    		} catch (SVNException e) {
    			if (e.getErrorMessage().getErrorCode().getCode()==155007) {
    					//file is outside repository, so not under version control.
    					curfile_statusType = "not under version control"
    					curfile_svn = 'notundersvn'
    					cfstat = curfile_statusType
    				} else throw e 
    			}
    		if (curfile_svn != 'notundersvn' ) {
    			curfile_status_r = clientManager.getStatusClient().doStatus(curfile, true, true)
    			SVNStatusType curfile_statusType = curfile_status_r.getContentsStatus()
    			cfstat = curfile_statusType
    		}
    		SVNStatusType folder_statusType = folder_status_r.getContentsStatus();
    		SVNStatusType projsav_statusType = projsav_status_r.getContentsStatus();
    		SVNStatusType glos_statusType = glos_status_r.getContentsStatus();
    		console.println "\n"
    		console.println "Project folder status: " +folder_statusType+"\n"
    		console.println "project_save.tmx status: "+projsav_statusType+"\n"
    		console.println "Glossary status: "+glos_statusType+"\n"
    		console.println "Current file status: "+cfstat
    		final def title = 'SVN status'
    		final def msg   = "Project folder status: " +folder_statusType+"\n"+"project_save.tmx status: "+projsav_statusType+"\n"+"Glossary status: "+glos_statusType+"\n"+"Current file status: " + cfstat
    		showMessageDialog null, msg, title, INFORMATION_MESSAGE
    		return
    	}else{
    	console.println "Not a Team project" }
    	final def title = 'SVN status'
    	final def msg   = 'Status unavailable.\nNot a Team project.'
    	showMessageDialog null, msg, title, INFORMATION_MESSAGE
    	return
    }
    

If you find it helpful or have some ideas how to improve it, feel free to leave a comment.


But as of now,
Good luck