backend/common/rhnLib.py | 10 ++++++++++
backend/satellite_tools/disk_dumper/dumper.py | 24 +++++-------------------
backend/satellite_tools/syncCache.py | 15 +++------------
3 files changed, 18 insertions(+), 31 deletions(-)
New commits:
commit 3911fde5bbbc39aaec436caaca649767a69fa786
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Thu May 27 16:47:17 2010 +0200
removed local hash_object_id() and reused rhnLib.hash_object_id()
diff --git a/backend/satellite_tools/disk_dumper/dumper.py
b/backend/satellite_tools/disk_dumper/dumper.py
index 40d6dc0..61c915f 100644
--- a/backend/satellite_tools/disk_dumper/dumper.py
+++ b/backend/satellite_tools/disk_dumper/dumper.py
@@ -1328,7 +1328,7 @@ class ShortPackagesDumper(CachedDumper,
exportLib.ShortPackagesDumper):
def _get_key(self, params):
package_id = params['package_id']
- hash_val = hash_object_id(package_id, 100)
+ hash_val = rhnLib.hash_object_id(package_id, 2)
return "xml-short-packages/%s/rhn-package-short-%s.xml" % (
hash_val, package_id)
@@ -1382,7 +1382,7 @@ class PackagesDumper(CachedDumper, exportLib.PackagesDumper):
def _get_key(self, params):
package_id = params['package_id']
- hash_val = hash_object_id(package_id, 100)
+ hash_val = rhnLib.hash_object_id(package_id, 2)
return "xml-packages/%s/rhn-package-%s.xml" % (hash_val, package_id)
def _dump_subelement(self, data):
@@ -1420,7 +1420,7 @@ class SourcePackagesDumper(CachedDumper,
exportLib.SourcePackagesDumper):
def _get_key(self, params):
package_id = params['package_id']
- hash_val = hash_object_id(package_id, 100)
+ hash_val = rhnLib.hash_object_id(package_id, 2)
return "xml-packages/%s/rhn-source-package-%s.xml" % (hash_val,
package_id)
def _dump_subelement(self, data):
@@ -1454,7 +1454,7 @@ class ErrataDumper(CachedDumper, exportLib.ErrataDumper):
def _get_key(self, params):
errata_id = params['errata_id']
- hash_val = hash_object_id(errata_id, 10)
+ hash_val = rhnLib.hash_object_id(errata_id, 1)
return "xml-errata/%s/rhn-erratum-%s.xml" % (hash_val, errata_id)
def _dump_subelement(self, data):
@@ -1488,7 +1488,7 @@ class ErrataDumperEx(CachedDumper, exportLib.ErrataSynopsisDumper):
def _get_key(self, params):
errata_id = params['errata_id']
- hash_val = hash_object_id(errata_id, 10)
+ hash_val = rhnLib.hash_object_id(errata_id, 1)
return "xml-errata/%s/rhn-erratum-%s.xml" % (hash_val, errata_id)
def _dump_subelement(self, data):
@@ -1529,20 +1529,6 @@ class KickstartableTreesDumper(CachedDumper,
exportLib.KickstartableTreesDumper)
log_debug(6, data)
return exportLib.KickstartableTreesDumper.dump_subelement(self, data)
-def hash_object_id(obj_id, factor):
- """ This looks complicated; it returns the (integer part of)
- obj_id, modulo factor
- The string is left padded with as many 0 chars as necessary to
- match factor
- XXX This is copied from satellite_tools.diskImportLib.hashPackageID -
- should figure out a way to share it -- misa
- """
- # Make sure obj_id is a string
- obj_id = str(obj_id)
- format = int(math.ceil(math.log10(factor)))
- format = "%%0%sd" % format
- return format % (int(string.split(obj_id, '-')[-1]) % factor, )
-
class ClosedConnectionError(Exception):
pass
commit 4c3b684480245f9c6ec6001158c3cbde38243dd8
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Thu May 27 16:43:30 2010 +0200
BaseCache._hash_object_id() moved to rhnLib.hash_object_id()
diff --git a/backend/common/rhnLib.py b/backend/common/rhnLib.py
index 12c2704..0905f9b 100644
--- a/backend/common/rhnLib.py
+++ b/backend/common/rhnLib.py
@@ -172,3 +172,13 @@ def fix_url(url, scheme="http", path="/"):
_fragment))
return url
+def hash_object_id(self, object_id, factor):
+ """Given an object id (assumed to be <label>-<number>),
returns the
+ last few digits for the number. For instance, (812345, 3) should
+ return 345"""
+ # Grab the digits after -
+ num_id = string.split(object_id, '-')[-1]
+ # get last 'factor' numbers
+ num_id = num_id[-factor:]
+ return num_id.rjust(factor,'0')
+
diff --git a/backend/satellite_tools/syncCache.py b/backend/satellite_tools/syncCache.py
index c8662fb..c510a74 100644
--- a/backend/satellite_tools/syncCache.py
+++ b/backend/satellite_tools/syncCache.py
@@ -23,6 +23,7 @@ import string
# rhn imports:
from common import CFG, rhnCache
+from common.rhnLib import hash_object_id
# NOTE: this is a python 2.2-ism
__all__ = []
@@ -54,16 +55,6 @@ class BaseCache:
def _get_key(self, object_id):
raise NotImplementedError()
- def _hash_object_id(self, object_id, factor):
- """Given an object id (assumed to be
<label>-<number>), returns the
- last few digits for the number. For instance, (812345, 3) should
- return 345"""
- # Grab the digits after -
- num_id = string.split(object_id, '-')[-1]
- # get last 'factor' numbers
- num_id = num_id[-factor:]
- return num_id.rjust(factor,'0')
-
class ChannelCache(BaseCache):
def _get_key(self, object_id):
return os.path.join("satsync", "channels", str(object_id))
@@ -71,7 +62,7 @@ class ChannelCache(BaseCache):
class BasePackageCache(BaseCache):
_subdir = "__unknown__"
def _get_key(self, object_id):
- hash_val = self._hash_object_id(object_id, 2)
+ hash_val = hash_object_id(object_id, 2)
return os.path.join("satsync", self._subdir, hash_val, str(object_id))
class ShortPackageCache(BasePackageCache):
@@ -87,7 +78,7 @@ class SourcePackageCache(BasePackageCache):
class ErratumCache(BaseCache):
_subdir = "errata"
def _get_key(self, object_id):
- hash_val = self._hash_object_id(object_id, 1)
+ hash_val = hash_object_id(object_id, 1)
return os.path.join("satsync", self._subdir, hash_val, str(object_id))
class KickstartableTreesCache(BaseCache):