az önce non-interactive için eksik göndermişim.
This commit is contained in:
@@ -28,10 +28,13 @@ class SourceArchive:
|
|||||||
self.ctx = ctx
|
self.ctx = ctx
|
||||||
self.url = PUrl(self.ctx.spec.source.archiveUri)
|
self.url = PUrl(self.ctx.spec.source.archiveUri)
|
||||||
self.dest = join(config.archives_dir(), self.url.filename())
|
self.dest = join(config.archives_dir(), self.url.filename())
|
||||||
|
self.showProgress = None
|
||||||
|
|
||||||
def fetch(self, interactive=True):
|
def fetch(self, interactive=True):
|
||||||
if not self.isCached(interactive):
|
if not self.isCached(interactive):
|
||||||
fetchUrl(self.url, config.archives_dir(), displayProgress)
|
if interactive:
|
||||||
|
self.showProgress = displayProgress
|
||||||
|
fetchUrl(self.url, config.archives_dir(), self.showProgress)
|
||||||
|
|
||||||
def isCached(self, interactive=True):
|
def isCached(self, interactive=True):
|
||||||
if not access(self.dest, R_OK):
|
if not access(self.dest, R_OK):
|
||||||
|
|||||||
+25
-23
@@ -2,12 +2,14 @@
|
|||||||
import unittest
|
import unittest
|
||||||
import os
|
import os
|
||||||
from os.path import exists as pathexists
|
from os.path import exists as pathexists
|
||||||
from os.path import basename, islink
|
from os.path import basename, islink, join
|
||||||
|
|
||||||
from pisi import archive
|
from pisi import archive
|
||||||
|
from pisi import sourcearchive
|
||||||
from pisi import fetcher
|
from pisi import fetcher
|
||||||
from pisi import util
|
from pisi import util
|
||||||
from pisi import context
|
from pisi import context
|
||||||
|
from pisi import purl
|
||||||
|
|
||||||
class ArchiveFileTestCase(unittest.TestCase):
|
class ArchiveFileTestCase(unittest.TestCase):
|
||||||
# def setUp(self):
|
# def setUp(self):
|
||||||
@@ -16,16 +18,17 @@ class ArchiveFileTestCase(unittest.TestCase):
|
|||||||
def testUnpackTar(self):
|
def testUnpackTar(self):
|
||||||
ctx = context.BuildContext("samples/popt/popt.pspec")
|
ctx = context.BuildContext("samples/popt/popt.pspec")
|
||||||
|
|
||||||
targetDir = ctx.pkg_work_dir()
|
achv = sourcearchive.SourceArchive(ctx)
|
||||||
fileName = os.path.basename(ctx.spec.source.archiveUri)
|
|
||||||
filePath = ctx.archives_dir() + '/' + fileName
|
|
||||||
achv = archive.Archive(filePath, ctx.spec.source.archiveType)
|
|
||||||
|
|
||||||
assert ctx.spec.source.archiveType == "targz"
|
assert ctx.spec.source.archiveType == "targz"
|
||||||
|
|
||||||
# unpacking is trivial with Archive()
|
# skip fetching and directly unpack the previously fetched (by
|
||||||
achv.unpack(targetDir)
|
# fetchertests) archive
|
||||||
|
if not achv.isCached(interactive=False):
|
||||||
|
achv.fetch(interactive=False)
|
||||||
|
achv.unpack()
|
||||||
|
|
||||||
|
targetDir = ctx.pkg_work_dir()
|
||||||
# but testing is hard
|
# but testing is hard
|
||||||
# "var/tmp/pisi/popt-1.7-3/work" (targetDir)
|
# "var/tmp/pisi/popt-1.7-3/work" (targetDir)
|
||||||
assert pathexists(targetDir + "/popt-1.7")
|
assert pathexists(targetDir + "/popt-1.7")
|
||||||
@@ -39,18 +42,14 @@ class ArchiveFileTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
def testUnpackZip(self):
|
def testUnpackZip(self):
|
||||||
ctx = context.BuildContext("tests/sandbox/sandbox.pspec")
|
ctx = context.BuildContext("tests/sandbox/sandbox.pspec")
|
||||||
fetch = fetcher.Fetcher(ctx.spec.source)
|
|
||||||
fetch.fetch()
|
|
||||||
|
|
||||||
targetDir = ctx.pkg_work_dir()
|
|
||||||
|
|
||||||
assert ctx.spec.source.archiveType == "zip"
|
assert ctx.spec.source.archiveType == "zip"
|
||||||
|
|
||||||
fileName = os.path.basename(ctx.spec.source.archiveUri)
|
achv = sourcearchive.SourceArchive(ctx)
|
||||||
filePath = ctx.archives_dir() + '/' + fileName
|
achv.fetch(interactive=False)
|
||||||
achv = archive.Archive(filePath, ctx.spec.source.archiveType)
|
achv.unpack(cleanDir=True)
|
||||||
achv.unpack(targetDir)
|
|
||||||
|
|
||||||
|
targetDir = ctx.pkg_work_dir()
|
||||||
assert pathexists(targetDir + "/sandbox")
|
assert pathexists(targetDir + "/sandbox")
|
||||||
|
|
||||||
testfile = targetDir + "/sandbox/borek.cs"
|
testfile = targetDir + "/sandbox/borek.cs"
|
||||||
@@ -68,10 +67,9 @@ class ArchiveFileTestCase(unittest.TestCase):
|
|||||||
# first unpack our dear sandbox.zip
|
# first unpack our dear sandbox.zip
|
||||||
ctx = context.BuildContext("tests/sandbox/sandbox.pspec")
|
ctx = context.BuildContext("tests/sandbox/sandbox.pspec")
|
||||||
targetDir = ctx.pkg_work_dir()
|
targetDir = ctx.pkg_work_dir()
|
||||||
fileName = os.path.basename(ctx.spec.source.archiveUri)
|
achv = sourcearchive.SourceArchive(ctx)
|
||||||
filePath = ctx.archives_dir() + '/' + fileName
|
achv.fetch(interactive=False)
|
||||||
achv = archive.Archive(filePath, ctx.spec.source.archiveType)
|
achv.unpack(cleanDir=True)
|
||||||
achv.unpack(targetDir)
|
|
||||||
del achv
|
del achv
|
||||||
|
|
||||||
newZip = targetDir + "/new.zip"
|
newZip = targetDir + "/new.zip"
|
||||||
@@ -85,12 +83,16 @@ class ArchiveFileTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
def testUnpackZipCond(self):
|
def testUnpackZipCond(self):
|
||||||
ctx = context.BuildContext("tests/sandbox/sandbox.pspec")
|
ctx = context.BuildContext("tests/sandbox/sandbox.pspec")
|
||||||
fetch = fetcher.Fetcher(ctx.spec.source)
|
url = purl.PUrl(ctx.spec.source.archiveUri)
|
||||||
fetch.fetch()
|
|
||||||
targetDir = ctx.pkg_work_dir()
|
targetDir = ctx.pkg_work_dir()
|
||||||
|
filePath = join(ctx.archives_dir(), url.filename())
|
||||||
|
|
||||||
|
# check cached
|
||||||
|
if util.sha1_file(filePath) != ctx.spec.source.archiveSHA1:
|
||||||
|
fetch = fetcher.Fetcher(ctx.spec.source.archiveUri, targetDir)
|
||||||
|
fetch.fetch()
|
||||||
assert ctx.spec.source.archiveType == "zip"
|
assert ctx.spec.source.archiveType == "zip"
|
||||||
fileName = os.path.basename(ctx.spec.source.archiveUri)
|
|
||||||
filePath = ctx.archives_dir() + '/' + fileName
|
|
||||||
achv = archive.Archive(filePath, ctx.spec.source.archiveType)
|
achv = archive.Archive(filePath, ctx.spec.source.archiveType)
|
||||||
achv.unpack_files(["sandbox/borek.cs"], targetDir)
|
achv.unpack_files(["sandbox/borek.cs"], targetDir)
|
||||||
assert pathexists(targetDir + "/sandbox")
|
assert pathexists(targetDir + "/sandbox")
|
||||||
|
|||||||
Reference in New Issue
Block a user