* add wildcard support to paths in files section
without breaking anything (but please see the notes) also rearrange the code a little, this is tested with a single entry in zlib, so definitely needs more extensive testing * cleanup en_build_no codes, reorganize * util: add is_package_name function * util: no studlyCaps
This commit is contained in:
+42
-70
@@ -16,6 +16,7 @@
|
|||||||
# python standard library
|
# python standard library
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import glob
|
||||||
|
|
||||||
import gettext
|
import gettext
|
||||||
__trans = gettext.translation('pisi', fallback=True)
|
__trans = gettext.translation('pisi', fallback=True)
|
||||||
@@ -73,8 +74,8 @@ def check_path_collision(package, pkgList):
|
|||||||
# path.pathname: /usr/share/doc
|
# path.pathname: /usr/share/doc
|
||||||
if util.subpath(pinfo.pathname, path.pathname):
|
if util.subpath(pinfo.pathname, path.pathname):
|
||||||
collisions.append(path.pathname)
|
collisions.append(path.pathname)
|
||||||
ctx.ui.debug(_('Path %s belongs in multiple packages') %
|
ctx.ui.error(_('Path %s belongs in multiple packages') %
|
||||||
path.pathname)
|
path.pathname)
|
||||||
return collisions
|
return collisions
|
||||||
|
|
||||||
# a dynamic build context
|
# a dynamic build context
|
||||||
@@ -356,27 +357,38 @@ class Builder:
|
|||||||
self.metadata = metadata
|
self.metadata = metadata
|
||||||
|
|
||||||
def gen_files_xml(self, package):
|
def gen_files_xml(self, package):
|
||||||
"""Generetes files.xml using the path definitions in specfile and
|
"""Generates files.xml using the path definitions in specfile and
|
||||||
generated files by the build system."""
|
the files produced by the build system."""
|
||||||
files = Files()
|
files = Files()
|
||||||
install_dir = self.bctx.pkg_install_dir()
|
install_dir = self.bctx.pkg_install_dir()
|
||||||
|
|
||||||
|
# FIXME: We need to expand globs before trying to calculate hashes
|
||||||
|
# Not on the fly like now.
|
||||||
|
|
||||||
# we'll exclude collisions in get_file_hashes. Having a
|
# we'll exclude collisions in get_file_hashes. Having a
|
||||||
# collisions list is not wrong, we must just handle it :).
|
# collisions list is not wrong, we must just handle it :).
|
||||||
collisions = check_path_collision(package,
|
# sure -- exa
|
||||||
self.spec.packages)
|
collisions = check_path_collision(package, self.spec.packages)
|
||||||
|
# FIXME: material collisions after expanding globs must be
|
||||||
|
# reported as errors, and an exception must be raised
|
||||||
|
|
||||||
d = {}
|
d = {}
|
||||||
for pinfo in package.paths:
|
def add_path(path):
|
||||||
path = install_dir + pinfo.pathname
|
# add the files under material path
|
||||||
for fpath, fhash in util.get_file_hashes(path, collisions, install_dir):
|
for fpath, fhash in util.get_file_hashes(path, collisions, install_dir):
|
||||||
frpath = util.removepathprefix(install_dir, fpath) # relative path
|
frpath = util.removepathprefix(install_dir, fpath) # relative path
|
||||||
ftype = get_file_type(frpath, package.paths)
|
ftype = get_file_type(frpath, package.paths)
|
||||||
try: # broken links can cause problem
|
try: # broken links and empty dirs can cause problem
|
||||||
fsize = str(os.path.getsize(fpath))
|
fsize = str(os.path.getsize(fpath))
|
||||||
except OSError:
|
except OSError:
|
||||||
fsize = None
|
fsize = None
|
||||||
d[frpath] = FileInfo(frpath, ftype, fsize, fhash)
|
d[frpath] = FileInfo(frpath, ftype, fsize, fhash)
|
||||||
|
|
||||||
|
for pinfo in package.paths:
|
||||||
|
wildcard_path = util.join_path(install_dir, pinfo.pathname)
|
||||||
|
for path in glob.glob(wildcard_path):
|
||||||
|
add_path(path)
|
||||||
|
|
||||||
for (p, fileinfo) in d.iteritems():
|
for (p, fileinfo) in d.iteritems():
|
||||||
files.append(fileinfo)
|
files.append(fileinfo)
|
||||||
|
|
||||||
@@ -387,69 +399,29 @@ class Builder:
|
|||||||
def calc_build_no(self, package_name):
|
def calc_build_no(self, package_name):
|
||||||
"""Calculate build number"""
|
"""Calculate build number"""
|
||||||
|
|
||||||
def found_package(fn):
|
# find previous build in output dir and packages dir
|
||||||
"did we find the filename we were looking for?"
|
found = []
|
||||||
if fn.startswith(package_name + '-'):
|
def locate_package_names(files):
|
||||||
if fn.endswith(ctx.const.package_prefix):
|
for fn in files:
|
||||||
# get version string, skip separator '-'
|
fn = fn.decode('utf-8')
|
||||||
verstr = fn[len(package_name) + 1:
|
if util.is_package_name(fn, package_name):
|
||||||
len(fn)-len(ctx.const.package_prefix)]
|
old_package_fn = os.path.join(root, fn)
|
||||||
import string
|
ctx.ui.info('(found old version %s)' % old_package_fn)
|
||||||
for x in verstr.split('-'):
|
old_pkg = Package(old_package_fn, 'r')
|
||||||
# weak rule: version components start with a digit
|
old_pkg.read(os.path.join(ctx.config.tmp_dir(), 'oldpkg'))
|
||||||
if x is '' or (not x[0] in string.digits):
|
if str(old_pkg.metadata.package.name) != package_name:
|
||||||
return False
|
ctx.ui.warning('Skipping %s with wrong pkg name ' %
|
||||||
return True
|
old_package_fn)
|
||||||
return False
|
continue
|
||||||
|
old_build = old_pkg.metadata.package.build
|
||||||
|
found.append( (old_package_fn, old_build) )
|
||||||
|
|
||||||
# find previous build in ctx.config.options.output_dir
|
for root, dirs, files in os.walk(ctx.config.options.output_dir):
|
||||||
found = []
|
dirs = [] # don't recurse
|
||||||
# for root, dirs, files in os.walk(ctx.config.options.output_dir):
|
locate_package_names(files)
|
||||||
# for fn in files:
|
for root, dirs, files in os.walk(ctx.config.packages_dir()):
|
||||||
# fn = fn.decode('utf-8')
|
locate_package_names(files)
|
||||||
# if found_package(fn):
|
|
||||||
# old_package_fn = os.path.join(root, fn)
|
|
||||||
# ctx.ui.info('(found old version %s)' % old_package_fn)
|
|
||||||
# old_pkg = Package(old_package_fn, 'r')
|
|
||||||
# old_pkg.read(os.path.join(ctx.config.tmp_dir(), 'oldpkg'))
|
|
||||||
# if str(old_pkg.metadata.package.name) != package_name:
|
|
||||||
# ctx.ui.warning('Skipping %s with wrong pkg name ' %
|
|
||||||
# old_package_fn)
|
|
||||||
# continue
|
|
||||||
# old_build = old_pkg.metadata.package.build
|
|
||||||
# found.append( (old_package_fn, old_build) )
|
|
||||||
#
|
|
||||||
# FIXME: Following dirty lines of code just search in the output_dir and
|
|
||||||
# packages dir for previous packages. But we should find a neat way
|
|
||||||
# for this...
|
|
||||||
files = []
|
|
||||||
for f in os.listdir(ctx.config.options.output_dir):
|
|
||||||
fp = os.path.join(ctx.config.options.output_dir, f)
|
|
||||||
if os.path.isfile(fp):
|
|
||||||
files.append(fp)
|
|
||||||
|
|
||||||
packages_dir = ctx.config.packages_dir()
|
|
||||||
# FIXME: packages_dir() should be there!
|
|
||||||
if not os.path.exists(packages_dir):
|
|
||||||
os.makedirs(packages_dir)
|
|
||||||
for f in os.listdir(packages_dir):
|
|
||||||
fp = os.path.join(packages_dir, f)
|
|
||||||
if os.path.isfile(fp):
|
|
||||||
files.append(fp)
|
|
||||||
|
|
||||||
for fn in files:
|
|
||||||
fn = fn.decode('utf-8')
|
|
||||||
if found_package(os.path.basename(fn)):
|
|
||||||
old_package_fn = fn
|
|
||||||
ctx.ui.info(_('(found old version %s)') % old_package_fn)
|
|
||||||
old_pkg = Package(old_package_fn, 'r')
|
|
||||||
old_pkg.read(os.path.join(ctx.config.tmp_dir(), 'oldpkg'))
|
|
||||||
if str(old_pkg.metadata.package.name) != package_name:
|
|
||||||
ctx.ui.warning(_('Skipping %s with wrong pkg name ') %
|
|
||||||
old_package_fn)
|
|
||||||
continue
|
|
||||||
old_build = old_pkg.metadata.package.build
|
|
||||||
found.append( (old_package_fn, old_build) )
|
|
||||||
if not found:
|
if not found:
|
||||||
return 0
|
return 0
|
||||||
ctx.ui.warning(_('(no previous build found, setting build no to 0.)'))
|
ctx.ui.warning(_('(no previous build found, setting build no to 0.)'))
|
||||||
|
|||||||
+28
-11
@@ -241,13 +241,11 @@ def dir_size(dir):
|
|||||||
# installed size. Gettin a sum of all files' sizes if far from
|
# installed size. Gettin a sum of all files' sizes if far from
|
||||||
# being true. Using 'du' command (like Debian does) can be a
|
# being true. Using 'du' command (like Debian does) can be a
|
||||||
# better solution :(.
|
# better solution :(.
|
||||||
getsize = os.path.getsize
|
# Not really, du calculates size on disk, this is much better -- exa
|
||||||
|
from os.path import getsize, islink, isdir, exists
|
||||||
join = join_path
|
join = join_path
|
||||||
islink = os.path.islink
|
|
||||||
isdir = os.path.isdir
|
|
||||||
exist = os.path.exists
|
|
||||||
|
|
||||||
if exist(dir) and (not isdir(dir) and not islink(dir)):
|
if exists(dir) and (not isdir(dir) and not islink(dir)):
|
||||||
#so, this is not a directory but file..
|
#so, this is not a directory but file..
|
||||||
return getsize(dir)
|
return getsize(dir)
|
||||||
|
|
||||||
@@ -262,7 +260,10 @@ 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, exclude_prefix=None, removePrefix=None):
|
# FIXME: this should be done in a much much simpler way
|
||||||
|
# as it stands, it seems to be a kludge to solve
|
||||||
|
# an unrelated problem
|
||||||
|
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) tuples for all files. If excludePrefixes list
|
(filePath, sha1Hash) tuples 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
|
||||||
@@ -294,8 +295,8 @@ def get_file_hashes(top, exclude_prefix=None, removePrefix=None):
|
|||||||
return
|
return
|
||||||
|
|
||||||
def has_excluded_prefix(filename):
|
def has_excluded_prefix(filename):
|
||||||
if exclude_prefix and removePrefix:
|
if exclude_prefix and remove_prefix:
|
||||||
tempfnam = remove_prefix(removePrefix, filename)
|
tempfnam = remove_prefix(remove_prefix, filename)
|
||||||
for p in exclude_prefix:
|
for p in exclude_prefix:
|
||||||
if tempfnam.startswith(p):
|
if tempfnam.startswith(p):
|
||||||
return 1
|
return 1
|
||||||
@@ -307,7 +308,7 @@ def get_file_hashes(top, exclude_prefix=None, removePrefix=None):
|
|||||||
#yield the symlink..
|
#yield the symlink..
|
||||||
#bug 373
|
#bug 373
|
||||||
yield (root, sha1_sum(os.readlink(root), True))
|
yield (root, sha1_sum(os.readlink(root), True))
|
||||||
exclude_prefix.append(remove_prefix(removePrefix, root) + "/")
|
exclude_prefix.append(remove_prefix(remove_prefix, root) + "/")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
#bug 397
|
#bug 397
|
||||||
@@ -315,7 +316,7 @@ def get_file_hashes(top, exclude_prefix=None, removePrefix=None):
|
|||||||
d = join_path(root, dir)
|
d = join_path(root, dir)
|
||||||
if os.path.islink(d) and not has_excluded_prefix(d):
|
if os.path.islink(d) and not has_excluded_prefix(d):
|
||||||
yield (d, sha1_sum(os.readlink(d), True))
|
yield (d, sha1_sum(os.readlink(d), True))
|
||||||
exclude_prefix.append(remove_prefix(removePrefix, d) + "/")
|
exclude_prefix.append(remove_prefix(remove_prefix, d) + "/")
|
||||||
|
|
||||||
#bug 340
|
#bug 340
|
||||||
if os.path.isdir(root) and not has_excluded_prefix(root):
|
if os.path.isdir(root) and not has_excluded_prefix(root):
|
||||||
@@ -355,7 +356,7 @@ def sha1_file(filename):
|
|||||||
m.update(line)
|
m.update(line)
|
||||||
return m.hexdigest()
|
return m.hexdigest()
|
||||||
except IOError:
|
except IOError:
|
||||||
raise FileError(_("Cannot calculate SHA1 hash of %s") % filename)
|
raise FileError(_("I/O Error: Cannot calculate SHA1 hash of %s") % filename)
|
||||||
|
|
||||||
def sha1_data(data):
|
def sha1_data(data):
|
||||||
"""calculate sha1 hash of given data"""
|
"""calculate sha1 hash of given data"""
|
||||||
@@ -478,6 +479,22 @@ def clean_locks(top = '.'):
|
|||||||
def package_name(name, version, release):
|
def package_name(name, version, release):
|
||||||
return name + '-' + version + '-' + release + ctx.const.package_prefix
|
return name + '-' + version + '-' + release + ctx.const.package_prefix
|
||||||
|
|
||||||
|
def is_package_name(fn, package_name = None):
|
||||||
|
"check if fn is a valid filename for given package_name"
|
||||||
|
"if not given a package name, see if fn fits the package name rules"
|
||||||
|
if (package_name==None) or fn.startswith(package_name + '-'):
|
||||||
|
if fn.endswith(ctx.const.package_prefix):
|
||||||
|
# get version string, skip separator '-'
|
||||||
|
verstr = fn[len(package_name) + 1:
|
||||||
|
len(fn)-len(ctx.const.package_prefix)]
|
||||||
|
import string
|
||||||
|
for x in verstr.split('-'):
|
||||||
|
# weak rule: version components after '-' start with a digit
|
||||||
|
if x is '' or (not x[0] in string.digits):
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def env_update():
|
def env_update():
|
||||||
|
|
||||||
env_dir = join_path(ctx.config.dest_dir(), "/etc/env.d")
|
env_dir = join_path(ctx.config.dest_dir(), "/etc/env.d")
|
||||||
|
|||||||
Reference in New Issue
Block a user