summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Dieter <jdieter@gmail.com>2007-03-26 09:29:05 +0300
committerJonathan Dieter <jdieter@gmail.com>2007-03-26 09:29:05 +0300
commitfefaa0389539e4433d6ae4d0c85a459304bbbbe6 (patch)
treef1e2e8b58ae4930596d6d6d330291436636d711c
parentfff4696a43faa32f41d5c1726847b51c68db8d60 (diff)
downloadpresto-fefaa0389539e4433d6ae4d0c85a459304bbbbe6.zip
presto-fefaa0389539e4433d6ae4d0c85a459304bbbbe6.tar.gz
presto-fefaa0389539e4433d6ae4d0c85a459304bbbbe6.tar.xz
Added logging to /var/log/presto.log
Signed-off-by: Jonathan Dieter <jdieter@gmail.com>
-rw-r--r--ChangeLog4
-rw-r--r--Makefile1
-rw-r--r--presto.py12
-rw-r--r--shared/prestoLog.py71
4 files changed, 87 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 8de0693..f37c5b2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+* Mon Mar 26 2007 Jonathan Dieter <jdieter@gmail.com> - 0.2.4
+ - Minor optimization
+ - Added logging to /var/log/presto.log
+
* Sat Mar 24 2007 Jonathan Dieter <jdieter@gmail.com> - 0.2.3
- Fixed bug that breaks yum install
diff --git a/Makefile b/Makefile
index 5ea597a..23f7848 100644
--- a/Makefile
+++ b/Makefile
@@ -11,4 +11,5 @@ install:
install -m 644 shared/prestoRepo.py $(DESTDIR)/usr/share/presto
install -m 644 shared/prestomdparser.py $(DESTDIR)/usr/share/presto
install -m 644 shared/prestoTransaction.py $(DESTDIR)/usr/share/presto
+ install -m 644 shared/prestoLog.py $(DESTDIR)/usr/share/presto
install -m 644 shared/deltarpm.py $(DESTDIR)/usr/share/presto
diff --git a/presto.py b/presto.py
index 1427a90..3db6e93 100644
--- a/presto.py
+++ b/presto.py
@@ -29,12 +29,15 @@ import deltarpm
from prestoRepo import PrestoRepository
from prestomdparser import PrestoMDParser
import prestoTransaction
+import prestoLog
requires_api_version = '2.1'
+LOG_FILE = "/var/log/presto.log"
plugin_type = (TYPE_INTERACTIVE,)
rpm_size = 0
drpm_size = 0
+was_drpm = False
# Configuration stuff
def config_hook(conduit):
@@ -74,6 +77,7 @@ def prereposetup_hook(conduit):
def postresolve_hook(conduit):
global rpm_size
global drpm_size
+ global was_drpm
opts, commands = conduit.getCmdLine()
if not opts.disablepresto:
@@ -85,6 +89,7 @@ def postresolve_hook(conduit):
# If a drpm was found, change certain package information so it reflects
# the drpm, not the rpm.
if chosen_drpm != None:
+ was_drpm = True
rpm_size += int(newpkg.po.simple['packagesize'])
drpm_size += int(chosen_drpm['size'])
newpkg.po.hasdrpm = True
@@ -123,8 +128,10 @@ def postresolve_hook(conduit):
del active_repo.p_repo
def postdownload_hook(conduit):
+ global was_drpm
+
opts, commands = conduit.getCmdLine()
- if not opts.disablepresto:
+ if not opts.disablepresto and was_drpm:
failure = False
# Cycle through packages to see if we've downloaded a deltarpm
conduit.info(2, "Rebuilding full packages from deltas")
@@ -171,8 +178,11 @@ def postdownload_hook(conduit):
def posttrans_hook(conduit):
global rpm_size
global drpm_size
+ global LOG_FILE
if rpm_size > 0:
+ prestoLog.log(conduit, LOG_FILE, rpm_size, drpm_size)
+
conduit.info(2, "Size of all updates downloaded from Presto-enabled repositories: %i bytes" % drpm_size)
conduit.info(2, "Size updates would have been downloaded if Presto wasn't enabled: %i bytes" % rpm_size)
conduit.info(2, "This is a savings of %i percent" % (100 - ((drpm_size * 100) / rpm_size)))
diff --git a/shared/prestoLog.py b/shared/prestoLog.py
new file mode 100644
index 0000000..3c0c1e6
--- /dev/null
+++ b/shared/prestoLog.py
@@ -0,0 +1,71 @@
+# author: Jonathan Dieter <jdieter@gmail.com>
+#
+# 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 Library 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.
+# Copyright 2005 Duke University
+
+def log(conduit, LOG_FILE, rpm_size, drpm_size):
+ # Open log file for reading
+ try:
+ log_file = open(LOG_FILE, "r")
+ log_exists = True
+ except:
+ conduit.info(5, "Info: %s doesn't exist. Will create." % LOG_FILE)
+ log_exists = False
+
+ # Log file doesn't exist, create
+ if not log_exists:
+ try:
+ log_file = open(LOG_FILE, "w")
+ log_file.write("Download Size (without DRPM),Download Size (with DRPM),Percentage Savings,Total Percentage Savings\n")
+ log_file.close()
+ log_exists = True
+ except:
+ conduit.info(2, "Warning: Unable to write to %s" % LOG_FILE)
+ if log_exists:
+ try:
+ log_file = open(LOG_FILE, "r")
+ except:
+ conduit.info(2, "Warning: Unable to open %s for reading." % LOG_FILE)
+ log_exists = False
+
+ # Cycle through items already in log so we can come up with total savings
+ if log_exists:
+ total_rpm_size = 0
+ total_drpm_size = 0
+
+ # Get rid of header line
+ log_file.readline()
+
+ data = log_file.readline()
+ while data != "":
+ fc = data.find(",")
+ sc = data.find(",", fc + 1)
+ total_rpm_size += int(data[:fc])
+ total_drpm_size += int(data[fc + 1:sc])
+ data = log_file.readline()
+ log_file.close()
+ total_rpm_size += rpm_size
+ total_drpm_size += drpm_size
+
+ try:
+ log_file = open(LOG_FILE, "a")
+ except:
+ conduit.info(2, "Warning: Unable to open %s for writing." % LOG_FILE)
+ log_exists = False
+
+ # Write data to log
+ if log_exists:
+ log_file.write("%i,%i,%i,%i\n" % (rpm_size, drpm_size, 100 - ((drpm_size * 100) / rpm_size), 100 - ((total_drpm_size * 100) / total_rpm_size)))
+ log_file.close()