* improve fetching code, fix bug 838

* add a function to find the parent of a path
* pxml: typo
This commit is contained in:
Eray Özkural
2005-11-19 20:42:11 +00:00
parent 2bde83880b
commit b2ad081a67
4 changed files with 100 additions and 86 deletions
+11 -7
View File
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Project SYSTEM "Project-3.8.dtd"> <!DOCTYPE Project SYSTEM "Project-3.8.dtd">
<!-- Project file for project pisi --> <!-- Project file for project pisi -->
<!-- Saved: 2005-11-17, 21:46:58 --> <!-- Saved: 2005-11-19, 21:48:29 -->
<!-- Copyright (C) 2005 PiSi Development Team, --> <!-- Copyright (C) 2005 PiSi Development Team, -->
<Project version="3.8"> <Project version="3.8">
<ProgLanguage mixed="0">Python</ProgLanguage> <ProgLanguage mixed="0">Python</ProgLanguage>
@@ -9,7 +9,7 @@
<Description>The package management software of Pardus distribution. <Description>The package management software of Pardus distribution.
</Description> </Description>
<Author>PiSi Development Team</Author> <Author>PiSi Development Team</Author>
<EmaIl></EmaIl> <Email></Email>
<Sources> <Sources>
<Source> <Source>
<Dir>tools</Dir> <Dir>tools</Dir>
@@ -222,10 +222,6 @@
<Dir>pisi</Dir> <Dir>pisi</Dir>
<Name>context.py</Name> <Name>context.py</Name>
</Source> </Source>
<Source>
<Dir>pisi</Dir>
<Name>sourcefetcher.py</Name>
</Source>
<Source> <Source>
<Dir>pisi</Dir> <Dir>pisi</Dir>
<Name>graph.py</Name> <Name>graph.py</Name>
@@ -434,6 +430,14 @@
<Dir>tools</Dir> <Dir>tools</Dir>
<Name>check-source-repo.py</Name> <Name>check-source-repo.py</Name>
</Source> </Source>
<Source>
<Dir>tests</Dir>
<Name>filetests.py</Name>
</Source>
<Source>
<Dir>pisi</Dir>
<Name>file.py</Name>
</Source>
</Sources> </Sources>
<Forms> <Forms>
</Forms> </Forms>
@@ -478,7 +482,7 @@
<FiletypeAssociation pattern="*.ui.h" type="FORMS" /> <FiletypeAssociation pattern="*.ui.h" type="FORMS" />
<FiletypeAssociation pattern="*.ui" type="FORMS" /> <FiletypeAssociation pattern="*.ui" type="FORMS" />
<FiletypeAssociation pattern="*.idl" type="INTERFACES" /> <FiletypeAssociation pattern="*.idl" type="INTERFACES" />
<FiletypeAssociation pattern="*.ptl" type="SOURCES" />
<FiletypeAssociation pattern="*.py" type="SOURCES" /> <FiletypeAssociation pattern="*.py" type="SOURCES" />
<FiletypeAssociation pattern="*.ptl" type="SOURCES" />
</FiletypeAssociations> </FiletypeAssociations>
</Project> </Project>
+79 -77
View File
@@ -26,7 +26,8 @@ _ = __trans.ugettext
import pisi import pisi
from pisi.specfile import SpecFile from pisi.specfile import SpecFile
import pisi.util as util import pisi.util as util
from pisi.util import join_path as join from pisi.util import join_path as join, parenturi
from pisi.file import File
import pisi.context as ctx import pisi.context as ctx
import pisi.dependency as dependency import pisi.dependency as dependency
import pisi.operations as operations import pisi.operations as operations
@@ -42,71 +43,13 @@ import pisi.component as component
class Error(pisi.Error): class Error(pisi.Error):
pass pass
class SourceFetcher(object): class SourceFetcher(object):
def __init__(self, url, authInfo=None):
self.url = url
if authInfo:
self.url.set_auth_info(authInfo)
self.location = dirname(self.url.uri)
pkgname = basename(dirname(self.url.path())) def fetch(self, url, appendDest=""):
self.dest = join(ctx.config.tmp_dir(), pkgname)
def fetch_all(self):
# fetch pspec file
self.fetch()
pspec = join(self.dest, self.url.filename())
self.spec = SpecFile()
self.spec.read(pspec)
self.fetch_actionsfile()
self.fetch_patches()
self.fetch_comarfiles()
self.fetch_additionalFiles()
return URI(pspec)
def fetch_actionsfile(self):
actionsuri = join(self.location, ctx.const.actions_file)
self.url.uri = actionsuri
self.fetch()
def fetch_patches(self):
spec = self.spec
for patch in spec.source.patches:
file_name = basename(patch.filename)
dir_name = dirname(patch.filename)
patchuri = join(self.location,
ctx.const.files_dir, dir_name, file_name)
self.url.uri = patchuri
target_dir = join(ctx.const.files_dir, dir_name)
self.fetch(target_dir)
def fetch_comarfiles(self):
spec = self.spec
for package in spec.packages:
for pcomar in package.providesComar:
comaruri = join(self.location,
ctx.const.comar_dir, pcomar.script)
self.url.uri = comaruri
self.fetch(ctx.const.comar_dir)
def fetch_additionalFiles(self):
spec = self.spec
for pkg in spec.packages:
for afile in pkg.additionalFiles:
file_name = basename(afile.filename)
dir_name = dirname(afile.filename)
afileuri = join(self.location,
ctx.const.files_dir, dir_name, file_name)
self.url.uri = afileuri
target_dir = join(ctx.const.files_dir, dir_name)
self.fetch(target_dir)
def fetch(self, appendDest=""):
from fetcher import fetch_url from fetcher import fetch_url
ctx.ui.info(_("Fetching %s") % self.url.uri) ctx.ui.info(_("Fetching %s") % url.get_uri())
dest = join(self.dest, appendDest) dest = join(self.dest, appendDest)
fetch_url(self.url, dest) fetch_url(self.url, dest)
@@ -157,18 +100,25 @@ class Builder:
"""Provides the package build and creation routines""" """Provides the package build and creation routines"""
#FIXME: this class and every other class must use URLs as paths! #FIXME: this class and every other class must use URLs as paths!
def __init__(self, pspecuri, authinfo = None): def __init__(self, specuri, authinfo = None):
if not isinstance(pspecuri, URI): # process args
pspecuri = URI(pspecuri) if not isinstance(specuri, URI):
specuri = URI(specuri)
if authinfo:
specuri.set_auth_info(authInfo)
if pspecuri.is_remote_file(): self.authinfo = authinfo
fs = SourceFetcher(pspecuri, authinfo)
# read spec file, we'll need it :)
self.set_spec_file(specuri)
if specuri.is_remote_file():
#make local here and fuck up #make local here and fuck up
pspecuri = fs.fetch_all() self.specdir = self.fetch_files()
else:
self.specdir = dirname(self.specuri)
self.set_spec_file(pspecuri)
self.specdir = os.path.dirname(os.path.realpath(pspecuri.get_uri()))
self.sourceArchive = SourceArchive(self.spec, self.pkg_work_dir()) self.sourceArchive = SourceArchive(self.spec, self.pkg_work_dir())
self.set_environment_vars() self.set_environment_vars()
@@ -177,9 +127,10 @@ class Builder:
self.actionGlobals = None self.actionGlobals = None
self.srcDir = None self.srcDir = None
def set_spec_file(self, pspecuri): def set_spec_file(self, specuri):
self.specuri = specuri
spec = SpecFile() spec = SpecFile()
spec.read(pspecuri, ctx.config.tmp_dir()) spec.read(specuri, ctx.config.tmp_dir())
self.spec = spec self.spec = spec
# directory accessor functions # directory accessor functions
@@ -221,9 +172,8 @@ class Builder:
self.patch_exists() self.patch_exists()
self.check_build_dependencies() self.check_build_dependencies()
self.fetch_files()
self.get_component() self.fetch_component()
self.fetch_source_archive() self.fetch_source_archive()
self.unpack_source_archive() self.unpack_source_archive()
@@ -260,10 +210,62 @@ class Builder:
os.environ["PATH"] = "/usr/lib/ccache/bin/:" + os.environ["PATH"] os.environ["PATH"] = "/usr/lib/ccache/bin/:" + os.environ["PATH"]
ctx.ui.info(_("CCache detected...")) ctx.ui.info(_("CCache detected..."))
def get_component(self): def fetch_files(self):
self.specdiruri = dirname(self.specuri.get_uri())
pkgname = basename(self.specdiruri)
self.destdir = join(ctx.config.tmp_dir(), pkgname)
#self.location = dirname(self.url.uri)
self.fetch_actionsfile()
self.fetch_patches()
self.fetch_comarfiles()
self.fetch_additionalFiles()
return self.destdir
def fetch_actionsfile(self):
actionsuri = join(self.specdiruri, ctx.const.actions_file)
self.download(actionsuri, self.destdir)
def fetch_patches(self):
spec = self.spec
for patch in spec.source.patches:
file_name = basename(patch.filename)
dir_name = dirname(patch.filename)
patchuri = join(self.location,
ctx.const.files_dir, dir_name, file_name)
self.download(patchuri, join(self.destdir, ctx.const.files_dir, dir_name))
def fetch_comarfiles(self):
spec = self.spec
for package in spec.packages:
for pcomar in package.providesComar:
comaruri = join(self.location,
ctx.const.comar_dir, pcomar.script)
self.download(comaruri, join(self.destdir, ctx.const.comar_dir))
def fetch_additionalFiles(self):
spec = self.spec
for pkg in spec.packages:
for afile in pkg.additionalFiles:
file_name = basename(afile.filename)
dir_name = dirname(afile.filename)
afileuri = join(self.location,
ctx.const.files_dir, dir_name, file_name)
self.download(afileuri, join(self.destdir, ctx.const.files_dir, dir_name))
def download(self, uri, transferdir):
# fix auth info and download
uri = File.make_uri(uri)
if self.authinfo:
uri.set_auth_info(self.authinfo)
File.download(uri, transferdir)
def fetch_component(self):
if not self.spec.source.partOf: if not self.spec.source.partOf:
ctx.ui.warning(_('PartOf tag not defined, looking for component')) ctx.ui.warning(_('PartOf tag not defined, looking for component'))
parentdir = os.path.realpath(self.specdir + '/../') diruri = parenturi(self.specuri.get_uri())
parentdir = parenturi(diruri)
url = util.join_path(parentdir, 'component.xml') url = util.join_path(parentdir, 'component.xml')
progress = ctx.ui.Progress progress = ctx.ui.Progress
if URI(url).is_remote_file(): if URI(url).is_remote_file():
+2 -2
View File
@@ -75,9 +75,9 @@ class XmlFile(object):
self.doc = ParsePath(localpath) self.doc = ParsePath(localpath)
return self.doc.documentElement return self.doc.documentElement
except Ft.FtException, e: except Ft.FtException, e:
raise Error(_("File '%s' has invalid XML: %s") % (path, str(e)) ) raise Error(_("File '%s' has invalid XML: %s") % (localpath, str(e)) )
except exceptions.ValueError, e: except exceptions.ValueError, e:
raise Error(_("File '%s' not found") % path ) raise Error(_("File '%s' not found") % localpath )
def writexml(self, uri, tmpDir = '/tmp'): def writexml(self, uri, tmpDir = '/tmp'):
f = file(uri, 'w') f = file(uri, 'w')
+8
View File
@@ -177,6 +177,14 @@ def makepath(comps, relative = False, sep = os.path.sep):
else: else:
return path return path
def parentpath(a, sep = os.path.sep):
# remove trailing '/'
a = a.lstrip(sep)
return a[:a.rfind(sep)]
def parenturi(a):
return parentpath(a, '/')
# I'm not sure how necessary this is. Ahem. # I'm not sure how necessary this is. Ahem.
def commonprefix(l): def commonprefix(l):
"""an improved version of os.path.commonprefix, """an improved version of os.path.commonprefix,