r287 - in branches/rewrite: . src
Otavio Salvador
partial-mirror-devel@lists.alioth.debian.org
Wed, 10 Nov 2004 16:21:28 -0700
Author: otavio
Date: Wed Nov 10 16:21:27 2004
New Revision: 287
Added:
branches/rewrite/src/DisplayStatus.py (contents, props changed)
Removed:
branches/rewrite/src/DisplayInfo.py
Modified:
branches/rewrite/ (props changed)
branches/rewrite/src/Download.py
Log:
r214@nurf: otavio | 2004-11-10T23:20:51.730167Z
Rename DisplayInfo to DisplayStatus.
Added: branches/rewrite/src/DisplayStatus.py
==============================================================================
--- (empty file)
+++ branches/rewrite/src/DisplayStatus.py Wed Nov 10 16:21:27 2004
@@ -0,0 +1,97 @@
+# debpartial-mirror - partial debian mirror package tool
+# (c) 2004 Otavio Salvador <otavio@debian.org>, Enrico Zini <enrico@debian.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+# $Id$
+
+import sys
+from os.path import basename
+
+class StatusItem:
+ id = 0
+ def __init__(self):
+ self._properties = None
+
+ def __getitem__(self, key):
+ if key not in ['id', 'finished', 'current', 'size', 'errored']:
+ raise KeyError("%s is not allowed on StatusItem." % key)
+
+ if self._properties is None:
+ StatusItem.id += 1
+ self._properties = {'id' : StatusItem.id,
+ 'finished': False,
+ 'current' : 0,
+ 'size' : 0,
+ 'errored' : ''}
+
+ return self._properties.get(key)
+
+ def __setitem__(self, key, value):
+ if key not in ['id', 'finished', 'current', 'size', 'errored']:
+ raise KeyError("%s is not allowed on StatusItem." % key)
+
+ if self._properties is None:
+ StatusItem.id += 1
+ self._properties = {'id' : StatusItem.id,
+ 'finished': False,
+ 'current' : 0,
+ 'size' : 0,
+ 'errored' : ''}
+
+ self._properties[key] = value
+
+class BaseDisplayStatus:
+ _items = {}
+
+ def __getitem__ (self, key):
+ return self._items.get(key, None)
+
+ def start(self, url, size):
+ self._items[url] = StatusItem()
+ self._items[url]['size'] = size
+
+ def update(self, url, current):
+ self._items[url]['current'] = current
+
+ def errored(self, url, message):
+ if not self._items.has_key(url):
+ self._items[url] = StatusItem()
+ self._items[url]['errored'] = message
+
+class TextDisplayStatus(BaseDisplayStatus):
+ def start(self, url, size):
+ BaseDisplayStatus.start(self, url, size)
+ sys.stdout.write("\r" + " " * 80 + "\rGetting %d: %s\n" % (self._items[url]['id'], url))
+
+ def update(self, url, current):
+ BaseDisplayStatus.update(self, url, current)
+ if self._items[url]['current'] == self._items[url]['size']:
+ self._items[url]['finished'] = True
+ sys.stdout.write("\r" + " " * 80 + "\r")
+ for url in self._items.keys():
+ if self._items[url]['finished'] or self._items[url]['errored']:
+ continue
+ try:
+ sys.stdout.write("[%d %s: %.2f%%]" % (self._items[url]['id'],
+ basename(url).split('_')[0],
+ self._items[url]['current']*100/(self._items[url]['size'])))
+ except ZeroDivisionError:
+ pass
+
+ sys.stdout.flush()
+
+ def errored(self, url, message):
+ BaseDisplayStatus.errored(self, url, message)
+ sys.stdout.write("\r" + " " * 80 + "\rFailed: %s\n" % url)
Modified: branches/rewrite/src/Download.py
==============================================================================
--- branches/rewrite/src/Download.py (original)
+++ branches/rewrite/src/Download.py Wed Nov 10 16:21:27 2004
@@ -20,7 +20,7 @@
import threading
from Queue import Queue, Empty
-from DisplayInfo import *
+from DisplayStatus import *
class DownloadQueue(Queue):
counter = 0