Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(872)

Unified Diff: third_party/repo/progress.py

Issue 564051: Add progress indicator for sync (Closed)
Patch Set: Created 10 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/repo/__init__.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/repo/progress.py
diff --git a/third_party/repo/progress.py b/third_party/repo/progress.py
new file mode 100644
index 0000000000000000000000000000000000000000..08392fcdf29939b0e0610c3738bc11e290f95c14
--- /dev/null
+++ b/third_party/repo/progress.py
@@ -0,0 +1,70 @@
+#
+# Copyright (C) 2009 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import sys
+from time import time
+
+class Progress(object):
+ def __init__(self, title, total=0):
+ self._title = title
+ self._total = total
+ self._done = 0
+ self._lastp = -1
+ self._start = time()
+ self._show = False
+
+ def update(self, inc=1):
+ self._done += inc
+
+ 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 end(self):
+ if 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()
« no previous file with comments | « third_party/repo/__init__.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698