casprint | 68 ++++++++++++++++++++++------------------------------
lib/cas/rpmutils.py | 16 ++++++++----
2 files changed, 41 insertions(+), 43 deletions(-)
New commits:
commit ba98f0cfab10a3291f70298ae02d889059e7fa57
Author: Adam Stokes <adam(a)conans.battleaxe>
Date: Tue Oct 21 21:35:34 2008 -0400
re-worked casprint
diff --git a/lib/cas/rpmutils.py b/lib/cas/rpmutils.py
index 23b024b..5cecce4 100644
--- a/lib/cas/rpmutils.py
+++ b/lib/cas/rpmutils.py
@@ -37,14 +37,15 @@ class Analyze(object):
return ".%s" % (i,)
else:
return hdr["FILENAMES"]
-
+
class Tools(object):
""" provide file alteration tools
"""
def __init__(self):
pass
- def extract(self, rpm, dst, tool="/usr/bin/rpm2cpio", filter="*/vmlinux"):
+ def extract(self, rpm, dst, tool="/usr/bin/rpm2cpio",
+ filter="*/vmlinux", return_results=True):
""" extract file(s) from rpm
"""
self.rpm = rpm
@@ -53,15 +54,20 @@ class Tools(object):
self.rpm2cpio = tool
self.cpio = "/bin/cpio"
self.cpio_args = "-imud"
+ self.filter_results = []
# change to destination directory
if not os.path.isdir(self.dst):
os.makedirs(self.dst)
os.chdir(self.dst)
-
+
# pipe to handle extraction, e.g. rpm2cpio kernel.rpm | cpio -imud */vmlinux
p1 = Popen([self.rpm2cpio, self.rpm], stdout=PIPE)
- (out, err) = Popen([self.cpio,self.cpio_args,self.filter], stdin=p1.stdout,
- stdout=open(os.devnull, "w"),stderr=open(os.devnull,"w")).communicate()
+ (out, err) = Popen([self.cpio,self.cpio_args,self.filter], stdin=p1.stdout,
+ stdout=open(os.devnull, "w"),stderr=PIPE).communicate()
+ if return_results:
+ for item in out.stderr.readlines():
+ self.filter_results.append(os.path.join(self.dst,item))
+ return self.filter_results
return
commit a605acbf91a5c0b2fb123d675605dd6b4a5cab3b
Author: Adam Stokes <adam(a)conans.battleaxe>
Date: Tue Oct 21 21:34:48 2008 -0400
reworking casprint to not store debugs locally and use the debuginfo
rpm packages as main storage.
diff --git a/casprint b/casprint
index e8656da..eca970b 100755
--- a/casprint
+++ b/casprint
@@ -22,31 +22,20 @@ RPMS = config.get("settings","rpms")
DEBUGS = config.get("settings","debugs")
DPRINT = config.get("settings","dprint")
-class CasTimeStampHandler(object):
- def __init__(self):
- self.cmd = ["find", "-L", DEBUGS, "-iname", "vmlinux"]
- self.tool = CoreTool()
- self.util = Utilities()
- self.debugList = []
-
- def run(self):
- pipe = Popen(self.cmd, stdout=PIPE, stderr=PIPE)
- for line in pipe.stdout:
- vmlinux = line.strip()
- tstamp = CoreTool()
- timestamp = tstamp.timestamp(vmlinux)
- self.debugList.append((vmlinux,timestamp))
- sprint("(timestamp) %-100s" % (os.path.realpath(vmlinux),))
- self.util.save(self.debugList, RPMS)
- return
-
class CasDatabaseHandler(object):
def __init__(self):
self.util = Utilities()
if os.path.isfile(RPMS):
self.debugList = self.util.load(RPMS)
else:
- self.debugList = []
+ self.debugList = {}
+
+ def rpmExist(self, rpm):
+ """ checks existence of rpm in db
+ """
+ if self.debugList.has_key(rpm):
+ return True
+ return False
def run(self):
rpms = []
@@ -58,11 +47,19 @@ class CasDatabaseHandler(object):
totalRpms = len(rpms)
count = 0
for x in rpms:
- count = count + 1
- dst = os.path.join(DEBUGS, str(count))
- rpmTool = Tools()
- rpmTool.extract(x, dst)
- sprint("(extracted) [%d/%d] %-100s" % (count, totalRpms, os.path.basename(x)))
+ if not self.rpmExist(x):
+ count = count + 1
+ dst = os.path.join(DEBUGS, str(count))
+ rpmTool = Tools()
+ results = rpmTool.extract(x, dst)
+ sprint("(extracted) [%d/%d] %-100s" % (count, totalRpms, os.path.basename(x)))
+ for item in results:
+ vmlinux = item.strip()
+ stamper = CoreTool()
+ timestamp = stamper.timestamp(vmlinux)
+ self.debugList[x] = (vmlinux, timestamp)
+ sprint("(timestamp) %-100s" % (os.path.realpath(vmlinux),))
+ self.util.save(self.debugList, RPMS)
return
class CasprintApplication(object):
@@ -70,11 +67,9 @@ class CasprintApplication(object):
self.parse_options(args)
def parse_options(self, args):
- parser = optparse.OptionParser(usage="casprint -n -t")
- parser.add_option("-n","--new", dest="newCasDB",
- help="Build new CAS database", action="store_true")
- parser.add_option("-t","--timestamp", dest="timestamp",
- help="Timestamp existing debug kernels", action="store_true")
+ parser = optparse.OptionParser(usage="casprint -b")
+ parser.add_option("-b","--build", dest="buildDB",
+ help="Build CAS DB", action="store_true")
self.opts, args = parser.parse_args()
def run(self):
@@ -84,20 +79,17 @@ class CasprintApplication(object):
util = Utilities()
if os.getuid() is not 0:
raise RuntimeError, "You must be root(0), instead you are id(%d)" % (os.getuid())
- if not os.path.isdir(os.path.dirname(RPMS)):
+ if not os.path.isdir(os.path.dirname(RPMS)):
util.mkdir(RPMS)
- if not os.path.isdir(DEBUGS):
+ if not os.path.isdir(DEBUGS):
util.mkdir(DEBUGS)
- if self.opts.newCasDB:
- dprint("Running a new cas database instance.", DPRINT)
+ if self.opts.buildDB:
+ dprint("Building CAS DB instance.", DPRINT)
dbHandler = CasDatabaseHandler().run()
- elif self.opts.timestamp:
- dprint("Building an updated cache of timestamps on existing debugs.", DPRINT)
- timestampHandler = CasTimeStampHandler().run()
else:
- raise RuntimeError("You must define either -n for a new CAS database or \n"
- "-t to update existing debugs")
+ dprint("Please define -b switch to update the CAS database\n", DPRINT)
+ raise sys.exit(1)
if __name__=="__main__":
app = CasprintApplication(sys.argv[1:])