summaryrefslogtreecommitdiffstats
path: root/yum-presto/shared/prestoLog.py
diff options
context:
space:
mode:
Diffstat (limited to 'yum-presto/shared/prestoLog.py')
-rw-r--r--yum-presto/shared/prestoLog.py71
1 files changed, 71 insertions, 0 deletions
diff --git a/yum-presto/shared/prestoLog.py b/yum-presto/shared/prestoLog.py
new file mode 100644
index 0000000..3c0c1e6
--- /dev/null
+++ b/yum-presto/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()