backend/common/rhnMail.py | 10 +++--
backend/satellite_tools/messages.py | 68 +++++++++++++++++++-----------------
backend/satellite_tools/satsync.py | 43 +++++++++++++++++++++-
3 files changed, 85 insertions(+), 36 deletions(-)
New commits:
commit 88a9273544879bb86db5cea5dc4288cb2c41bb08
Author: Miroslav Suchý <msuchy(a)redhat.com>
Date: Thu May 5 11:47:15 2011 +0200
683200 - send emails as utf-8
diff --git a/backend/common/rhnMail.py b/backend/common/rhnMail.py
index f7aaa60..b96e2b9 100644
--- a/backend/common/rhnMail.py
+++ b/backend/common/rhnMail.py
@@ -22,6 +22,7 @@ import smtplib
from rhnConfig import CFG
from rhnLog import log_error
+from rhn.connections import idn_pune_to_unicode
# check if the headers have the minimum required fields
def __check_headers(h):
@@ -29,11 +30,13 @@ def __check_headers(h):
# does not look like a dictionary
h = {}
if not h.has_key("Subject"):
- h["Subject"] = "RHN System Mail From %s" % os.uname()[1]
+ h["Subject"] = "RHN System Mail From %s" %
idn_pune_to_unicode(os.uname()[1])
if not h.has_key("To"):
to = CFG.TRACEBACK_MAIL
else:
to = h["To"]
+ if not ("Content-Type" in h):
+ h["Content-Type"] = "text/plain; charset=utf-8"
if type(to) in [type([]), type(())]:
toaddrs = to
to = string.join(to, ', ')
@@ -49,8 +52,9 @@ def send(headers, body, sender = None, lazy = 0):
sender = headers["From"]
joined_headers = ''
for h in headers.keys():
- joined_headers += "%s: %s\n" % (h, headers[h])
+ joined_headers += "%s: %s\n" % (h, headers[h].encode('utf-8'))
server = smtplib.SMTP('localhost')
- server.sendmail(sender, toaddrs, "%s\n%s\n" % (joined_headers, body))
+ msg = "%s\n%s\n" % (joined_headers, body)
+ server.sendmail(sender, toaddrs, msg.encode('utf-8'))
server.quit()
commit bd0f7cabcac195d08f6c11a79cfb662681872bc7
Author: Miroslav Suchý <msuchy(a)redhat.com>
Date: Thu May 5 11:45:23 2011 +0200
683200 - convert hostname in subject from pune to unicode
diff --git a/backend/satellite_tools/satsync.py b/backend/satellite_tools/satsync.py
index 07da5d8..4dfaabe 100644
--- a/backend/satellite_tools/satsync.py
+++ b/backend/satellite_tools/satsync.py
@@ -27,7 +27,7 @@ import time
import types
import exceptions
from optparse import Option, OptionParser
-from rhn.connections import idn_ascii_to_pune
+from rhn.connections import idn_ascii_to_pune, idn_pune_to_unicode
import gettext
t = gettext.translation('spacewalk-backend-server', fallback=True)
@@ -355,7 +355,7 @@ def sendMail(forceEmail=0):
if body:
print _("+++ sending log as an email +++")
headers = {
- 'Subject' : _('RHN Management Satellite sync. report from
%s') % os.uname()[1],
+ 'Subject' : _('RHN Management Satellite sync. report from
%s') % idn_pune_to_unicode(os.uname()[1]),
}
sndr = CFG.get('traceback_mail', 'root@localhost')
rhnMail.send(headers, body, sender=sndr)
commit 6f658cfa23f1eada2b2022d86b6a218b6daa5a06
Author: Miroslav Suchý <msuchy(a)redhat.com>
Date: Thu May 5 10:38:28 2011 +0200
localize satsync messages
diff --git a/backend/satellite_tools/messages.py b/backend/satellite_tools/messages.py
index 6a4c7a3..ac671f2 100644
--- a/backend/satellite_tools/messages.py
+++ b/backend/satellite_tools/messages.py
@@ -20,63 +20,67 @@
All rights reserved.
"""
-failed_step = """
+import gettext
+t = gettext.translation('spacewalk-backend-server', fallback=True)
+_ = t.ugettext
+
+failed_step = _("""
ERROR: executing step %s. Error is:
%s
-"""
+""")
-file_dir_error = """
+file_dir_error = _("""
ERROR: there was a problem accessing the channel data from your temporary
repository. Did you migrate all of the data from the channel ISOs
do this directory? If so, please recheck the channels ISOs, ensure
that you have them all, and then iteratively remount and repopulate
the temporary repository (%s).
-"""
+""")
-syncer_error = """
+syncer_error = _("""
ERROR: there was a problem synchronizing the information.
Error message: %s
-"""
+""")
-iss_not_available = """
+iss_not_available = _("""
ERROR: The Server listed within iss-parent is not configured for ISS
capability.
Please review your configuration before trying again.
-"""
+""")
-parent_channel_error = """
+parent_channel_error = _("""
ERROR: a child-channel cannot be synced without its parent being synced as
well. A parent needs to be either (a) previously synced or (b) synced
in tandem with the desired child-channel. Missing parents for this
transaction:
%s
-"""
+""")
-invalid_channel_family_error = """
+invalid_channel_family_error = _("""
ERROR: you are not entitled to sync a channel in this set of channels.
Please contact your sales rep or RHN contact
-%s"""
+%s""")
-not_enough_diskspace = " ERROR: not enough free space (%s KB) on device."
+not_enough_diskspace = _(" ERROR: not enough free space (%s KB) on device.")
-package_fetch_successful = " %3d/%s Fetch successful: %s (%s bytes)"
-package_fetch_extinct = " %3d/%s Extinct package: %s"
-package_fetch_total_size = " Total size: %s"
-package_fetch_remain_size_time = " Downloaded %s of %s. Estimated remaining
time: %s"
-package_fetch_failed = " %3d/%s Fetch unsuccessful: %s"
-package_fetch_summary = " RPM fetch summary: %s"
-package_fetch_summary_success = " success: %d"
-package_fetch_summary_failed = " failed: %d"
-package_fetch_summary_extinct = " extinct: %d"
+package_fetch_successful = _(" %3d/%s Fetch successful: %s (%s bytes)")
+package_fetch_extinct = _(" %3d/%s Extinct package: %s")
+package_fetch_total_size = _(" Total size: %s")
+package_fetch_remain_size_time = _(" Downloaded %s of %s. Estimated remaining
time: %s")
+package_fetch_failed = _(" %3d/%s Fetch unsuccessful: %s")
+package_fetch_summary = _(" RPM fetch summary: %s")
+package_fetch_summary_success = _(" success: %d")
+package_fetch_summary_failed = _(" failed: %d")
+package_fetch_summary_extinct = _(" extinct: %d")
-package_parsing = " Retrieving / parsing *relevant* package metadata: %s
(%s)"
-erratum_parsing = " Retrieving / parsing errata data: %s (%s)"
-kickstart_parsing = " Retrieving / parsing kickstart data: %s (%s)"
-kickstart_downloading = " Retrieving / parsing kickstart tree files: %s
(%s)"
-package_importing = " Importing *relevant* package metadata: %s (%s)"
-warning_slow = " * WARNING: this may be a slow process."
-link_channel_packages = "Linking packages to channels"
-errata_importing = " Importing *relevant* errata: %s (%s)"
-kickstart_import_nothing_to_do = " No new kickstartable tree to import"
-kickstart_importing = "Importing kickstartable trees (%d)"
-kickstart_imported = "Imported kickstartable trees (%d)"
+package_parsing = _(" Retrieving / parsing *relevant* package metadata: %s
(%s)")
+erratum_parsing = _(" Retrieving / parsing errata data: %s (%s)")
+kickstart_parsing = _(" Retrieving / parsing kickstart data: %s (%s)")
+kickstart_downloading = _(" Retrieving / parsing kickstart tree files: %s
(%s)")
+package_importing = _(" Importing *relevant* package metadata: %s (%s)")
+warning_slow = _(" * WARNING: this may be a slow process.")
+link_channel_packages = _("Linking packages to channels")
+errata_importing = _(" Importing *relevant* errata: %s (%s)")
+kickstart_import_nothing_to_do = _(" No new kickstartable tree to import")
+kickstart_importing = _("Importing kickstartable trees (%d)")
+kickstart_imported = _("Imported kickstartable trees (%d)")
commit ae519c1e17d43d0a93a3abff5ab9bcb866597c58
Author: Miroslav Suchý <msuchy(a)redhat.com>
Date: Thu May 5 10:31:16 2011 +0200
provide estimation about remaining time for downloading rpm
diff --git a/backend/satellite_tools/messages.py b/backend/satellite_tools/messages.py
index 3c67e3a..6a4c7a3 100644
--- a/backend/satellite_tools/messages.py
+++ b/backend/satellite_tools/messages.py
@@ -61,6 +61,8 @@ not_enough_diskspace = " ERROR: not enough free space (%s KB) on
device."
package_fetch_successful = " %3d/%s Fetch successful: %s (%s bytes)"
package_fetch_extinct = " %3d/%s Extinct package: %s"
+package_fetch_total_size = " Total size: %s"
+package_fetch_remain_size_time = " Downloaded %s of %s. Estimated remaining
time: %s"
package_fetch_failed = " %3d/%s Fetch unsuccessful: %s"
package_fetch_summary = " RPM fetch summary: %s"
package_fetch_summary_success = " success: %d"
diff --git a/backend/satellite_tools/satsync.py b/backend/satellite_tools/satsync.py
index 59d167f..07da5d8 100644
--- a/backend/satellite_tools/satsync.py
+++ b/backend/satellite_tools/satsync.py
@@ -18,6 +18,7 @@
# __lang. imports__
+import datetime
import os
import sys
import stat
@@ -1726,11 +1727,25 @@ Please contact your RHN representative""") %
(generation, sat_cert.generation))
pkgs_total = len(missing_fs_packages)
pkg_current = 0
cfg = config.initUp2dateConfig()
+ total_size = 0
+
+ #count size of missing packages
for package_id, path in missing_fs_packages:
pkg_current = pkg_current + 1
timestamp = short_package_collection.get_package_timestamp(package_id)
package = package_collection.get_package(package_id, timestamp)
+ total_size = total_size+package['package_size']
+
+ log(1, messages.package_fetch_total_size %
+ (self._bytes_to_fuzzy(total_size)))
+
+ processed_size = 0
+ start_time = round(time.time())
+ for package_id, path in missing_fs_packages:
+ pkg_current = pkg_current + 1
+ timestamp = short_package_collection.get_package_timestamp(package_id)
+ package = package_collection.get_package(package_id, timestamp)
checksum_type = package['checksum_type']
checksum = package['checksum']
package_size = package['package_size']
@@ -1791,7 +1806,15 @@ Please contact your RHN representative""") %
(generation, sat_cert.generation))
# Package successfully saved
filename = os.path.basename(rpmManip.relative_path)
+
+ # Determine downloaded size and remaining time
size = package['package_size']
+ processed_size = processed_size + size
+ current_time = round(time.time())
+ remain_time =
(datetime.timedelta(seconds=current_time-start_time))*(total_size/processed_size - 1)
+
+ log(1, messages.package_fetch_remain_size_time %
+ (self._bytes_to_fuzzy(processed_size), self._bytes_to_fuzzy(total_size),
remain_time))
log(1, messages.package_fetch_successful %
(pkg_current, pkgs_total, filename, size))
@@ -1818,6 +1841,22 @@ Please contact your RHN representative""") %
(generation, sat_cert.generation))
log(2, messages.package_fetch_summary_extinct % extinct_count,
notimeYN=1)
+ # Translate x bytes to string "x MB", "x GB" or "x kB"
+ def _bytes_to_fuzzy(self, bytes):
+ kilo=1024
+ mega=kilo*1024
+ giga=mega*1024
+ if (bytes/kilo == 0):
+ return "%d bytes" %(bytes)
+ elif (bytes/mega == 0):
+ return "%d kB" %(bytes / 1024)
+ elif (bytes/giga == 0):
+ mega_value=bytes / mega
+ return "%d.%d MB" %(mega_value, (bytes % mega) / kilo)
+ else:
+ giga_value=bytes / giga
+ return "%d.%d GB" %(giga_value, (bytes % giga) / mega)
+
def _get_package_stream(self, channel, package_id, nvrea, sources):
""" returns (filepath, stream), so in the case of a "wire
source",
the return value is, of course, (None, stream)