* util: add a method to determine absolute paths
* uri: absolute/relative paths* * operations: take relative packageURIs into account * these changes fix bug 368 * PEP 8 stuf
This commit is contained in:
+2
-2
@@ -108,7 +108,7 @@ class PisiBuild:
|
|||||||
"""Build the package in one shot."""
|
"""Build the package in one shot."""
|
||||||
|
|
||||||
ui.info("Building PISI source package: %s\n" % self.spec.source.name)
|
ui.info("Building PISI source package: %s\n" % self.spec.source.name)
|
||||||
util.xtermTitle("Building PISI source package: %s\n" % self.spec.source.name)
|
util.xterm_title("Building PISI source package: %s\n" % self.spec.source.name)
|
||||||
|
|
||||||
self.compile_action_script()
|
self.compile_action_script()
|
||||||
|
|
||||||
@@ -342,4 +342,4 @@ class PisiBuild:
|
|||||||
pkg.close()
|
pkg.close()
|
||||||
os.chdir(c)
|
os.chdir(c)
|
||||||
self.set_state("buildpackages")
|
self.set_state("buildpackages")
|
||||||
util.xtermTitleReset()
|
util.xterm_title_reset()
|
||||||
|
|||||||
+4
-5
@@ -76,14 +76,13 @@ def install_single_name(name, upgrade = False):
|
|||||||
repo = repodb.get_repo(repo)
|
repo = repodb.get_repo(repo)
|
||||||
pkg = packagedb.get_package(name)
|
pkg = packagedb.get_package(name)
|
||||||
|
|
||||||
if repo.indexuri.is_local_file():
|
# FIXME: let pkg.packageURI be stored as URI type rather than string
|
||||||
|
pkg_uri = URI(pkg.packageURI)
|
||||||
|
if pkg_uri.is_absolute_path():
|
||||||
pkg_path = str(pkg.packageURI)
|
pkg_path = str(pkg.packageURI)
|
||||||
else:
|
else:
|
||||||
# FIXME: determine if we have relative paths in the index
|
|
||||||
# rather than doing this. Requires the index to know about
|
|
||||||
# that related to bug 368
|
|
||||||
pkg_path = os.path.join(os.path.dirname(repo.indexuri.get_uri()),
|
pkg_path = os.path.join(os.path.dirname(repo.indexuri.get_uri()),
|
||||||
os.path.basename(pkg.packageURI))
|
pkg_uri.path())
|
||||||
|
|
||||||
ui.debug("Package URI: %s\n" % pkg_path)
|
ui.debug("Package URI: %s\n" % pkg_path)
|
||||||
|
|
||||||
|
|||||||
+9
-1
@@ -13,8 +13,10 @@
|
|||||||
from urlparse import urlparse
|
from urlparse import urlparse
|
||||||
from os.path import basename
|
from os.path import basename
|
||||||
|
|
||||||
|
import pisi.util as util
|
||||||
|
|
||||||
class URI(object):
|
class URI(object):
|
||||||
"""PUrl class provides a URL parser and simplifies working with
|
"""URI class provides a URL parser and simplifies working with
|
||||||
URLs."""
|
URLs."""
|
||||||
|
|
||||||
def __init__(self, uri=None):
|
def __init__(self, uri=None):
|
||||||
@@ -59,6 +61,12 @@ class URI(object):
|
|||||||
def is_remote_file(self):
|
def is_remote_file(self):
|
||||||
return not self.is_local_file()
|
return not self.is_local_file()
|
||||||
|
|
||||||
|
def is_absolute_path(self):
|
||||||
|
return util.absolute_path(self.__path)
|
||||||
|
|
||||||
|
def is_relative_path(self):
|
||||||
|
return not self.is_absolute_path()
|
||||||
|
|
||||||
def set_auth_info(self, authTuple):
|
def set_auth_info(self, authTuple):
|
||||||
if not isinstance(authTuple, tuple):
|
if not isinstance(authTuple, tuple):
|
||||||
raise Exception, "setAuthInfo needs a tuple (user, pass)"
|
raise Exception, "setAuthInfo needs a tuple (user, pass)"
|
||||||
|
|||||||
+20
-17
@@ -71,7 +71,7 @@ def unzip(seq):
|
|||||||
return zip(*seq)
|
return zip(*seq)
|
||||||
|
|
||||||
def concat(l):
|
def concat(l):
|
||||||
"""concatenate a list of lists"""
|
'''concatenate a list of lists'''
|
||||||
return reduce( lambda x,y: x+y, l )
|
return reduce( lambda x,y: x+y, l )
|
||||||
|
|
||||||
def strlist(l):
|
def strlist(l):
|
||||||
@@ -86,7 +86,7 @@ def multisplit(str, chars):
|
|||||||
return l
|
return l
|
||||||
|
|
||||||
def same(l):
|
def same(l):
|
||||||
"check if all elements of a sequence are equal"
|
'''check if all elements of a sequence are equal'''
|
||||||
if len(l)==0:
|
if len(l)==0:
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
@@ -97,7 +97,7 @@ def same(l):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def prefix(a, b):
|
def prefix(a, b):
|
||||||
"check if sequence a is a prefix of sequence b"
|
'''check if sequence a is a prefix of sequence b'''
|
||||||
if len(a)>len(b):
|
if len(a)>len(b):
|
||||||
return False
|
return False
|
||||||
for i in range(0,len(a)):
|
for i in range(0,len(a)):
|
||||||
@@ -128,7 +128,7 @@ def run_batch(cmd):
|
|||||||
return (successful,lines)
|
return (successful,lines)
|
||||||
|
|
||||||
|
|
||||||
def xtermTitle(message):
|
def xterm_title(message):
|
||||||
"""sets message as a console window's title"""
|
"""sets message as a console window's title"""
|
||||||
if os.environ.has_key("TERM") and sys.stderr.isatty():
|
if os.environ.has_key("TERM") and sys.stderr.isatty():
|
||||||
terminalType = os.environ["TERM"]
|
terminalType = os.environ["TERM"]
|
||||||
@@ -138,11 +138,11 @@ def xtermTitle(message):
|
|||||||
sys.stderr.flush()
|
sys.stderr.flush()
|
||||||
break
|
break
|
||||||
|
|
||||||
def xtermTitleReset():
|
def xterm_title_reset():
|
||||||
"""resets console window's title"""
|
"""resets console window's title"""
|
||||||
if os.environ.has_key("TERM"):
|
if os.environ.has_key("TERM"):
|
||||||
terminalType = os.environ["TERM"]
|
terminalType = os.environ["TERM"]
|
||||||
xtermTitle(os.environ["TERM"])
|
xterm_title(os.environ["TERM"])
|
||||||
|
|
||||||
#############################
|
#############################
|
||||||
# Path Processing Functions #
|
# Path Processing Functions #
|
||||||
@@ -150,7 +150,7 @@ def xtermTitleReset():
|
|||||||
|
|
||||||
def splitpath(a):
|
def splitpath(a):
|
||||||
"""split path into components and return as a list
|
"""split path into components and return as a list
|
||||||
os.path.split doesn't do what I want"""
|
os.path.split doesn't do what I want like removing trailing /"""
|
||||||
comps = a.split(os.path.sep)
|
comps = a.split(os.path.sep)
|
||||||
if comps[len(comps)-1]=='':
|
if comps[len(comps)-1]=='':
|
||||||
comps.pop()
|
comps.pop()
|
||||||
@@ -181,6 +181,10 @@ def removepathprefix(prefix, path):
|
|||||||
else:
|
else:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
def absolute_path(path):
|
||||||
|
"determine if given @path is absolute"
|
||||||
|
comps = splitpath(path)
|
||||||
|
return comps[0] == ''
|
||||||
|
|
||||||
####################################
|
####################################
|
||||||
# File/Directory Related Functions #
|
# File/Directory Related Functions #
|
||||||
@@ -226,7 +230,7 @@ def copy_file(src,dest):
|
|||||||
check_dir(os.path.dirname(dest))
|
check_dir(os.path.dirname(dest))
|
||||||
shutil.copyfile(src, dest)
|
shutil.copyfile(src, dest)
|
||||||
|
|
||||||
def get_file_hashes(top, excludePrefixes=None, removePrefix=None):
|
def get_file_hashes(top, exclude_prefix=None, remove_prefix=None):
|
||||||
"""Generator function iterates over a toplevel path and returns the
|
"""Generator function iterates over a toplevel path and returns the
|
||||||
(filePath, sha1Hash) tuple for all files. If excludePrefixes list
|
(filePath, sha1Hash) tuple for all files. If excludePrefixes list
|
||||||
is given as a parameter, function will exclude the filePaths
|
is given as a parameter, function will exclude the filePaths
|
||||||
@@ -234,10 +238,10 @@ def get_file_hashes(top, excludePrefixes=None, removePrefix=None):
|
|||||||
used to remove prefix from filePath while matching excludes, if
|
used to remove prefix from filePath while matching excludes, if
|
||||||
given."""
|
given."""
|
||||||
|
|
||||||
def hasExcludedPrefix(filename):
|
def has_excluded_prefix(filename):
|
||||||
if excludePrefixes and removePrefix:
|
if exclude_prefix and remove_prefix:
|
||||||
tempfnam = remove_prefix(removePrefix, filename)
|
tempfnam = remove_prefix(remove_prefix, filename)
|
||||||
for p in excludePrefixes:
|
for p in exclude_prefix:
|
||||||
if tempfnam.startswith(p):
|
if tempfnam.startswith(p):
|
||||||
return 1
|
return 1
|
||||||
else:
|
else:
|
||||||
@@ -245,13 +249,13 @@ def get_file_hashes(top, excludePrefixes=None, removePrefix=None):
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
for root, dirs, files in os.walk(top, topdown=False):
|
for root, dirs, files in os.walk(top, topdown=False):
|
||||||
if os.path.islink(root) and not hasExcludedPrefix(root):
|
if os.path.islink(root) and not has_excluded_prefix(root):
|
||||||
#yield the symlink..
|
#yield the symlink..
|
||||||
yield (root, sha1_file(root))
|
yield (root, sha1_file(root))
|
||||||
excludePrefixes.append(remove_prefix(removePrefix, root) + "/")
|
exclude_prefix.append(remove_prefix(remove_prefix, root) + "/")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if os.path.isdir(root) and not hasExcludedPrefix(root):
|
if os.path.isdir(root) and not has_excluded_prefix(root):
|
||||||
parent, r, d, f = root, '', '', ''
|
parent, r, d, f = root, '', '', ''
|
||||||
for r, d, f in os.walk(parent, topdown=False): pass
|
for r, d, f in os.walk(parent, topdown=False): pass
|
||||||
if not f and not d:
|
if not f and not d:
|
||||||
@@ -259,7 +263,7 @@ def get_file_hashes(top, excludePrefixes=None, removePrefix=None):
|
|||||||
|
|
||||||
for fname in files:
|
for fname in files:
|
||||||
f = os.path.join(root, fname)
|
f = os.path.join(root, fname)
|
||||||
if hasExcludedPrefix(f):
|
if has_excluded_prefix(f):
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
yield (f, sha1_file(f))
|
yield (f, sha1_file(f))
|
||||||
@@ -335,4 +339,3 @@ def partition_freespace(directory):
|
|||||||
|
|
||||||
def package_name(name, version, release):
|
def package_name(name, version, release):
|
||||||
return name + '-' + version + '-' + release + const.package_prefix
|
return name + '-' + version + '-' + release + const.package_prefix
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user