forked from Mirror/pmbootstrap
* Two new functions for getting a list of files and their timestamps in the repo, and diffing that information to get a list of changed files: pmb.helpers.repo.files() and pmb.helpers.repo.diff(). (I've put it in the helpers folder, because it is not specific to one chroot, but to all chroots at once.) * pmbootstrap challenge (new command introduced a few commits back to verify, that the contents of an APK file are deterministic) uses these functions to a) support subpackages and b) optionally output a list of changed files (this gets used in the pmbuilder script, which lives outside of this repository). This commit is progress for #64 again.
60 lines
1.9 KiB
Python
60 lines
1.9 KiB
Python
"""
|
|
Copyright 2017 Oliver Smith
|
|
|
|
This file is part of pmbootstrap.
|
|
|
|
pmbootstrap is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
pmbootstrap is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with pmbootstrap. If not, see <http://www.gnu.org/licenses/>.
|
|
"""
|
|
import glob
|
|
import os
|
|
|
|
|
|
def files(args):
|
|
"""
|
|
Returns all files (apk/buildinfo) with their last modification timestamp
|
|
inside the package repository, sorted by architecture.
|
|
|
|
:returns: {"x86_64": {"first.apk": last_modified_timestamp, ... }, ... }
|
|
"""
|
|
ret = {}
|
|
for arch_folder in glob.glob(args.work + "/packages/*"):
|
|
arch = os.path.basename(arch_folder)
|
|
ret[arch] = {}
|
|
for file in glob.glob(arch_folder + "/*"):
|
|
basename = os.path.basename(file)
|
|
ret[arch][basename] = os.path.getmtime(file)
|
|
return ret
|
|
|
|
|
|
def diff(args, files_a, files_b=None):
|
|
"""
|
|
Returns a list of files, that have been added or modified inside the
|
|
package repository.
|
|
|
|
:param files_a: return value from pmb.helpers.repo.files()
|
|
:param files_b: defaults to creating a new list
|
|
:returns: ["x86_64/APKINDEX.tar.gz", "x86_64/package.apk",
|
|
"x86_64/package.buildinfo", ...]
|
|
"""
|
|
if not files_b:
|
|
files_b = files(args)
|
|
|
|
ret = []
|
|
for arch in files_b.keys():
|
|
for file, timestamp in files_b[arch].items():
|
|
if (arch not in files_a or file not in files_a[arch] or
|
|
timestamp is not files_a[arch][file]):
|
|
ret.append(arch + "/" + file)
|
|
|
|
return sorted(ret)
|