adding reagent tool md5remote that remotely checks packages hash

git-svn-id: http://svn.sabayonlinux.org/projects/entropy/trunk@657 cd1c1023-2f26-0410-ae45-c471fc1f0318
This commit is contained in:
(no author)
2007-11-11 16:44:38 +00:00
parent a1c2fe3f95
commit d331c2caac
4 changed files with 111 additions and 14 deletions

View File

@@ -70,8 +70,8 @@ def sync(options, justTidy = False):
# if packages are ok, we can sync the database
database(["sync"])
# now check packages checksum
import databaseTools
databaseTools.database(['md5check','--noask'])
import reagentTools
reagentTools.database(['md5check','--noask'])
time.sleep(2)
if (not activatorRequestNoAsk):
# ask question
@@ -670,8 +670,8 @@ def packages(options):
# Now we should start to check all the packages in the packages directory
if (activatorRequestPackagesCheck):
import databaseTools
databaseTools.database(['md5check'])
import reagentTools
reagentTools.database(['md5check'])
def database(options):

View File

@@ -263,5 +263,5 @@ def writechar(char):
def readtext(request):
xtermTitle("Entropy needs your attention")
text = raw_input(request)
text = raw_input(request) # using readline module
return text

View File

@@ -949,7 +949,7 @@ def database(options):
pass
dbconn.closeDB()
print_info(red(" * ")+bold("WARNING")+red(": database file already exists. Overwriting."))
rc = entropyTools.askquestion("\n Do you want to continue ?")
rc = askquestion("\n Do you want to continue ?")
if rc == "No":
exit(0)
os.remove(etpConst['etpdatabasefilepath'])
@@ -1099,7 +1099,7 @@ def database(options):
atom = dbconn.retrieveAtom(pkg)
print_info(red(" (*) ")+bold(atom))
rc = entropyTools.askquestion(" Would you like to continue ?")
rc = askquestion(" Would you like to continue ?")
if rc == "No":
exit(0)
@@ -1141,7 +1141,7 @@ def database(options):
# change filename remotely
for uri in etpConst['activatoruploaduris']:
print_info(green(" * ")+darkred(atom+": ")+red("Moving file remotely on: ")+entropyTools.extractFTPHostFromUri(uri), back = True)
print_info(green(" * ")+darkred(atom+": ")+red("Moving file remotely on: ")+extractFTPHostFromUri(uri), back = True)
ftp = mirrorTools.handlerFTP(uri)
ftp.setCWD(etpConst['binaryurirelativepath'])
@@ -1202,7 +1202,7 @@ def database(options):
print_info(red("\t (*) ")+bold(pkgatom)+blue(" [")+red(branch)+blue("]"))
# ask to continue
rc = entropyTools.askquestion(" Would you like to continue ?")
rc = askquestion(" Would you like to continue ?")
if rc == "No":
exit(0)
@@ -1246,9 +1246,11 @@ def database(options):
# catch the names
pkgs2check = []
for pkg in mypackages:
results = dbconn.searchPackages(pkg)
for i in results:
pkgs2check.append(i)
result = dbconn.atomMatch(pkg)
if result[0] != -1:
iatom = dbconn.retrieveAtom(result[0])
ibranch = dbconn.retrieveBranch(result[0])
pkgs2check.append((iatom,result[0],ibranch))
if (not worldSelected):
print_info(red(" This is the list of the packages that would be checked:"))
@@ -1274,7 +1276,7 @@ def database(options):
toBeDownloaded.append([idpackage,pkgfile,pkgbranch])
if (not databaseRequestNoAsk):
rc = entropyTools.askquestion(" Would you like to continue ?")
rc = askquestion(" Would you like to continue ?")
if rc == "No":
exit(0)
@@ -1319,7 +1321,7 @@ def database(options):
pkgfile = os.path.basename(pkgfile)
print_info(" ("+red(str(currentcounter))+"/"+blue(totalcounter)+") "+red("Checking hash of ")+yellow(pkgfile)+red(" in branch: ")+blue(pkgbranch)+red(" ..."), back = True)
storedmd5 = dbconn.retrieveDigest(pkg)
result = entropyTools.compareMd5(etpConst['packagesbindir']+"/"+pkgbranch+"/"+pkgfile,storedmd5)
result = compareMd5(etpConst['packagesbindir']+"/"+pkgbranch+"/"+pkgfile,storedmd5)
if (result):
# match !
pkgMatch += 1
@@ -1346,3 +1348,97 @@ def database(options):
print_info(green(" Number of happy downloads:\t\t")+str(pkgDownloadedSuccessfully))
print_info(red(" Number of failed downloads:\t\t")+str(pkgDownloadedError))
# used by reagent
elif (options[0] == "md5remote"):
print_info(green(" * ")+red("Integrity verification of the selected packages:"))
mypackages = options[1:]
dbconn = databaseTools.openServerDatabase(readOnly = True, noUpload = True)
worldSelected = False
if (len(mypackages) == 0):
# check world
# create packages list
worldSelected = True
pkgs2check = dbconn.listAllIdpackages()
elif (mypackages[0] == "world"):
# check world
# create packages list
worldSelected = True
pkgs2check = dbconn.listAllIdpackages()
else:
# catch the names
pkgs2check = []
for pkg in mypackages:
result = dbconn.atomMatch(pkg)
if result[0] != -1:
pkgs2check.append(result[0])
else:
print_warning(red("ATTENTION: ")+blue("cannot match: ")+bold(pkg))
if (not worldSelected):
print_info(red(" This is the list of the packages that would be checked:"))
else:
print_info(red(" All the packages in the Entropy Packages repository will be checked."))
if (not worldSelected):
for idpackage in pkgs2check:
pkgatom = dbconn.retrieveAtom(idpackage)
pkgbranch = dbconn.retrieveBranch(idpackage)
pkgfile = os.path.basename(dbconn.retrieveDownloadURL(idpackage))
print_info(green(" - ")+red(pkgatom)+" -> "+bold(str(pkgbranch)+"/"+pkgfile))
if (not databaseRequestNoAsk):
rc = askquestion(" Would you like to continue ?")
if rc == "No":
exit(0)
import remoteTools
for uri in etpConst['activatoruploaduris']:
# statistic vars
pkgMatch = 0
pkgNotMatch = 0
currentcounter = 0
print_info(green(" * ")+yellow("Working on ")+bold(extractFTPHostFromUri(uri)+red(" mirror.")))
brokenPkgsList = []
totalcounter = str(len(pkgs2check))
for idpackage in pkgs2check:
currentcounter += 1
pkgfile = dbconn.retrieveDownloadURL(idpackage)
pkgbranch = dbconn.retrieveBranch(idpackage)
pkgfilename = os.path.basename(pkgfile)
print_info(" ("+red(str(currentcounter))+"/"+blue(totalcounter)+") "+red("Checking hash of ")+blue(pkgbranch+"/"+pkgfilename), back = True)
ckOk = False
ck = remoteTools.getRemotePackageChecksum(extractFTPHostFromUri(uri),pkgfilename, pkgbranch)
if ck == None:
print_warning(" "+red(" -> Digest verification of ")+green(pkgfilename)+bold(" not supported"))
elif len(ck) == 32:
ckOk = True
if (ckOk):
pkgMatch += 1
else:
pkgNotMatch += 1
print_error(red(" Package ")+blue(pkgbranch+"/"+pkgfilename)+red(" is NOT healthy."))
brokenPkgsList.append(pkgbranch+"/"+pkgfilename)
if (brokenPkgsList):
print_info(blue(" * This is the list of broken packages: "))
for bp in brokenPkgsList:
print_info(red(" * Package: ")+bold(bp))
# print stats
print_info(blue(" * Statistics for "+extractFTPHostFromUri(uri)+":"))
print_info(yellow(" Number of checked packages:\t\t")+str(pkgMatch+pkgNotMatch))
print_info(green(" Number of healthy packages:\t\t")+str(pkgMatch))
print_info(red(" Number of broken packages:\t\t")+str(pkgNotMatch))
dbconn.closeDB()

View File

@@ -53,6 +53,7 @@ def print_help():
print_info(" \t\t"+green("create-empty-database")+"\t\t Create an empty Entropy database file in the specified <path>")
print_info(" \t\t"+green("switchbranch")+"\t\t\t Switch to the specified branch, a package, a list of packages, world")
print_info(" \t\t"+green("md5check")+"\t\t\t Check digest of a package, a list of packages, world")
print_info(" \t\t"+green("md5remote")+"\t\t\t Compare digest of a package between database and mirrors")
print_info(" \t"+green("deptest")+yellow("\t\t Look for unsatisfied dependencies inside database"))
print_info(" \t"+green("depends")+yellow("\t\t Regenerate depends table (plus database lock and bump)"))
print_info(" \t\t"+red("--quiet")+"\t\t\t\t just print the dependencies list")