* 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.percent = 0
|
||||||
self.rate = 0
|
self.rate = 0
|
||||||
self.percentHook = None
|
self.percentHook = None
|
||||||
|
|
||||||
def fetch (self):
|
|
||||||
"""Return value: Fetched file's full path.."""
|
|
||||||
from string import split
|
from string import split
|
||||||
u = urlparse.urlparse(self.uri)
|
u = urlparse.urlparse(self.uri)
|
||||||
self.scheme, self.netloc, self.filepath = u[0], u[1], u[2]
|
self.scheme, self.netloc, self.filepath = u[0], u[1], u[2]
|
||||||
self.filename = split(self.filepath, "/")[-1:][0]
|
self.filename = split(self.filepath, "/")[-1:][0]
|
||||||
|
|
||||||
|
def fetch (self):
|
||||||
|
"""Return value: Fetched file's full path.."""
|
||||||
|
|
||||||
if self.filename == "":
|
if self.filename == "":
|
||||||
self.err("filename error")
|
self.err("filename error")
|
||||||
|
|
||||||
|
|||||||
+6
-5
@@ -51,11 +51,12 @@ def main():
|
|||||||
util.information("Fetching source from: %s (be patient)\n" % pb.spec.archiveUri)
|
util.information("Fetching source from: %s (be patient)\n" % pb.spec.archiveUri)
|
||||||
pb.fetchArchive(doProgress)
|
pb.fetchArchive(doProgress)
|
||||||
util.information("Source archive is stored: %s/%s\n" %(pisiconfig.archives_dir, pb.archiveName))
|
util.information("Source archive is stored: %s/%s\n" %(pisiconfig.archives_dir, pb.archiveName))
|
||||||
# pb.unpackArchive()
|
# pb.unpackArchive()
|
||||||
# pb.applyPatches()
|
# pb.applyPatches()
|
||||||
# pb.buildSource()
|
# pb.buildSource()
|
||||||
# pb.installTarget()
|
# pb.installTarget()
|
||||||
# pb.buildPisiPackage()
|
|
||||||
|
pb.buildPackages()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
+26
-2
@@ -1,20 +1,22 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# python standard library
|
# python standard library
|
||||||
|
import os
|
||||||
from os.path import basename
|
from os.path import basename
|
||||||
|
|
||||||
from specfile import SpecFile
|
from specfile import SpecFile
|
||||||
from fetcher import Fetcher
|
from fetcher import Fetcher
|
||||||
# from archive import Archive
|
# from archive import Archive
|
||||||
# import pisipackage
|
# import pisipackage
|
||||||
# import pisiutils # patch, fileutils?
|
import util
|
||||||
import pisiconfig
|
import pisiconfig
|
||||||
|
|
||||||
|
|
||||||
class PisiBuildError(Exception):
|
class PisiBuildError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class PisiBuild:
|
class PisiBuild:
|
||||||
"""PisiBuild class, provides the package build and creation rutines"""
|
"""PisiBuild class, provides the package build and creation routines"""
|
||||||
def __init__(self, pspecfile):
|
def __init__(self, pspecfile):
|
||||||
self.pspecfile = pspecfile
|
self.pspecfile = pspecfile
|
||||||
spec = SpecFile()
|
spec = SpecFile()
|
||||||
@@ -29,9 +31,31 @@ class PisiBuild:
|
|||||||
"""fetch an archive and store to pisiconfig.archives_dir
|
"""fetch an archive and store to pisiconfig.archives_dir
|
||||||
using fether.Fetcher"""
|
using fether.Fetcher"""
|
||||||
fetch = Fetcher(self.spec.archiveUri)
|
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:
|
if percentHook:
|
||||||
fetch.percentHook = percentHook
|
fetch.percentHook = percentHook
|
||||||
fetch.fetch()
|
fetch.fetch()
|
||||||
|
|
||||||
def unpackArchive(self):
|
def unpackArchive(self):
|
||||||
pass
|
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")
|
archiveNode = self.getNode("Source/Archive")
|
||||||
self.archiveUri = getNodeText(archiveNode).strip()
|
self.archiveUri = getNodeText(archiveNode).strip()
|
||||||
self.archiveType = getNodeAttribute(archiveNode, "archType")
|
self.archiveType = getNodeAttribute(archiveNode, "archType")
|
||||||
self.archiveHash = getNodeAttribute(archiveNode, "md5sum")
|
self.archiveMD5 = getNodeAttribute(archiveNode, "md5sum")
|
||||||
patchElts = self.getChildElts("Source/Patches")
|
patchElts = self.getChildElts("Source/Patches")
|
||||||
patches = [ PatchInfo(p) for p in patchElts ]
|
self.patches = [ PatchInfo(p) for p in patchElts ]
|
||||||
for x in patches:
|
for x in self.patches:
|
||||||
print "patch fn:", x.filename
|
print "patch fn:", x.filename
|
||||||
print "patch ct:", x.compressionType
|
print "patch ct:", x.compressionType
|
||||||
buildDepElts = self.getChildElts("Source/BuildDependencies")
|
buildDepElts = self.getChildElts("Source/BuildDependencies")
|
||||||
buildDeps = [DepInfo(d) for d in buildDepElts]
|
self.buildDeps = [DepInfo(d) for d in buildDepElts]
|
||||||
for x in buildDeps:
|
for x in self.buildDeps:
|
||||||
print "dep nm:", x.package
|
print "dep nm:", x.package
|
||||||
print "dep vf:", x.versionFrom
|
print "dep vf:", x.versionFrom
|
||||||
|
|
||||||
# find all binary packages
|
# find all binary packages
|
||||||
packageElts = self.getAllNodes("Package")
|
packageElts = self.getAllNodes("Package")
|
||||||
packages = [PackageInfo(p) for p in packageElts]
|
self.packages = [PackageInfo(p) for p in packageElts]
|
||||||
print packages
|
for x in self.packages:
|
||||||
for x in packages:
|
|
||||||
print 'package', x.name
|
print 'package', x.name
|
||||||
|
|
||||||
def verify(self):
|
def verify(self):
|
||||||
|
|||||||
+8
-1
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import string
|
import md5
|
||||||
|
|
||||||
def information(message):
|
def information(message):
|
||||||
sys.stdout.write(message)
|
sys.stdout.write(message)
|
||||||
@@ -22,6 +22,13 @@ def check_dir(dir):
|
|||||||
check_dir(parent_dir)
|
check_dir(parent_dir)
|
||||||
os.mkdir(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
|
# run a command non-interactively
|
||||||
def run_batch(cmd):
|
def run_batch(cmd):
|
||||||
print 'running ', cmd
|
print 'running ', cmd
|
||||||
|
|||||||
Reference in New Issue
Block a user