~ubuntu-branches/ubuntu/karmic/eric/karmic

« back to all changes in this revision

Viewing changes to eric/VCS/vcsSubversion/SvnStatusMonitorThread.py

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2008-01-28 18:02:25 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080128180225-6nrox6yrworh2c4v
Tags: 4.0.4-1ubuntu1
* Add python-qt3 to build-depends becuase that's where Ubuntu puts 
  pyqtconfig
* Change maintainer to MOTU

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
 
 
3
# Copyright (c) 2006 - 2007 Detlev Offenbach <detlev@die-offenbachs.de>
 
4
#
 
5
 
 
6
"""
 
7
Module implementing the VCS status monitor thread class for Subversion.
 
8
"""
 
9
 
 
10
from PyQt4.QtCore import QRegExp, QProcess, QStringList, QString
 
11
 
 
12
from VCS.StatusMonitorThread import VcsStatusMonitorThread
 
13
 
 
14
import Preferences
 
15
 
 
16
class SvnStatusMonitorThread(VcsStatusMonitorThread):
 
17
    """
 
18
    Class implementing the VCS status monitor thread class for Subversion.
 
19
    """
 
20
    def __init__(self, interval, projectDir, parent = None):
 
21
        """
 
22
        Constructor
 
23
        
 
24
        @param interval new interval in seconds (integer)
 
25
        @param projectDir project directory to monitor (string or QString)
 
26
        @param parent reference to the parent object (QObject)
 
27
        """
 
28
        VcsStatusMonitorThread.__init__(self, interval, projectDir, parent)
 
29
        
 
30
        self.__ioEncoding = str(Preferences.getSystem("IOEncoding"))
 
31
        
 
32
        self.rx_status1 = \
 
33
            QRegExp('(.{8})\\s+([0-9]+)\\s+(.+)\\s*')
 
34
        self.rx_status2 = \
 
35
            QRegExp('(.{8})\\s+([0-9-]+)\\s+([0-9?]+)\\s+([\\w?]+)\\s+(.+)\\s*')
 
36
    
 
37
    def _performMonitor(self):
 
38
        """
 
39
        Protected method implementing the monitoring action.
 
40
        
 
41
        This method populates the statusList member variable
 
42
        with a list of strings giving the status in the first column and the
 
43
        path relative to the project directory starting with the third column.
 
44
        The allowed status flags are:
 
45
        <li>
 
46
            <ul>"A" path was added but not yet comitted</ul>
 
47
            <ul>"M" path has local changes</ul>
 
48
            <ul>"U" path needs an update</ul>
 
49
            <ul>"Z" path contains a conflict</ul>
 
50
            <ul>" " path is back at normal</ul>
 
51
        </li>
 
52
        
 
53
        @return tuple of flag indicating successful operation (boolean) and 
 
54
            a status message in case of non successful operation (QString)
 
55
        """
 
56
        process = QProcess()
 
57
        args = QStringList()
 
58
        args.append('status')
 
59
        args.append('--show-updates')
 
60
        args.append('--non-interactive')
 
61
        args.append('.')
 
62
        process.setWorkingDirectory(self.projectDir)
 
63
        process.start('svn', args)
 
64
        procStarted = process.waitForStarted()
 
65
        if procStarted:
 
66
            finished = process.waitForFinished(300000)
 
67
            if finished and process.exitCode() == 0:
 
68
                output = \
 
69
                    unicode(process.readAllStandardOutput(), self.__ioEncoding, 'replace')
 
70
                states = {}
 
71
                for line in output.splitlines():
 
72
                    if self.rx_status1.exactMatch(line):
 
73
                        flags = str(self.rx_status1.cap(1))
 
74
                        path = self.rx_status1.cap(3).trimmed()
 
75
                    elif self.rx_status2.exactMatch(line):
 
76
                        flags = str(self.rx_status2.cap(1))
 
77
                        path = self.rx_status2.cap(5).trimmed()
 
78
                    else:
 
79
                        continue
 
80
                    if flags[0] in "ACM" or \
 
81
                       (flags[0] == " " and flags[7] == "*"):
 
82
                        if flags[7] == "*":
 
83
                            status = "U"
 
84
                        else:
 
85
                            status = flags[0]
 
86
                        if status == "C":
 
87
                            status = "Z"    # give it highest priority
 
88
                        name = unicode(path)
 
89
                        states[name] = status
 
90
                        try:
 
91
                            if self.reportedStates[name] != status:
 
92
                                self.statusList.append("%s %s" % (status, name))
 
93
                        except KeyError:
 
94
                            self.statusList.append("%s %s" % (status, name))
 
95
                for name in self.reportedStates.keys():
 
96
                    if name not in states:
 
97
                        self.statusList.append("  %s" % name)
 
98
                self.reportedStates = states
 
99
                return True, \
 
100
                       self.trUtf8("Subversion status checked successfully (using svn)")
 
101
            else:
 
102
                process.kill()
 
103
                return False, QString(process.readAllStandardError())
 
104
        else:
 
105
            process.kill()
 
106
            return False, self.trUtf8("Could not start the Subversion process.")