Beispiel #1
0
    def run(self, serial=False):
        repo = self.repo
        cmd = self.cmd
        msg = ' '.join([START_COLOR, '\n', repo, ':'] + cmd + [RESET_COLOR])

        shell = UseShellOnSubprocess()
        if serial:
            #Print directly to stdout/stderr without buffering.
            if not IsQuietMode():
                Print(msg)
            p = None
            try:
                p = subprocess.Popen(cmd, cwd=repo, shell=shell)
            except:
                PrintError('Error executing: ' + ' '.join(cmd) + ' on: ' +
                           repo)
            if p is not None:
                p.wait()

        else:
            try:
                p = subprocess.Popen(cmd,
                                     cwd=repo,
                                     stderr=subprocess.PIPE,
                                     stdout=subprocess.PIPE,
                                     shell=shell)
            except:
                import os
                PrintError('Error executing: ' + ' '.join(cmd) + ' on: ' +
                           repo + ' cwd: ' + os.path.abspath('.'))
                self.output_queue.put(
                    Output(repo,
                           'Error executing: %s on repo: %s' % (cmd, repo), '',
                           ''))
                return

            self.stdout_thread = self._CreateReaderThread(p, 'stdout')
            self.stderr_thread = self._CreateReaderThread(p, 'stderr')

            p.wait()
            self.stdout_thread.join(2)  #finish in at most 2 seconds
            self.stderr_thread.join(2)  #finish in at most 2 seconds
            stdout = AsStr(self.stdout_thread.GetFullOutput())
            stderr = AsStr(self.stderr_thread.GetFullOutput())

            self._HandleOutput(msg, stdout, stderr)
Beispiel #2
0
 def run(self):
     while True:
         func = self.tasks_queue.get()
         try:
             try:
                 func()
             except:
                 from mu_repo.print_ import PrintError
                 PrintError()
         finally:
             self.tasks_queue.task_done()
Beispiel #3
0
    def __call__(self):
        try:
            git, repo, original_repo, target_repo, branch = self._args
            stdout = ExecuteGettingStdOutput(
                [git, 'show', '%s:%s' % (
                    branch,
                    original_repo,
                )], repo)

            try:
                if not os.path.isdir(target_repo):
                    with open(target_repo, 'wb') as f:
                        f.write(stdout)
            except:
                PrintError('Error writing to file: %s\n%s' % (
                    target_repo,
                    stdout,
                ))
        except:
            NotifyErrorListeners()
Beispiel #4
0
    def run(self):
        while True:
            action = self.output_queue.get(True)
            try:
                if action is self.FINISH_PROCESSING_ITEM:
                    return
                if isinstance(action, Output):
                    if self.on_output is not None:
                        self.on_output(action)
                    #else:
                    #    Note: in this case, the output will be printed by the
                    #    ExecuteThreadsHandlingOutputQueue method (along with the stderr).
                    #    Print(action)
                else:
                    Print(action)  #Progress message.
            except:
                PrintError()

            finally:
                self.output_queue.task_done()
Beispiel #5
0
    def run(self):
        stop = False
        while not stop:
            try:
                semaphores_to_release = []
                while True:
                    try:
                        semaphores_to_release.append(
                            self.semaphore_sync_queue.get(False))
                    except Queue.Empty:
                        break  #Break the inner while

                try:
                    while True:
                        try:
                            self._files.append(
                                self.files_to_keep_in_sync_queue.get(False))
                        except Queue.Empty:
                            break  #Break the inner while

                    #Ok, files collected without any timeout... let's see if some other arrives with
                    #a timeout.
                    try:
                        self._files.append(
                            self.files_to_keep_in_sync_queue.get(
                                True, self._TIMEOUT))
                    except Queue.Empty:
                        pass

                    for f in self._files:
                        f.Sync()
                finally:
                    for semaphore, cmd in semaphores_to_release:
                        if cmd == 'stop':
                            stop = True
                        semaphore.release()

            except:
                #Should not happen...
                PrintError()
Beispiel #6
0
def ExecuteCommand(cmd, repo, return_stdout=False, verbose=True):
    '''
    Execute command letting stderr go to the default sys.stderr.
    Will block until the command finishes.
    
    @param cmd: list(str)
        The command to be executed.
        
    @param repo: str
        The repository (working dir) where the command should be executed.
    
    @param return_stdout: bool
        If True, will grab stdout and return it, otherwise will let it go to sys.stderr.
        
    @param verbose: bool
        If True will print the command being executed.
        
    @return: the redirected stdout (if return_stdout is True) or None otherwise
    '''
    if verbose:
        msg = ' '.join([START_COLOR, '\n', repo, ':'] + cmd + [RESET_COLOR])
        Print(msg)
    try:
        shell = UseShellOnSubprocess()
        if return_stdout:
            p = subprocess.Popen(cmd,
                                 cwd=repo,
                                 stdout=subprocess.PIPE,
                                 shell=shell)
        else:
            p = subprocess.Popen(cmd, cwd=repo, shell=shell)
    except:
        PrintError('Error executing: ' + ' '.join(cmd) + ' on: ' + repo)
        raise

    if not return_stdout:
        p.wait()
    else:
        stdout, _stderr = p.communicate()
        return stdout