From 791f649648560413e4a3f31cf6c50ee50e3a2c75 Mon Sep 17 00:00:00 2001 From: Erik Troan Date: Fri, 8 Dec 2000 18:43:23 +0000 Subject: use separate timer for install which can be stopped and started --- harddrive.py | 4 ++-- image.py | 8 ++++++-- iw/progress_gui.py | 9 +++------ text.py | 6 ++---- timer.py | 23 +++++++++++++++++++++++ urlinstall.py | 2 +- 6 files changed, 37 insertions(+), 15 deletions(-) create mode 100644 timer.py diff --git a/harddrive.py b/harddrive.py index 1e1880060..a92112d34 100644 --- a/harddrive.py +++ b/harddrive.py @@ -47,7 +47,7 @@ class OldHardDriveInstallMethod(InstallMethod): self.umountMedia() return cs - def getFilename(self, h): + def getFilename(self, h, timer): return self.tree + self.path + "/RedHat/RPMS/" + self.fnames[h] def readHeaders(self): @@ -149,7 +149,7 @@ class HardDriveInstallMethod(InstallMethod): self.umountMedia() return cs - def getFilename(self, h): + def getFilename(self, h, timer): if self.mediaIsMounted != h[1000002]: self.umountMedia() self.mountMedia(h[1000002]) diff --git a/image.py b/image.py index b6bf55fb3..244524028 100644 --- a/image.py +++ b/image.py @@ -16,7 +16,7 @@ class ImageInstallMethod(InstallMethod): def readComps(self, hdlist): return ComponentSet(self.tree + '/RedHat/base/comps', hdlist) - def getFilename(self, h): + def getFilename(self, h, timer): return self.tree + "/RedHat/RPMS/" + h[1000000] def readHeaders(self): @@ -63,11 +63,13 @@ class CdromInstallMethod(ImageInstallMethod): isys.makeDevInode("loop0", "/tmp/loop") isys.lochangefd("/tmp/loop", self.loopbackFile) - def getFilename(self, h): + def getFilename(self, h, timer): if h[1000002] == None: log ("header for %s has no disc location tag, assuming it's" "on the current CD", h[1000000]) elif h[1000002] != self.currentDisc: + timer.stop() + self.currentDisc = h[1000002] isys.umount("/mnt/source") @@ -116,6 +118,8 @@ class CdromInstallMethod(ImageInstallMethod): self.messageWindow(_("Error"), _("The CDROM could not be mounted.")) + timer.start() + return self.tree + "/RedHat/RPMS/" + h[1000000] def filesDone(self): diff --git a/iw/progress_gui.py b/iw/progress_gui.py index ffe67185c..84213f180 100644 --- a/iw/progress_gui.py +++ b/iw/progress_gui.py @@ -2,7 +2,6 @@ from gtk import * from iw_gui import * import string import rpm -import time import os from threading import * from translate import _ @@ -83,11 +82,9 @@ class InstallProgressWindow (InstallWindow): ("%d M" % (self.totalSize/1024 - self.sizeComplete/1024),)) # check to see if we've started yet - if (self.timeStarted == -1): - self.timeStarted = time.time () - elapsedTime = 1 - else: - elapsedTime = time.time() - self.timeStarted + elapsedTime = timer.elapsed() + if not elapsedTime: + elapsedTime = 1 apply (self.clist.set_text, self.status["completed"]["time"] + ("%s" % formatTime(elapsedTime),)) diff --git a/text.py b/text.py index dfa404eca..226eb5b31 100644 --- a/text.py +++ b/text.py @@ -566,7 +566,7 @@ class ReconfigFinishedWindow: return INSTALL_OK class InstallProgressWindow: - def completePackage(self, header): + def completePackage(self, header, timer): def formatTime(amt): hours = amt / 60 / 60 amt = amt % (60 * 60) @@ -584,9 +584,7 @@ class InstallProgressWindow: self.sizeRemainingW.setText("%10dM" % (self.sizeTotal/1024 - self.sizeComplete/1024)) self.total.set(self.sizeComplete) - if self.timeStarted == -1: - self.timeStarted = time.time() - elapsedTime = time.time() - self.timeStarted + elapsedTime = timer.elapsed() if not elapsedTime: elapsedTime = 1 self.timeCompleteW.setText("%12s" % formatTime(elapsedTime)) diff --git a/timer.py b/timer.py new file mode 100644 index 000000000..502a359a6 --- /dev/null +++ b/timer.py @@ -0,0 +1,23 @@ +import time + +class Timer: + + def stop(self): + if self.startedAt > -1: + self.total = self.total + (time.time() - self.startedAt) + self.startedAt = -1 + + def start(self): + if self.startedAt == -1: + self.startedAt = time.time() + + def elapsed(self): + if self.startedAt == -1: + return self.total + else: + return self.total + (time.time() - self.startedAt) + + def __init__(self, start = 1): + self.total = 0 + self.startedAt = -1 + self.start() diff --git a/urlinstall.py b/urlinstall.py index 725c2c96f..a417ea628 100644 --- a/urlinstall.py +++ b/urlinstall.py @@ -26,7 +26,7 @@ class UrlInstallMethod(InstallMethod): return ComponentSet(self.baseUrl + '/RedHat/base/comps', hdlist) - def getFilename(self, h): + def getFilename(self, h, timer): root = "/mnt/sysimage" pathlist = [ "/var/tmp", "/tmp", "/." ] -- cgit