* implement MD5 based caching when downloading source
* specfile: fix: store variables in self
This commit is contained in:
+3
-3
@@ -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")
|
||||
|
||||
|
||||
+6
-5
@@ -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__":
|
||||
|
||||
+26
-2
@@ -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);
|
||||
|
||||
|
||||
+7
-8
@@ -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):
|
||||
|
||||
+8
-1
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user