def update(self, inc=1): self._done += inc if _NOT_TTY or IsTrace(): return if not self._show: if 0.5 <= time() - self._start: self._show = True else: return if self._total <= 0: sys.stderr.write('\r%s: %d, ' % ( self._title, self._done)) sys.stderr.flush() else: p = (100 * self._done) / self._total if self._lastp != p: self._lastp = p sys.stderr.write('\r%s: %3d%% (%d/%d) ' % ( self._title, p, self._done, self._total)) sys.stderr.flush()
def update(self, inc=1): self._done += inc if _NOT_TTY or IsTrace(): return if not self._show: if 0.5 <= time() - self._start: self._show = True else: return if self._total <= 0: sys.stderr.write('\r\033[1;33m%s: %d, \033[0;0m' % (self._title, self._done)) sys.stderr.flush() else: p = (100 * self._done) / self._total if self._lastp != p or self._always_print_percentage: self._lastp = p sys.stderr.write( '\r\033[1;33m%s: %3d%% (%d%s/%d%s)%s\033[0;0m' % (self._title, p, self._done, self._units, self._total, self._units, "\n" if self._print_newline else "")) sys.stderr.flush()
def __init__(self, cmdv, capture_stdout=False, ignore_stdout=False, capture_stderr=False, cwd=None): env = dict(os.environ) for e in [ REPO_TRACE, GIT_DIR, 'GIT_ALTERNATE_OBJECT_DIRECTORIES', 'GIT_OBJECT_DIRECTORY', 'GIT_WORK_TREE', 'GIT_GRAFT_FILE', 'GIT_INDEX_FILE' ]: if e in env: del env[e] command = [GIT] command.extend(cmdv) stdout = capture_stdout and subprocess.PIPE or None if ignore_stdout: stdout = file("/dev/null", "w") stderr = capture_stderr and subprocess.PIPE or None if IsTrace(): global LAST_CWD global LAST_GITDIR dbg = '' if cwd and LAST_CWD != cwd: if LAST_GITDIR or LAST_CWD: dbg += '\n' dbg += ': cd %s\n' % cwd LAST_CWD = cwd if GIT_DIR in env and LAST_GITDIR != env[GIT_DIR]: if LAST_GITDIR or LAST_CWD: dbg += '\n' dbg += ': export GIT_DIR=%s\n' % env[GIT_DIR] LAST_GITDIR = env[GIT_DIR] dbg += ': ' dbg += ' '.join(command) if stdout == subprocess.PIPE: dbg += ' 1>|' if stderr == subprocess.PIPE: dbg += ' 2>|' Trace('%s', dbg) try: p = subprocess.Popen(command, cwd=cwd, env=env, stdout=stdout, stderr=stderr) except Exception, e: raise Exception('%s: %s' % (command[1], e))
def end(self): if _NOT_TTY or IsTrace() or not self._show: return if self._total <= 0: sys.stderr.write('\r%s: %d, done. \n' % (self._title, self._done)) sys.stderr.flush() else: p = (100 * self._done) / self._total sys.stderr.write('\r%s: %3d%% (%d%s/%d%s), done. \n' % (self._title, p, self._done, self._units, self._total, self._units)) sys.stderr.flush()
def end(self): if IsTrace() or not self._show: return if self._total <= 0: sys.stderr.write('\r%s: %d, done. \n' % ( self._title, self._done)) sys.stderr.flush() else: p = (100 * self._done) / self._total sys.stderr.write('\r%s: %3d%% (%d/%d), done. \n' % ( self._title, p, self._done, self._total)) sys.stderr.flush()
def __init__(self, project, cmdv, bare = False, provide_stdin = False, capture_stdout = False, capture_stderr = False, disable_editor = False, ssh_proxy = False, cwd = None, gitdir = None): env = os.environ.copy() for key in [REPO_TRACE, GIT_DIR, 'GIT_ALTERNATE_OBJECT_DIRECTORIES', 'GIT_OBJECT_DIRECTORY', 'GIT_WORK_TREE', 'GIT_GRAFT_FILE', 'GIT_INDEX_FILE']: if key in env: del env[key] # If we are not capturing std* then need to print it. self.tee = {'stdout': not capture_stdout, 'stderr': not capture_stderr} if disable_editor: _setenv(env, 'GIT_EDITOR', ':') if ssh_proxy: _setenv(env, 'REPO_SSH_SOCK', ssh_sock()) _setenv(env, 'GIT_SSH', _ssh_proxy()) if 'http_proxy' in env and 'darwin' == sys.platform: s = "'http.proxy=%s'" % (env['http_proxy'],) p = env.get('GIT_CONFIG_PARAMETERS') if p is not None: s = p + ' ' + s _setenv(env, 'GIT_CONFIG_PARAMETERS', s) if project: if not cwd: cwd = project.worktree if not gitdir: gitdir = project.gitdir command = [GIT] if bare: if gitdir: _setenv(env, GIT_DIR, gitdir) cwd = None command.append(cmdv[0]) # Need to use the --progress flag for fetch/clone so output will be # displayed as by default git only does progress output if stderr is a TTY. if sys.stderr.isatty() and cmdv[0] in ('fetch', 'clone'): if '--progress' not in cmdv and '--quiet' not in cmdv: command.append('--progress') command.extend(cmdv[1:]) if provide_stdin: stdin = subprocess.PIPE else: stdin = None stdout = subprocess.PIPE stderr = subprocess.PIPE if IsTrace(): global LAST_CWD global LAST_GITDIR dbg = '' if cwd and LAST_CWD != cwd: if LAST_GITDIR or LAST_CWD: dbg += '\n' dbg += ': cd %s\n' % cwd LAST_CWD = cwd if GIT_DIR in env and LAST_GITDIR != env[GIT_DIR]: if LAST_GITDIR or LAST_CWD: dbg += '\n' dbg += ': export GIT_DIR=%s\n' % env[GIT_DIR] LAST_GITDIR = env[GIT_DIR] dbg += ': ' dbg += ' '.join(command) if stdin == subprocess.PIPE: dbg += ' 0<|' if stdout == subprocess.PIPE: dbg += ' 1>|' if stderr == subprocess.PIPE: dbg += ' 2>|' Trace('%s', dbg) try: p = subprocess.Popen(command, cwd = cwd, env = env, stdin = stdin, stdout = stdout, stderr = stderr) except Exception as e: raise GitError('%s: %s' % (command[1], e)) if ssh_proxy: _add_ssh_client(p) self.process = p self.stdin = p.stdin
def __init__(self, project, cmdv, bare = False, provide_stdin = False, capture_stdout = False, capture_stderr = False, disable_editor = False, ssh_proxy = False, cwd = None, gitdir = None): env = os.environ.copy() for e in [REPO_TRACE, GIT_DIR, 'GIT_ALTERNATE_OBJECT_DIRECTORIES', 'GIT_OBJECT_DIRECTORY', 'GIT_WORK_TREE', 'GIT_GRAFT_FILE', 'GIT_INDEX_FILE']: if e in env: del env[e] if disable_editor: _setenv(env, 'GIT_EDITOR', ':') if ssh_proxy: _setenv(env, 'REPO_SSH_SOCK', ssh_sock()) _setenv(env, 'GIT_SSH', _ssh_proxy()) if project: if not cwd: cwd = project.worktree if not gitdir: gitdir = project.gitdir command = [GIT] if bare: if gitdir: _setenv(env, GIT_DIR, gitdir) cwd = None command.extend(cmdv) if provide_stdin: stdin = subprocess.PIPE else: stdin = None if capture_stdout: stdout = subprocess.PIPE else: stdout = None if capture_stderr: stderr = subprocess.PIPE else: stderr = None if IsTrace(): global LAST_CWD global LAST_GITDIR dbg = '' if cwd and LAST_CWD != cwd: if LAST_GITDIR or LAST_CWD: dbg += '\n' dbg += ': cd %s\n' % cwd LAST_CWD = cwd if GIT_DIR in env and LAST_GITDIR != env[GIT_DIR]: if LAST_GITDIR or LAST_CWD: dbg += '\n' dbg += ': export GIT_DIR=%s\n' % env[GIT_DIR] LAST_GITDIR = env[GIT_DIR] dbg += ': ' dbg += ' '.join(command) if stdin == subprocess.PIPE: dbg += ' 0<|' if stdout == subprocess.PIPE: dbg += ' 1>|' if stderr == subprocess.PIPE: dbg += ' 2>|' Trace('%s', dbg) try: p = subprocess.Popen(command, cwd = cwd, env = env, stdin = stdin, stdout = stdout, stderr = stderr) except Exception, e: raise GitError('%s: %s' % (command[1], e))