diff --git a/src/fetcher.py b/src/fetcher.py index fad3194e..49e520cb 100755 --- a/src/fetcher.py +++ b/src/fetcher.py @@ -29,14 +29,14 @@ class Fetcher: self.percent = 0 self.rate = 0 self.percentHook = None - - def fetch (self): - """Return value: Fetched file's full path..""" from string import split u = urlparse.urlparse(self.uri) self.scheme, self.netloc, self.filepath = u[0], u[1], u[2] self.filename = split(self.filepath, "/")[-1:][0] + def fetch (self): + """Return value: Fetched file's full path..""" + if self.filename == "": self.err("filename error") diff --git a/src/pisi-build b/src/pisi-build index 3164fb6f..2c6124e4 100755 --- a/src/pisi-build +++ b/src/pisi-build @@ -51,11 +51,12 @@ def main(): util.information("Fetching source from: %s (be patient)\n" % pb.spec.archiveUri) pb.fetchArchive(doProgress) util.information("Source archive is stored: %s/%s\n" %(pisiconfig.archives_dir, pb.archiveName)) -# pb.unpackArchive() -# pb.applyPatches() -# pb.buildSource() -# pb.installTarget() -# pb.buildPisiPackage() + # pb.unpackArchive() + # pb.applyPatches() + # pb.buildSource() + # pb.installTarget() + + pb.buildPackages() if __name__ == "__main__": diff --git a/src/pisibuild.py b/src/pisibuild.py index d89f0e3e..b90c7152 100644 --- a/src/pisibuild.py +++ b/src/pisibuild.py @@ -1,20 +1,22 @@ # -*- coding: utf-8 -*- # python standard library +import os from os.path import basename from specfile import SpecFile from fetcher import Fetcher # from archive import Archive # import pisipackage -# import pisiutils # patch, fileutils? +import util import pisiconfig + class PisiBuildError(Exception): pass class PisiBuild: - """PisiBuild class, provides the package build and creation rutines""" + """PisiBuild class, provides the package build and creation routines""" def __init__(self, pspecfile): self.pspecfile = pspecfile spec = SpecFile() @@ -29,9 +31,31 @@ class PisiBuild: """fetch an archive and store to pisiconfig.archives_dir using fether.Fetcher""" fetch = Fetcher(self.spec.archiveUri) + + # check if source already cached + destpath = fetch.filedest + "/" + fetch.filename + if os.access(destpath, os.R_OK): + if util.md5_file(destpath)==self.spec.archiveMD5: + util.information(fetch.filename + " cached") + return + if percentHook: fetch.percentHook = percentHook fetch.fetch() def unpackArchive(self): pass + + def applyPatches(self): + pass + + def buildSource(self): + pass + + def installTarget(self): + pass + + def buildPackages(self): + for package in self.spec.packages: + util.information("** Building package " % package.name); + diff --git a/src/specfile.py b/src/specfile.py index 0a7e987b..9517e945 100644 --- a/src/specfile.py +++ b/src/specfile.py @@ -50,23 +50,22 @@ class SpecFile(XmlFile): archiveNode = self.getNode("Source/Archive") self.archiveUri = getNodeText(archiveNode).strip() self.archiveType = getNodeAttribute(archiveNode, "archType") - self.archiveHash = getNodeAttribute(archiveNode, "md5sum") + self.archiveMD5 = getNodeAttribute(archiveNode, "md5sum") patchElts = self.getChildElts("Source/Patches") - patches = [ PatchInfo(p) for p in patchElts ] - for x in patches: + self.patches = [ PatchInfo(p) for p in patchElts ] + for x in self.patches: print "patch fn:", x.filename print "patch ct:", x.compressionType buildDepElts = self.getChildElts("Source/BuildDependencies") - buildDeps = [DepInfo(d) for d in buildDepElts] - for x in buildDeps: + self.buildDeps = [DepInfo(d) for d in buildDepElts] + for x in self.buildDeps: print "dep nm:", x.package print "dep vf:", x.versionFrom # find all binary packages packageElts = self.getAllNodes("Package") - packages = [PackageInfo(p) for p in packageElts] - print packages - for x in packages: + self.packages = [PackageInfo(p) for p in packageElts] + for x in self.packages: print 'package', x.name def verify(self): diff --git a/src/util.py b/src/util.py index b826cb5a..5fd31aaa 100644 --- a/src/util.py +++ b/src/util.py @@ -3,7 +3,7 @@ import os import sys -import string +import md5 def information(message): sys.stdout.write(message) @@ -22,6 +22,13 @@ def check_dir(dir): check_dir(parent_dir) os.mkdir(dir) +def md5_file(filename): + m = md5.new() + f = file(filename, 'rb') + for l in f: + m.update(l) + return m.hexdigest() + # run a command non-interactively def run_batch(cmd): print 'running ', cmd