change directory structure when indexing #8
This commit is contained in:
+36
-1
@@ -13,6 +13,7 @@
|
||||
"""PiSi source/package index"""
|
||||
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import multiprocessing
|
||||
|
||||
@@ -37,6 +38,7 @@ import pisi.operations.build
|
||||
class Error(pisi.Error):
|
||||
pass
|
||||
|
||||
|
||||
class Index(xmlfile.XmlFile, metaclass=autoxml.autoxml):
|
||||
tag = "PISI"
|
||||
|
||||
@@ -89,6 +91,27 @@ class Index(xmlfile.XmlFile, metaclass=autoxml.autoxml):
|
||||
specs = []
|
||||
deltas = {}
|
||||
|
||||
pkgs_sorted = False
|
||||
|
||||
for fn in next(os.walk(repo_uri))[2]:
|
||||
if fn.endswith(ctx.const.delta_package_suffix) or fn.endswith(ctx.const.package_suffix):
|
||||
name, version = util.parse_package_name(fn)
|
||||
if name.split("-").pop() in ["devel", "32bit", "doc", "docs", "userspace"]:
|
||||
name = name[:-1 - len(name.split("-").pop())]
|
||||
pkgpath = os.path.join(repo_uri,
|
||||
name[0:4].lower() if name.startswith("lib") and len(name) > 3 else name.lower()[0],
|
||||
name.lower())
|
||||
if not os.path.isdir(pkgpath):
|
||||
os.makedirs(pkgpath)
|
||||
ctx.ui.info("%-80.80s\r" % (_('Sorting: %s ') % fn),
|
||||
noln=False if ctx.config.get_option("verbose") else True)
|
||||
shutil.copy2(os.path.join(repo_uri, fn), pkgpath)
|
||||
os.remove(os.path.join(repo_uri, fn))
|
||||
pkgs_sorted = True
|
||||
|
||||
if pkgs_sorted:
|
||||
ctx.ui.info("%-80.80s\r" % '')
|
||||
|
||||
for root, dirs, files in os.walk(repo_uri):
|
||||
# Filter hidden directories
|
||||
# TODO: Add --exclude-dirs parameter to CLI and filter according
|
||||
@@ -154,14 +177,26 @@ class Index(xmlfile.XmlFile, metaclass=autoxml.autoxml):
|
||||
|
||||
# Before calling pool.map check if list is empty or not: python#12157
|
||||
if latest_packages:
|
||||
sorted_pkgs = {}
|
||||
for pkg in latest_packages:
|
||||
key = re.search("\/((lib)?[\d\w])\/", pkg[0])
|
||||
key = key.group(1) if key else os.path.dirname(pkg[0])
|
||||
try:
|
||||
sorted_pkgs[key].append(pkg)
|
||||
except KeyError:
|
||||
sorted_pkgs[key] = [pkg]
|
||||
self.packages = []
|
||||
for key, pkgs in sorted(sorted_pkgs.items()):
|
||||
ctx.ui.info("%-80.80s\r" % (_("Adding packages from directory %s... " % key)), noln=True)
|
||||
try:
|
||||
# Add binary packages to index using a process pool
|
||||
self.packages = pool.map(add_package, latest_packages)
|
||||
self.packages.extend(pool.map(add_package, pkgs))
|
||||
except:
|
||||
pool.terminate()
|
||||
pool.join()
|
||||
ctx.ui.info("")
|
||||
raise
|
||||
ctx.ui.info("%-80.80s\r" % (_("Adding packages from directory %s... done." % key)))
|
||||
|
||||
ctx.ui.info("")
|
||||
pool.close()
|
||||
|
||||
@@ -1200,6 +1200,16 @@ class Builder:
|
||||
path = util.join_path(package_dir, filename)
|
||||
if os.path.exists(path):
|
||||
return path
|
||||
else:
|
||||
name, version = util.parse_package_name(filename)
|
||||
if name.split("-").pop() in ["devel", "32bit", "doc", "docs", "userspace"]:
|
||||
name = name[:-1 - len(name.split("-").pop())]
|
||||
path = os.path.join(package_dir,
|
||||
name[0:4].lower() if name.startswith("lib") and len(name) > 3 else name.lower()[0],
|
||||
name.lower(),
|
||||
filename)
|
||||
if os.path.exists(path):
|
||||
return path
|
||||
|
||||
old_packages = {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user