mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-07-18 00:09:56 +00:00
Compare commits
1 Commits
master
...
feature/tr
Author | SHA1 | Date | |
---|---|---|---|
e8b59f2e96 |
@ -31,7 +31,6 @@ class Repo(LazyLogging):
|
||||
|
||||
Attributes:
|
||||
name(str): repository name
|
||||
paths(RepositoryPaths): repository paths instance
|
||||
sign_args(list[str]): additional args which have to be used to sign repository archive
|
||||
uid(int): uid of the repository owner user
|
||||
"""
|
||||
@ -44,57 +43,71 @@ class Repo(LazyLogging):
|
||||
sign_args(list[str]): additional args which have to be used to sign repository archive
|
||||
"""
|
||||
self.name = name
|
||||
self.paths = paths
|
||||
self.uid, _ = paths.root_owner
|
||||
self.sign_args = sign_args
|
||||
|
||||
@property
|
||||
def repo_path(self) -> Path:
|
||||
"""
|
||||
get full path to the repository database
|
||||
|
||||
Returns:
|
||||
Path: path to repository database
|
||||
"""
|
||||
return self.paths.repository / f"{self.name}.db.tar.gz"
|
||||
|
||||
def add(self, path: Path) -> None:
|
||||
def add(self, path: Path, root: Path, *, remove_previous: bool) -> None:
|
||||
"""
|
||||
add new package to repository
|
||||
|
||||
Args:
|
||||
path(Path): path to archive to add
|
||||
root(Path): path to repository root
|
||||
remove_previous(bool): whether to remove old package or not
|
||||
"""
|
||||
check_output(
|
||||
"repo-add", *self.sign_args, "-R", str(self.repo_path), str(path),
|
||||
exception=BuildError.from_process(path.name),
|
||||
cwd=self.paths.repository,
|
||||
logger=self.logger,
|
||||
user=self.uid)
|
||||
command = ["repo-add", *self.sign_args]
|
||||
if remove_previous:
|
||||
command.append("--remove")
|
||||
command.extend([str(self.repo_path(root)), str(path)])
|
||||
|
||||
def init(self) -> None:
|
||||
check_output(
|
||||
*command,
|
||||
exception=BuildError.from_process(path.name),
|
||||
cwd=root,
|
||||
logger=self.logger,
|
||||
user=self.uid,
|
||||
)
|
||||
|
||||
def init(self, root: Path) -> None:
|
||||
"""
|
||||
create empty repository database. It just calls add with empty arguments
|
||||
"""
|
||||
check_output("repo-add", *self.sign_args, str(self.repo_path),
|
||||
cwd=self.paths.repository, logger=self.logger, user=self.uid)
|
||||
|
||||
def remove(self, package: str, filename: Path) -> None:
|
||||
Args:
|
||||
root(Path): path to repository root
|
||||
"""
|
||||
check_output("repo-add", *self.sign_args, str(self.repo_path(root)),
|
||||
cwd=root, logger=self.logger, user=self.uid)
|
||||
|
||||
def remove(self, package: str, filename: Path, root: Path) -> None:
|
||||
"""
|
||||
remove package from repository
|
||||
|
||||
Args:
|
||||
package(str): package name to remove
|
||||
filename(Path): package filename to remove
|
||||
root(Path): path to repository root
|
||||
"""
|
||||
# remove package and signature (if any) from filesystem
|
||||
for full_path in self.paths.repository.glob(f"{filename}*"):
|
||||
for full_path in root.glob(f"**/{filename}*"):
|
||||
full_path.unlink()
|
||||
|
||||
# remove package from registry
|
||||
check_output(
|
||||
"repo-remove", *self.sign_args, str(self.repo_path), package,
|
||||
"repo-remove", *self.sign_args, str(self.repo_path(root)), package,
|
||||
exception=BuildError.from_process(package),
|
||||
cwd=self.paths.repository,
|
||||
logger=self.logger,
|
||||
user=self.uid)
|
||||
user=self.uid,
|
||||
)
|
||||
|
||||
def repo_path(self, root: Path) -> Path:
|
||||
"""
|
||||
get full path to the repository database
|
||||
|
||||
Args:
|
||||
root(Path): repository root
|
||||
|
||||
Returns:
|
||||
Path: path to repository database
|
||||
"""
|
||||
return root / f"{self.name}.db.tar.gz"
|
||||
|
@ -17,7 +17,7 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
import shutil
|
||||
import shutil # shutil.move is used here to ensure cross fs file movement
|
||||
|
||||
from collections.abc import Iterable
|
||||
from pathlib import Path
|
||||
@ -187,9 +187,12 @@ class Executor(PackageInfo, Cleaner):
|
||||
# in theory, it might be NOT packages directory, but we suppose it is
|
||||
full_path = self.paths.packages / name
|
||||
files = self.sign.process_sign_package(full_path, packager_key)
|
||||
|
||||
for src in files:
|
||||
dst = self.paths.repository / safe_filename(src.name)
|
||||
shutil.move(src, dst)
|
||||
archive = self.paths.archive_for(package_base) / safe_filename(src.name)
|
||||
shutil.move(src, archive)
|
||||
if not (symlink := self.paths.repository / archive.name).exists():
|
||||
symlink.symlink_to(archive.relative_to(symlink.parent, walk_up=True))
|
||||
package_path = self.paths.repository / safe_filename(name)
|
||||
self.repo.add(package_path)
|
||||
|
||||
|
@ -85,6 +85,16 @@ class RepositoryPaths(LazyLogging):
|
||||
return Path(self.repository_id.architecture) # legacy tree suffix
|
||||
return Path(self.repository_id.name) / self.repository_id.architecture
|
||||
|
||||
@property
|
||||
def archive(self) -> Path:
|
||||
"""
|
||||
archive directory root
|
||||
|
||||
Returns:
|
||||
Path: archive directory root
|
||||
"""
|
||||
return self.root / "archive" / self._suffix
|
||||
|
||||
@property
|
||||
def build_root(self) -> Path:
|
||||
"""
|
||||
@ -249,6 +259,23 @@ class RepositoryPaths(LazyLogging):
|
||||
set_owner(path)
|
||||
path = path.parent
|
||||
|
||||
def archive_for(self, package_base: str) -> Path:
|
||||
"""
|
||||
get path to archive specified search criteria
|
||||
|
||||
Args:
|
||||
package_base(str): package base name
|
||||
|
||||
Returns:
|
||||
Path: path to archive directory for package base
|
||||
"""
|
||||
directory = self.archive / package_base[0] / package_base
|
||||
if not directory.is_dir(): # create if not exists
|
||||
with self.preserve_owner(self.archive):
|
||||
directory.mkdir(mode=0o755, parents=True)
|
||||
|
||||
return directory
|
||||
|
||||
def cache_for(self, package_base: str) -> Path:
|
||||
"""
|
||||
get path to cached PKGBUILD and package sources for the package base
|
||||
@ -320,6 +347,7 @@ class RepositoryPaths(LazyLogging):
|
||||
|
||||
with self.preserve_owner():
|
||||
for directory in (
|
||||
self.archive,
|
||||
self.cache,
|
||||
self.chroot,
|
||||
self.packages,
|
||||
|
Reference in New Issue
Block a user