Commit 56bb435c authored by Luca Giambonini's avatar Luca Giambonini

Imported 'akbm' from the cherry project

parents 5defdd74 d671ff80
This diff is collapsed.
#!/usr/bin/python3
# A script to clean pkg that doesn't belong to the current repository database, by parsing
# both the pkg in the pacman database and in the server repository, and if they
# don't match the removal
#
# Copyright (C) 2014 Luca Giambonini <gluca86@gmail.com>
# This program 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 2 of the License, or (at your option) any later version.
import sys
import os
from contextlib import closing
import tarfile
import gzip
def removeExtensions(pkg):
return pkg[:pkg.rindex("-")]
def duplicates(dirname,repository,pkglist):
duplicateDictionary = {}
with closing(gzip.GzipFile(os.path.join(dirname, repository + ".db.tar.gz"))) as xz:
with tarfile.open(fileobj=xz) as f:
try:
list_tar_pkg = f.getnames()
for pkg in pkglist:
pkgWithoutExtension = removeExtensions(pkg) # remove file extension and architecture string
if pkgWithoutExtension not in list_tar_pkg:
duplicateDictionary[pkgWithoutExtension] = [pkg]
except Exception as e:
print(e)
return duplicateDictionary
def printDups(dups):
if not dups:
print (":: No package files found, is all up to date :-) ")
return
else:
print (":: The package files which would be removed are: ")
for name in dups:
print(name)
def removeDups(dups, path):
if not dups:
print (":: No package files found, is all up to date :-) ")
return
for name in dups:
pkg = dups[name][0]
completePath = path + "/" + pkg
os.remove(completePath)
print(completePath)
if os.path.isfile(completePath + ".sig"):
os.remove(completePath + ".sig")
print(completePath + ".sig")
print(":: Files removed successfully")
def help():
print("-d <dir> Perform check on <dir>. If no argument is supplied, defaults to the current working directory.")
print("-r <repo> The repository name that you want to look <repo>. No extension is needed.")
print("-f Prints the file that would be removed, without touching them.")
print("-h This message")
exit(0)
if __name__ == "__main__":
dirname = ""
repository = ""
fake = False
for arg in sys.argv:
if (arg == "-d"):
i = sys.argv.index("-d")
if (i < len(sys.argv) - 1):
dirname = sys.argv[i+1]
else:
print(":: Error: directory name is missing after -d")
exit(-1)
if (arg == "-r"):
i = sys.argv.index("-r")
if (i < len(sys.argv) - 1):
repository = sys.argv[i+1]
else:
print(":: Error: repository name is missing after -r")
exit(-1)
elif (arg == "-f"):
fake = True
elif (arg == "-h") or (arg == "--help"):
help()
# No argument supplied
if len(dirname) == 0:
dirname = os.getcwd()
if len(repository) == 0:
print(":: Error: repository name is missing, use option -r <repo>")
exit(-1)
pkglist = [file for file in os.listdir(dirname) if file.endswith(".pkg.tar.xz")]
dup = duplicates(dirname,repository,pkglist)
if fake:
printDups(dup)
else:
removeDups(dup, dirname)
#!/usr/bin/python3
# This is used by akbm when checking new uploads (repo-check-upload command).
import os
import re
def RemoveSignatureExtension(filename):
index = filename.index('.sig')
return filename[:index]
def IsPackageFile(filename):
return filename.endswith('.pkg.tar.xz')
def IsSignatureFile(filename):
return filename.endswith('.pkg.tar.xz.sig')
def GetPackageName(filename):
"""Retrieves the name of a package, without the version
and pkgrel, from the archive file name."""
pkgNames = []
pkgVerRe = '[0-9.]+'
# Divide the file name in pieces by -, then add pieces
# until you find a piece which represents a version (through
# regular expression). Then all the "name pieces" are joined
# together again to return the complete name.
#
# This should deal with package names containing numbers.
pieces = filename.split('-')
for p in pieces:
if re.match(pkgVerRe, p):
break
pkgNames.append(p)
pkgName = '-'.join(pkgNames)
return pkgName
def missingSignature(filelist):
"""Checks whether there is a signature file for each
package file. Returns the list of package files with no
signature file."""
pkgsHasSig = {}
for f in filelist:
if IsPackageFile(f):
pkgsHasSig[f] = False
elif IsSignatureFile(f):
pkgsHasSig[RemoveSignatureExtension(f)] = True
return [x for x in pkgsHasSig if not pkgsHasSig[x]]
def checkDuplicates(reposPath, arch, repoName, filelist):
"""Checks whether the repository already contains the same
package file we are trying to upload. Returns the list of
duplicate files."""
repoPath = os.path.join(reposPath, repoName, arch)
print(repoPath)
dirListing = [ f for f in os.listdir(repoPath) if IsPackageFile(f) ]
intersection = set(filelist) & set(dirListing)
return intersection
# Calling this on a lib32 package should return an empty list.
def checkLib32Package(reposPath, arch, filelist):
"""Checks whether a package has a corresponding package in lib32. Returns
the list of lib32 package names that were found."""
repoPath = os.path.join(reposPath, 'lib32', arch)
repoListing = [ GetPackageName(f) for f in os.listdir(repoPath) if IsPackageFile(f) ]
packageNames32 = []
for pkgFile in filelist:
if IsSignatureFile(pkgFile):
continue
pkgName = GetPackageName(pkgFile)
pkgName = 'lib32-' + pkgName
# We are not concerned with comparing versions, since that adds
# complexity, only whether a lib32 package exists or not.
if pkgName in repoListing:
packageNames32.append(pkgName)
return packageNames32
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment