pisi.purl -> pisi.URI
This commit is contained in:
@@ -14,7 +14,7 @@ import sys
|
||||
from optparse import OptionParser
|
||||
|
||||
import pisi
|
||||
from pisi.purl import PUrl
|
||||
from pisi.purl import URI
|
||||
from pisi.cli.common import *
|
||||
|
||||
|
||||
@@ -352,6 +352,11 @@ source and binary packages.
|
||||
def name(self):
|
||||
return ("index", "ix")
|
||||
|
||||
def options(self):
|
||||
self.parser.add_option("-a", "--absolute-uris", action="store_true",
|
||||
default=False,
|
||||
help="store absolute links for indexed files.")
|
||||
|
||||
def run(self):
|
||||
|
||||
self.init()
|
||||
@@ -492,7 +497,7 @@ Lists currently tracked repositories.
|
||||
from pisi.repodb import repodb
|
||||
for repo in repodb.list():
|
||||
print repo
|
||||
print ' ', repodb.get_repo(repo).indexuri.getUri()
|
||||
print ' ', repodb.get_repo(repo).indexuri.get_uri()
|
||||
self.finalize()
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ import sys
|
||||
from optparse import OptionParser
|
||||
|
||||
import pisi
|
||||
from pisi.purl import PUrl
|
||||
from pisi.purl import URI
|
||||
from pisi.cli.common import *
|
||||
from pisi.cli.commands import *
|
||||
|
||||
|
||||
+5
-5
@@ -23,7 +23,7 @@ from base64 import encodestring
|
||||
# pisi modules
|
||||
import pisi
|
||||
import pisi.util as util
|
||||
from pisi.purl import PUrl
|
||||
from pisi.purl import URI
|
||||
from pisi.ui import ui
|
||||
|
||||
|
||||
@@ -44,8 +44,8 @@ class Fetcher:
|
||||
"""Fetcher can fetch a file from various sources using various
|
||||
protocols."""
|
||||
def __init__(self, url, dest):
|
||||
if not isinstance(url, PUrl):
|
||||
url = PUrl(url)
|
||||
if not isinstance(url, URI):
|
||||
url = URI(url)
|
||||
|
||||
self.url = url
|
||||
self.filedest = dest
|
||||
@@ -63,7 +63,7 @@ class Fetcher:
|
||||
if not os.access(self.filedest, os.W_OK):
|
||||
self.err("no perm to write to dest dir")
|
||||
|
||||
if self.url.isLocalFile():
|
||||
if self.url.is_local_file():
|
||||
self.fetchLocalFile()
|
||||
else:
|
||||
self.fetchRemoteFile()
|
||||
@@ -141,7 +141,7 @@ class Fetcher:
|
||||
self.doGrab(fileObj, dest, totalsize)
|
||||
|
||||
def formatRequest(self, request):
|
||||
authinfo = self.url.authInfo()
|
||||
authinfo = self.url.auth_info()
|
||||
if authinfo:
|
||||
enc = encodestring("%s:%s" % authinfo)
|
||||
request.add_header('Authorization', 'Basic %s' % enc)
|
||||
|
||||
+10
-10
@@ -24,7 +24,7 @@ from pisi.ui import ui
|
||||
import pisi.util as util
|
||||
from pisi.config import config
|
||||
from pisi.constants import const
|
||||
from pisi.purl import PUrl
|
||||
from pisi.purl import URI
|
||||
|
||||
class Index(XmlFile):
|
||||
|
||||
@@ -37,8 +37,8 @@ class Index(XmlFile):
|
||||
"""Read PSPEC file"""
|
||||
|
||||
self.filepath = filename
|
||||
url = PUrl(filename)
|
||||
if url.isRemoteFile():
|
||||
url = URI(filename)
|
||||
if url.is_remote_file():
|
||||
from fetcher import fetchUrl
|
||||
|
||||
dest = os.path.join(config.index_dir(), repo)
|
||||
@@ -86,13 +86,13 @@ class Index(XmlFile):
|
||||
|
||||
md = metadata.MetaData()
|
||||
md.read(os.path.join(config.install_dir(), const.metadata_xml))
|
||||
# TODO: in the future we'll do all of this with purl/pfile/&helpers
|
||||
# After that, we'll remove the ugly repo_uri parameter from this
|
||||
# function.
|
||||
# FIXME: for now, do all paths absolute, support relative URIs
|
||||
# in the future
|
||||
#md.package.packageURI = util.removepathprefix(repo_uri, path)
|
||||
md.package.packageURI = os.path.realpath(path)
|
||||
if config.options and config.options.absolute_uris:
|
||||
md.package.packageURI = os.path.realpath(path)
|
||||
else: # create relative path by default
|
||||
# TODO: in the future we'll do all of this with purl/pfile/&helpers
|
||||
# After that, we'll remove the ugly repo_uri parameter from this
|
||||
# function.
|
||||
md.package.packageURI = util.removepathprefix(repo_uri, path)
|
||||
# check package semantics
|
||||
if md.has_errors():
|
||||
ui.error('Package ' + md.package.name + ': metadata corrupt\n')
|
||||
|
||||
+6
-8
@@ -16,7 +16,7 @@ import pisi
|
||||
from pisi.config import config
|
||||
from pisi.constants import const
|
||||
from pisi.ui import ui
|
||||
from pisi.purl import PUrl
|
||||
from pisi.purl import URI
|
||||
import pisi.util as util
|
||||
import pisi.packagedb as packagedb
|
||||
|
||||
@@ -53,11 +53,11 @@ def remove_single(package_name):
|
||||
|
||||
def install_single(pkg, upgrade = False):
|
||||
"""install a single package from URI or ID"""
|
||||
url = PUrl(pkg)
|
||||
url = URI(pkg)
|
||||
# Check if we are dealing with a remote file or a real path of
|
||||
# package filename. Otherwise we'll try installing a package from
|
||||
# the package repository.
|
||||
if url.isRemoteFile() or os.path.exists(url.uri):
|
||||
if url.is_remote_file() or os.path.exists(url.uri):
|
||||
install_single_file(pkg, upgrade)
|
||||
else:
|
||||
install_single_name(pkg, upgrade)
|
||||
@@ -72,19 +72,17 @@ def install_single_name(name, upgrade = False):
|
||||
# find package in repository
|
||||
repo = packagedb.which_repo(name)
|
||||
if repo:
|
||||
# TODO: Allright this is ugly, but works. Eventually, we'll
|
||||
# change this...
|
||||
from repodb import repodb
|
||||
repo = repodb.get_repo(repo)
|
||||
pkg = packagedb.get_package(name)
|
||||
|
||||
if repo.indexuri.isLocalFile():
|
||||
if repo.indexuri.is_local_file():
|
||||
pkg_path = pkg.packageURI
|
||||
else:
|
||||
# FIXME: determine if we have relative paths in the index
|
||||
# rather than doing this. Requires the index to know about
|
||||
# that
|
||||
pkg_path = os.path.join(os.path.dirname(repo.indexuri.getUri()),
|
||||
pkg_path = os.path.join(os.path.dirname(repo.indexuri.get_uri()),
|
||||
os.path.basename(pkg.packageURI))
|
||||
|
||||
ui.debug("Package URI: %s\n" % pkg_path)
|
||||
@@ -92,7 +90,7 @@ def install_single_name(name, upgrade = False):
|
||||
# Package will handle remote file for us!
|
||||
install_single_file(pkg_path, upgrade)
|
||||
else:
|
||||
ui.error("Package %s not found in the repository file.\n" % pkg)
|
||||
ui.error("Package %s not found in any active repository.\n" % pkg)
|
||||
|
||||
# deneme, don't remove ulan
|
||||
class AtomicOperation(object):
|
||||
|
||||
+3
-3
@@ -21,7 +21,7 @@ import pisi
|
||||
import pisi.archive as archive
|
||||
from pisi.constants import const
|
||||
from pisi.config import config
|
||||
from pisi.purl import PUrl
|
||||
from pisi.purl import URI
|
||||
from pisi.metadata import MetaData
|
||||
from pisi.files import Files
|
||||
|
||||
@@ -34,9 +34,9 @@ class Package:
|
||||
file)."""
|
||||
def __init__(self, packagefn, mode='r'):
|
||||
self.filepath = packagefn
|
||||
url = PUrl(packagefn)
|
||||
url = URI(packagefn)
|
||||
|
||||
if url.isRemoteFile():
|
||||
if url.is_remote_file():
|
||||
from fetcher import fetchUrl
|
||||
from ui import ui
|
||||
dest = config.packages_dir()
|
||||
|
||||
+12
-13
@@ -7,20 +7,19 @@
|
||||
#
|
||||
# Please read the COPYING file.
|
||||
#
|
||||
|
||||
# Simplifying working with URLs, PURL module provides common URL
|
||||
# parsing interface
|
||||
# Simplifies working with URLs, purl module provides common URL
|
||||
# parsing and processing
|
||||
|
||||
from urlparse import urlparse
|
||||
from os.path import basename
|
||||
|
||||
class PUrl(object):
|
||||
class URI(object):
|
||||
"""PUrl class provides a URL parser and simplifies working with
|
||||
URLs."""
|
||||
|
||||
def __init__(self, uri=None):
|
||||
if uri:
|
||||
self.setUri(uri)
|
||||
self.set_uri(uri)
|
||||
else:
|
||||
self.__scheme = None
|
||||
self.__location = None
|
||||
@@ -33,12 +32,12 @@ class PUrl(object):
|
||||
|
||||
self.__authinfo = None
|
||||
|
||||
def getUri(self):
|
||||
def get_uri(self):
|
||||
if self.__uri:
|
||||
return self.__uri
|
||||
return None
|
||||
|
||||
def setUri(self, uri):
|
||||
def set_uri(self, uri):
|
||||
# (scheme, location, path, params, query, fragment)
|
||||
u = urlparse(uri, "file")
|
||||
self.__scheme = u[0]
|
||||
@@ -51,21 +50,21 @@ class PUrl(object):
|
||||
|
||||
self.__uri = uri
|
||||
|
||||
def isLocalFile(self):
|
||||
def is_local_file(self):
|
||||
if self.scheme() == "file":
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def isRemoteFile(self):
|
||||
return not self.isLocalFile()
|
||||
def is_remote_file(self):
|
||||
return not self.is_local_file()
|
||||
|
||||
def setAuthInfo(self, authTuple):
|
||||
def set_auth_info(self, authTuple):
|
||||
if not isinstance(authTuple, tuple):
|
||||
raise Exception, "setAuthInfo needs a tuple (user, pass)"
|
||||
self.__authinfo = authTuple
|
||||
|
||||
def authInfo(self):
|
||||
def auth_info(self):
|
||||
return self.__authinfo
|
||||
|
||||
def scheme(self):
|
||||
@@ -90,6 +89,6 @@ class PUrl(object):
|
||||
return self.__fragment
|
||||
|
||||
def __str__(self):
|
||||
return self.getUri()
|
||||
return self.get_uri()
|
||||
|
||||
uri = property(getUri, setUri)
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ import os, fcntl
|
||||
from pisi.config import config
|
||||
import pisi.packagedb as packagedb
|
||||
import pisi.util as util
|
||||
from pisi.purl import PUrl
|
||||
from pisi.purl import URI
|
||||
|
||||
class RepoDB(object):
|
||||
"""RepoDB maps repo ids to repository information"""
|
||||
|
||||
@@ -22,7 +22,7 @@ from os import access, R_OK
|
||||
# pisi modules
|
||||
import pisi
|
||||
from pisi.archive import Archive
|
||||
from pisi.purl import PUrl
|
||||
from pisi.purl import URI
|
||||
from pisi.ui import ui
|
||||
from pisi.config import config
|
||||
from pisi.fetcher import fetchUrl
|
||||
@@ -36,7 +36,7 @@ class SourceArchive:
|
||||
and unpacking a source archive"""
|
||||
def __init__(self, ctx):
|
||||
self.ctx = ctx
|
||||
self.url = PUrl(self.ctx.spec.source.archiveUri)
|
||||
self.url = URI(self.ctx.spec.source.archiveUri)
|
||||
self.archiveFile = join(config.archives_dir(), self.url.filename())
|
||||
self.archiveType = self.ctx.spec.source.archiveType
|
||||
self.archiveSHA1 = self.ctx.spec.source.archiveSHA1
|
||||
|
||||
@@ -15,14 +15,14 @@ from os.path import basename, dirname, join
|
||||
from pisi.ui import ui
|
||||
from pisi.config import config
|
||||
from pisi.constants import const
|
||||
from pisi.purl import PUrl
|
||||
from pisi.purl import URI
|
||||
from pisi.specfile import SpecFile
|
||||
|
||||
class SourceFetcher(object):
|
||||
def __init__(self, url, authInfo=None):
|
||||
self.url = url
|
||||
if authInfo:
|
||||
self.url.setAuthInfo(authInfo)
|
||||
self.url.set_auth_info(authInfo)
|
||||
self.location = dirname(self.url.uri)
|
||||
|
||||
pkgname = basename(dirname(self.url.path()))
|
||||
|
||||
+5
-5
@@ -20,7 +20,7 @@ if ver[0] <= 2 and ver[1] < 4:
|
||||
from pisi.config import config
|
||||
from pisi.constants import const
|
||||
from pisi.ui import ui
|
||||
from pisi.purl import PUrl
|
||||
from pisi.purl import URI
|
||||
import pisi.util as util
|
||||
import pisi.dependency as dependency
|
||||
import pisi.pgraph as pgraph
|
||||
@@ -357,7 +357,7 @@ class Repo:
|
||||
self.indexuri = indexuri
|
||||
|
||||
def add_repo(name, indexuri):
|
||||
repo = Repo(PUrl(indexuri))
|
||||
repo = Repo(URI(indexuri))
|
||||
repodb.add_repo(name, repo)
|
||||
|
||||
def remove_repo(name):
|
||||
@@ -371,7 +371,7 @@ def update_repo(repo):
|
||||
|
||||
ui.info('* Updating repository: %s\n' % repo)
|
||||
index = Index()
|
||||
index.read(repodb.get_repo(repo).indexuri.getUri(), repo)
|
||||
index.read(repodb.get_repo(repo).indexuri.get_uri(), repo)
|
||||
index.update_db(repo)
|
||||
ui.info('* Package db updated.\n')
|
||||
|
||||
@@ -383,8 +383,8 @@ def prepare_for_build(pspecfile, authInfo=None):
|
||||
# makes it impossible to use build module directly.
|
||||
from build import PisiBuild
|
||||
|
||||
url = PUrl(pspecfile)
|
||||
if url.isRemoteFile():
|
||||
url = URI(pspecfile)
|
||||
if url.is_remote_file():
|
||||
from sourcefetcher import SourceFetcher
|
||||
fs = SourceFetcher(url, authInfo)
|
||||
url.uri = fs.fetch_all()
|
||||
|
||||
Reference in New Issue
Block a user