~mapclient.devs/mapclient/stable

« back to all changes in this revision

Viewing changes to mapclient/core/threadcommandmanager.py

  • Committer: musculoskeletal
  • Date: 2014-06-25 05:38:05 UTC
  • mfrom: (1.6.35 testing)
  • Revision ID: musculoskeletal@bioeng1033-20140625053805-jkqhi5oq74vmlntl
Merging testing into stable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
from shutil import copy, move, rmtree
25
25
from subprocess import call, Popen, PIPE, STDOUT
26
26
 
 
27
from PySide import QtCore
 
28
 
27
29
class ThreadCommand(Thread):
28
30
    '''Base class for threaded commands to be used by the CommandThreadManager.
29
31
    Set the _caller for a callback to the manager to inform the manager that
106
108
    ''' Threadable command to clone a PMR workspace.
107
109
    '''
108
110
 
109
 
    def __init__(self, repourl, location, username, password):
 
111
    def __init__(self, repourl, location, username=None, password=None):
110
112
        ThreadCommand.__init__(self, 'CommandCloneWorkspace')
111
113
        self._repourl = repourl
112
114
        self._location = location
125
127
        if self._hg and not os.path.exists(join(self._location, '.hg')):
126
128
            d = tempfile.mkdtemp(dir=self._location)
127
129
 
128
 
            repourl = self._repourl[:7] + self._username + ':' + self._password + '@' + self._repourl[7:]
 
130
 
 
131
            if self._username is None or self._password is None:
 
132
                repourl = self._repourl
 
133
            else:
 
134
                repourl = self._repourl[:7] + self._username + ':' + self._password + '@' + self._repourl[7:]
129
135
            call([self._hg, 'clone', repourl, d])
130
136
            mvdir(d, self._location)
131
137
#            move(join(d, '.hg'), self._location)
167
173
        self.runFinished()
168
174
 
169
175
 
170
 
class ThreadCommandManager(object):
171
 
    '''This class managers thread commands in a queue.  The queue will
 
176
class ThreadCommandManager(QtCore.QObject):
 
177
    '''
 
178
    This class managers thread commands in a queue.  The queue will
172
179
    be executed in order serially.
173
180
    '''
 
181
    queue_empty = QtCore.Signal()
174
182
 
175
183
    def __init__(self):
 
184
        super(ThreadCommandManager, self).__init__()
176
185
        self._queue = []
177
 
        self._finished = None  # Callback for informing when the queue is empty
178
 
 
179
 
    def registerFinishedCallback(self, callback):
180
 
        self._finished = callback
181
186
 
182
187
    def addCommand(self, c):
183
188
        self._queue.append(c)
184
189
 
185
 
    def execute(self):
 
190
    def next(self):
186
191
        if len(self._queue) > 0:
187
192
            c = self._queue.pop(0)
188
193
            c.setCaller(self)
189
194
            c.start()
190
 
        elif self._finished:
191
 
            self._finished()
 
195
        else:
 
196
            self.queue_empty.emit()
192
197
 
193
198
    def _commandFinished(self, thread_name):
194
 
        self.execute()
 
199
        self.next()
195
200
 
196
201
 
197
202
def which(name, flags=os.X_OK):