database sync now is working again
git-svn-id: http://svn.sabayonlinux.org/projects/entropy/trunk@231 cd1c1023-2f26-0410-ae45-c471fc1f0318
This commit is contained in:
@@ -50,6 +50,7 @@ def print_help():
|
||||
entropyTools.print_info(" \t\t"+entropyTools.green("search")+"\t\t\t Search a package inside the Entropy packages database")
|
||||
entropyTools.print_info(" \t\t"+entropyTools.green("dump-package-info")+"\t Dump the stored information of package atom(s) to a file")
|
||||
entropyTools.print_info(" \t\t"+entropyTools.green("inject-package-info")+"\t Inject an Entropy dump inside the database (file path is mandatory)")
|
||||
entropyTools.print_info(" \t\t"+entropyTools.green("restore-package-info")+"\t Reinitialize a package entry looking at the current install.")
|
||||
entropyTools.print_info(" \t"+entropyTools.green(entropyTools.bold("cleanup"))+entropyTools.yellow("\t\t to clean temporary files"))
|
||||
|
||||
options = sys.argv[1:]
|
||||
|
||||
@@ -30,6 +30,7 @@ from pysqlite2 import dbapi2 as sqlite
|
||||
#import re
|
||||
import os
|
||||
import sys
|
||||
import string
|
||||
|
||||
# TIP OF THE DAY:
|
||||
# never nest closeDB() and re-init inside a loop !!!!!!!!!!!! NEVER !
|
||||
@@ -42,13 +43,13 @@ def database(options):
|
||||
if (options[0] == "--initialize"):
|
||||
# initialize the database
|
||||
entropyTools.print_info(entropyTools.green(" * ")+entropyTools.red("Initializing Entropy database..."), back = True)
|
||||
# database file: etpConst['etpdatabasefile']
|
||||
if os.path.isfile(etpConst['etpdatabasefile']):
|
||||
# database file: etpConst['etpdatabasefilepath']
|
||||
if os.path.isfile(etpConst['etpdatabasefilepath']):
|
||||
entropyTools.print_info(entropyTools.red(" * ")+entropyTools.bold("WARNING")+entropyTools.red(": database file already exists. Overwriting."))
|
||||
rc = askquestion("\n Do you want to continue ?")
|
||||
if rc == "No":
|
||||
sys.exit(0)
|
||||
os.system("rm -f "+etpConst['etpdatabasefile'])
|
||||
os.system("rm -f "+etpConst['etpdatabasefilepath'])
|
||||
|
||||
# fill the database
|
||||
dbconn = etpDatabase()
|
||||
@@ -56,13 +57,13 @@ def database(options):
|
||||
|
||||
entropyTools.print_info(entropyTools.green(" * ")+entropyTools.red("Reinitializing Entropy database using Portage database..."))
|
||||
# now run quickpkg for all the packages and then extract data
|
||||
installedAtoms, atomsnumber = getInstalledPackages()
|
||||
installedAtoms, atomsnumber = entropyTools.getInstalledPackages()
|
||||
currCounter = 0
|
||||
import reagentTools
|
||||
for atom in installedAtoms:
|
||||
currCounter += 1
|
||||
entropyTools.print_info(entropyTools.green(" (")+ entropyTools.blue(str(currCounter))+"/"+entropyTools.red(str(atomsnumber))+entropyTools.green(") ")+entropyTools.red("Analyzing ")+entropyTools.bold(atom)+entropyTools.red(" ..."))
|
||||
quickpkg(atom,etpConst['packagestmpdir'])
|
||||
entropyTools.quickpkg(atom,etpConst['packagestmpdir'])
|
||||
# file is etpConst['packagestmpdir']+"/atomscan/"+pkgnamever.tbz2
|
||||
etpData = reagentTools.extractPkgData(etpConst['packagestmpdir']+"/"+atom.split("/")[1]+".tbz2")
|
||||
# fill the db entry
|
||||
@@ -79,7 +80,7 @@ def database(options):
|
||||
if (len(mykeywords) == 0):
|
||||
entropyTools.print_error(entropyTools.yellow(" * ")+entropyTools.red("Not enough parameters"))
|
||||
sys.exit(302)
|
||||
if (not os.path.isfile(etpConst['etpdatabasefile'])):
|
||||
if (not os.path.isfile(etpConst['etpdatabasefilepath'])):
|
||||
entropyTools.print_error(entropyTools.yellow(" * ")+entropyTools.red("Entropy Datbase does not exist"))
|
||||
sys.exit(303)
|
||||
# search tool
|
||||
@@ -213,7 +214,39 @@ def database(options):
|
||||
"""
|
||||
# print out the changes before doing them?
|
||||
|
||||
elif (options[0] == "restore-package-info"):
|
||||
mypackages = options[1:]
|
||||
if (len(mypackages) == 0):
|
||||
entropyTools.print_error(entropyTools.yellow(" * ")+entropyTools.red("Not enough parameters"))
|
||||
sys.exit(302)
|
||||
|
||||
dbconn = etpDatabase()
|
||||
|
||||
entropyTools.print_info(entropyTools.green(" * ")+entropyTools.red("Reinitializing Entropy database entries for the specified applications ..."))
|
||||
# now run quickpkg for all the packages and then extract data
|
||||
import reagentTools
|
||||
for atom in mypackages:
|
||||
if (entropyTools.isjustname(atom)) or (atom.find("/") == -1):
|
||||
entropyTools.print_info((entropyTools.red(" * Package ")+entropyTools.bold(atom)+entropyTools.red(" is not a complete atom, skipping ...")))
|
||||
continue
|
||||
if (entropyTools.getInstalledAtom("="+atom) is None):
|
||||
entropyTools.print_info((entropyTools.red(" * Package ")+entropyTools.bold(atom)+entropyTools.red(" is not installed, skipping ...")))
|
||||
continue
|
||||
entropyTools.print_info((entropyTools.red("Restoring entry for ")+entropyTools.bold(atom)+entropyTools.red(" ...")))
|
||||
entropyTools.quickpkg(atom,etpConst['packagestmpdir'])
|
||||
# file is etpConst['packagestmpdir']+"/atomscan/"+pkgnamever.tbz2
|
||||
etpData = reagentTools.extractPkgData(etpConst['packagestmpdir']+"/"+atom.split("/")[1]+".tbz2")
|
||||
# fill the db entry
|
||||
dbconn.removePackage(etpData['category']+"/"+etpData['name']+"-"+etpData['version'])
|
||||
dbconn.addPackage(etpData)
|
||||
entropyTools.print_info((entropyTools.green(" * ")+entropyTools.red(" Successfully restored database information for ")+entropyTools.bold(atom)+entropyTools.red(" .")))
|
||||
os.system("rm -rf "+etpConst['packagestmpdir']+"/"+atom.split("/")[1]+"*")
|
||||
|
||||
dbconn.commitChanges()
|
||||
dbconn.closeDB()
|
||||
entropyTools.print_info(entropyTools.green(" * ")+entropyTools.red("Done."))
|
||||
|
||||
|
||||
|
||||
|
||||
############
|
||||
@@ -267,7 +300,7 @@ class etpDatabase:
|
||||
# The first time you run this, sync the database and then lock
|
||||
# FIXME: do this
|
||||
# initialization open the database connection
|
||||
self.connection = sqlite.connect(etpConst['etpdatabasefile'])
|
||||
self.connection = sqlite.connect(etpConst['etpdatabasefilepath'])
|
||||
self.cursor = self.connection.cursor()
|
||||
|
||||
def closeDB(self):
|
||||
@@ -329,7 +362,6 @@ class etpDatabase:
|
||||
if (not self.isPackageAvailable(etpData['category']+"/"+etpData['name']+"-"+etpData['version'])):
|
||||
update, revision = self.addPackage(etpData)
|
||||
else:
|
||||
print "update"
|
||||
update, revision = self.updatePackage(etpData,forceBump)
|
||||
return update, revision
|
||||
|
||||
@@ -411,13 +443,8 @@ class etpDatabase:
|
||||
for i in myEtpData:
|
||||
myEtpData[i] = self.retrievePackageVar(dbPkgInfo,i)
|
||||
|
||||
print etpData
|
||||
print
|
||||
print myEtpData
|
||||
|
||||
for i in etpData:
|
||||
if etpData[i] != myEtpData[i]:
|
||||
print "differs"
|
||||
return False
|
||||
|
||||
return True
|
||||
@@ -471,7 +498,7 @@ class handlerFTP:
|
||||
|
||||
self.ftpuri = ftpuri
|
||||
|
||||
self.ftphost = extractFTPHostFromUri(self.ftpuri)
|
||||
self.ftphost = entropyTools.extractFTPHostFromUri(self.ftpuri)
|
||||
|
||||
self.ftpuser = ftpuri.split("ftp://")[len(ftpuri.split("ftp://"))-1].split(":")[0]
|
||||
if (self.ftpuser == ""):
|
||||
|
||||
@@ -105,6 +105,7 @@ ETP_REPODIR = "/packages"+"/"+ETP_ARCH_CONST
|
||||
ETP_PORTDIR = "/portage"
|
||||
ETP_DISTFILESDIR = "/distfiles"
|
||||
ETP_DBDIR = "/database/"+ETP_ARCH_CONST
|
||||
ETP_DBFILE = "packages.db"
|
||||
ETP_UPLOADDIR = "/upload"+"/"+ETP_ARCH_CONST
|
||||
ETP_STOREDIR = "/store"+"/"+ETP_ARCH_CONST
|
||||
ETP_CONF_DIR = "/etc/entropy"
|
||||
@@ -136,15 +137,18 @@ etpConst = {
|
||||
'binaryurirelativepath': "packages/"+ETP_ARCH_CONST+"/", # Relative remote path for the binary repository.
|
||||
'etpurirelativepath': "database/"+ETP_ARCH_CONST+"/", # Relative remote path for the .etp repository.
|
||||
# TO BE REMOVED? CHECK
|
||||
'etpdatabaserevisionfile': "packages.db.revision", # the local/remote database revision file
|
||||
'etpdatabaselockfile': "packages.db.lock", # the remote database lock file
|
||||
'etpdatabasedownloadlockfile': "packages.db.download.lock", # the remote database download lock file
|
||||
'etpdatabasetaintfile': "packages.db.tainted", # when this file exists, the database is not synced anymore with the online one
|
||||
'etpdatabaserevisionfile': ETP_DBFILE+".revision", # the local/remote database revision file
|
||||
'etpdatabasehashfile': ETP_DBFILE+".md5", # its checksum
|
||||
'etpdatabaselockfile': ETP_DBFILE+".lock", # the remote database lock file
|
||||
'etpdatabasedownloadlockfile': ETP_DBFILE+".download.lock", # the remote database download lock file
|
||||
'etpdatabasetaintfile': ETP_DBFILE+".tainted", # when this file exists, the database is not synced anymore with the online one
|
||||
'etpdatabasefile': ETP_DBFILE, # Entropy sqlite database file ETP_DIR+ETP_DBDIR+"/packages.db"
|
||||
'etpdatabasefilegzip': ETP_DBFILE+".gz", # Entropy sqlite database file (gzipped)
|
||||
'logdir': ETP_LOG_DIR , # Log dir where ebuilds store their shit
|
||||
'distcc-status': False, # used by Enzyme, if True distcc is enabled
|
||||
'distccconf': "/etc/distcc/hosts", # distcc hosts configuration file
|
||||
'etpdatabasedir': ETP_DIR+ETP_DBDIR, # FIXME: REMOVE THIS !
|
||||
'etpdatabasefile': ETP_DIR+ETP_DBDIR+"/packages.db", # Entropy sqlite database file
|
||||
'etpdatabasefilepath': ETP_DIR+ETP_DBDIR+"/"+ETP_DBFILE,
|
||||
'etpapi': ETP_API, # Entropy database API revision
|
||||
'headertext': ETP_HEADER_TEXT, # header text that can be outputted to a file
|
||||
'currentarch': ETP_ARCH_CONST, # contains the current running architecture
|
||||
@@ -156,7 +160,7 @@ if not os.path.isdir(ETP_DIR):
|
||||
if getpass.getuser() == "root":
|
||||
import re
|
||||
for x in etpConst:
|
||||
if (etpConst[x]) and (not etpConst[x].endswith(".conf")) and (not etpConst[x].endswith(".cfg")) and (not etpConst[x].endswith(".tmp")):
|
||||
if (etpConst[x]) and (not etpConst[x].endswith(".conf")) and (not etpConst[x].endswith(".cfg")) and (not etpConst[x].endswith(".tmp")) and (etpConst[x].find(".db") == -1):
|
||||
|
||||
if etpConst[x].find("%ARCH%") != -1:
|
||||
for i in ETP_ARCHS:
|
||||
|
||||
@@ -779,23 +779,23 @@ def getEtpRemoteDatabaseStatus():
|
||||
for uri in etpConst['activatoruploaduris']:
|
||||
ftp = databaseTools.handlerFTP(uri)
|
||||
ftp.setCWD(etpConst['etpurirelativepath'])
|
||||
rc = ftp.isFileAvailable(translateArchFromUname(ETP_ARCH_CONST)+etpConst['etpdatabasefile'])
|
||||
rc = ftp.isFileAvailable(etpConst['etpdatabasefile'])
|
||||
if (rc):
|
||||
# then get the file revision, if exists
|
||||
rc = ftp.isFileAvailable(translateArchFromUname(ETP_ARCH_CONST)+etpConst['etpdatabasefile']+".revision")
|
||||
rc = ftp.isFileAvailable(etpConst['etpdatabaserevisionfile'])
|
||||
if (rc):
|
||||
# get the revision number
|
||||
ftp.downloadFile(translateArchFromUname(ETP_ARCH_CONST) + etpConst['etpdatabasefile'] + ".revision",etpConst['packagestmpdir'],True)
|
||||
f = open( etpConst['packagestmpdir'] + "/" + translateArchFromUname(ETP_ARCH_CONST) + etpConst['etpdatabasefile'] + ".revision","r")
|
||||
ftp.downloadFile(etpConst['etpdatabaserevisionfile'],etpConst['packagestmpdir'],True)
|
||||
f = open( etpConst['packagestmpdir'] + "/" + etpConst['etpdatabaserevisionfile'],"r")
|
||||
revision = int(f.readline().strip())
|
||||
f.close()
|
||||
os.system("rm -f "+etpConst['packagestmpdir']+translateArchFromUname(ETP_ARCH_CONST)+etpConst['etpdatabasefile']+".revision")
|
||||
os.system("rm -f "+etpConst['packagestmpdir']+etpConst['etpdatabaserevisionfile'])
|
||||
else:
|
||||
revision = 0
|
||||
else:
|
||||
# then set mtime to 0 and quit
|
||||
revision = 0
|
||||
info = [uri+"/"+etpConst['etpurirelativepath']+translateArchFromUname(ETP_ARCH_CONST)+etpConst['etpdatabasefile'],revision]
|
||||
info = [uri+"/"+etpConst['etpurirelativepath']+etpConst['etpdatabasefile'],revision]
|
||||
uriDbInfo.append(info)
|
||||
ftp.closeFTPConnection()
|
||||
|
||||
@@ -811,21 +811,15 @@ def syncRemoteDatabases():
|
||||
print_info(red("\t * Database revision: ")+blue(str(dbstat[1])))
|
||||
|
||||
# check if the local DB exists
|
||||
etpDbLocalPath = etpConst['etpurirelativepath']
|
||||
etpDbLocalFile = etpConst['etpdatabasedir']
|
||||
if etpDbLocalFile.endswith("/"):
|
||||
etpDbLocalFile = etpDbLocalFile[:len(etpDbLocalFile)-1]
|
||||
etpDbLocalFile += etpConst['etpdatabasefile']
|
||||
if os.path.isfile(etpDbLocalFile) and os.path.isfile(etpDbLocalFile+".revision"):
|
||||
if os.path.isfile(etpConst['etpdatabasefilepath']) and os.path.isfile(etpConst['etpdatabasedir'] + "/" + etpConst['etpdatabaserevisionfile']):
|
||||
# file exist, get revision
|
||||
f = open(etpDbLocalFile+".revision","r")
|
||||
f = open(etpConst['etpdatabasedir'] + "/" + etpConst['etpdatabaserevisionfile'],"r")
|
||||
etpDbLocalRevision = int(f.readline().strip())
|
||||
f.close()
|
||||
else:
|
||||
etpDbLocalRevision = 0
|
||||
|
||||
|
||||
generateAndUpload = False
|
||||
downloadLatest = []
|
||||
uploadLatest = False
|
||||
uploadList = []
|
||||
@@ -842,7 +836,8 @@ def syncRemoteDatabases():
|
||||
if etpDbRemotePaths == []:
|
||||
#print "DEBUG: generate and upload"
|
||||
# (to all!)
|
||||
generateAndUpload = True
|
||||
uploadLatest = True
|
||||
uploadList = remoteDbsStatus
|
||||
else:
|
||||
#print "DEBUG: get the latest ?"
|
||||
revisions = []
|
||||
@@ -915,7 +910,7 @@ def syncRemoteDatabases():
|
||||
for uri in etpConst['activatoruploaduris']:
|
||||
if downloadLatest[0].startswith(uri):
|
||||
downloadLatest[0] = uri
|
||||
downloadDatabase(downloadLatest[0],etpDbLocalFile)
|
||||
downloadDatabase(downloadLatest[0])
|
||||
|
||||
if (uploadLatest):
|
||||
print_info(green(" * ")+red("Starting to update the needed mirrors ..."))
|
||||
@@ -928,104 +923,117 @@ def syncRemoteDatabases():
|
||||
break
|
||||
_uploadList.append(list[0])
|
||||
|
||||
uploadDatabase(_uploadList,etpDbLocalFile)
|
||||
uploadDatabase(_uploadList)
|
||||
print_info(green(" * ")+red("All the mirrors have been updated."))
|
||||
|
||||
if (generateAndUpload):
|
||||
print_info(green(" * ")+red("Compressing ETP Repository to ")+bold(etpDbLocalFile),back = True)
|
||||
rc = compressTarBz2(etpDbLocalFile,etpConst['etpdatabasedir'])
|
||||
if (rc):
|
||||
print_error(red(" * Cannot compress "+etpDbLocalFile))
|
||||
print_error(red(" *** Cannot continue"))
|
||||
sys.exit(120)
|
||||
print_info(green(" * ")+bold(etpDbLocalFile)+red(" has been succesfully created"))
|
||||
# create revision file
|
||||
f = open(etpDbLocalFile+".revision","w")
|
||||
f.write("1\n")
|
||||
f.flush()
|
||||
f.close()
|
||||
# digesting
|
||||
hexdigest = digestFile(etpDbLocalFile)
|
||||
f = open(etpDbLocalFile+".md5","w")
|
||||
filename = etpDbLocalFile.split("/")[len(etpDbLocalFile.split("/"))-1]
|
||||
f.write(hexdigest+" "+filename+"\n")
|
||||
f.flush()
|
||||
f.close()
|
||||
print_info(green(" * ")+red("Starting to update all the mirrors ..."))
|
||||
uploadDatabase(etpConst['activatoruploaduris'],etpDbLocalFile)
|
||||
print_info(green(" * ")+red("All the mirrors have been updated, it seems."))
|
||||
|
||||
|
||||
def uploadDatabase(uris,dbfile):
|
||||
def uploadDatabase(uris):
|
||||
|
||||
# our fancy compressor :-)
|
||||
import gzip
|
||||
|
||||
for uri in uris:
|
||||
lockDatabases(True,[uri])
|
||||
downloadLockDatabases(True,[uri])
|
||||
|
||||
print_info(green(" * ")+red("Uploading database to ")+bold(extractFTPHostFromUri(uri))+red(" ..."))
|
||||
print_info(green(" * ")+red("Connecting to ")+bold(extractFTPHostFromUri(uri))+red(" ..."), back = True)
|
||||
ftp = databaseTools.handlerFTP(uri)
|
||||
print_info(green(" * ")+red("Changing directory to ")+bold(etpConst['etpurirelativepath'])+red(" ..."), back = True)
|
||||
ftp.setCWD(etpConst['etpurirelativepath'])
|
||||
print_info(green(" * ")+red("Uploading file ")+bold(dbfile)+red(" ..."), back = True)
|
||||
|
||||
print_info(green(" * ")+red("Uploading file ")+bold(etpConst['etpdatabasefilegzip'])+red(" ..."), back = True)
|
||||
|
||||
# compress the database file first
|
||||
dbfile = open(etpConst['etpdatabasefilepath'],"rb")
|
||||
dbcont = dbfile.readlines()
|
||||
dbfile.close()
|
||||
dbfilegz = gzip.GzipFile(etpConst['etpdatabasedir'] + "/" + etpConst['etpdatabasefilegzip'],"wb")
|
||||
for i in dbcont:
|
||||
dbfilegz.write(i)
|
||||
dbfilegz.close()
|
||||
del dbcont
|
||||
|
||||
# uploading database file
|
||||
rc = ftp.uploadFile(dbfile)
|
||||
rc = ftp.uploadFile(etpConst['etpdatabasedir'] + "/" + etpConst['etpdatabasefilegzip'])
|
||||
if (rc.startswith("226")):
|
||||
print_info(green(" * ")+red("Upload of ")+bold(dbfile)+red(" completed."))
|
||||
print_info(green(" * ")+red("Upload of ")+bold(etpConst['etpdatabasefilegzip'])+red(" completed."))
|
||||
else:
|
||||
print_warning(yellow(" * ")+red("Cannot properly upload to ")+bold(extractFTPHostFromUri(uri))+red(". Please check."))
|
||||
print_info(green(" * ")+red("Uploading file ")+bold(dbfile+".revision")+red(" ..."), back = True)
|
||||
|
||||
# remove the gzip
|
||||
os.remove(etpConst['etpdatabasedir'] + "/" + etpConst['etpdatabasefilegzip'])
|
||||
|
||||
print_info(green(" * ")+red("Uploading file ")+bold(etpConst['etpdatabasedir'] + "/" + etpConst['etpdatabaserevisionfile'])+red(" ..."), back = True)
|
||||
# uploading revision file
|
||||
rc = ftp.uploadFile(dbfile+".revision",True)
|
||||
rc = ftp.uploadFile(etpConst['etpdatabasedir'] + "/" + etpConst['etpdatabaserevisionfile'],True)
|
||||
if (rc.startswith("226")):
|
||||
print_info(green(" * ")+red("Upload of ")+bold(dbfile+".revision")+red(" completed."))
|
||||
print_info(green(" * ")+red("Upload of ")+bold(etpConst['etpdatabasedir'] + "/" + etpConst['etpdatabaserevisionfile'])+red(" completed."))
|
||||
else:
|
||||
print_warning(yellow(" * ")+red("Cannot properly upload to ")+bold(extractFTPHostFromUri(uri))+red(". Please check."))
|
||||
# upload digest
|
||||
print_info(green(" * ")+red("Uploading file ")+bold(dbfile+".md5")+red(" ..."), back = True)
|
||||
rc = ftp.uploadFile(dbfile+".md5",True)
|
||||
if (rc.startswith("226")):
|
||||
print_info(green(" * ")+red("Upload of ")+bold(dbfile+".md5")+red(" completed. Disconnecting."))
|
||||
else:
|
||||
print_warning(yellow(" * ")+red("Cannot properly upload to ")+bold(extractFTPHostFromUri(uri))+red(". Please check."))
|
||||
downloadLockDatabases(False,[uri])
|
||||
lockDatabases(False,[uri])
|
||||
|
||||
def downloadDatabase(uri,dbfile):
|
||||
# generate digest
|
||||
hexdigest = digestFile(etpConst['etpdatabasefilepath'])
|
||||
f = open(etpConst['etpdatabasedir'] + "/" + etpConst['etpdatabasehashfile'],"w")
|
||||
f.write(hexdigest+" "+etpConst['etpdatabasehashfile']+"\n")
|
||||
f.flush()
|
||||
f.close()
|
||||
|
||||
# upload digest
|
||||
print_info(green(" * ")+red("Uploading file ")+bold(etpConst['etpdatabasedir'] + "/" + etpConst['etpdatabasehashfile'])+red(" ..."), back = True)
|
||||
rc = ftp.uploadFile(etpConst['etpdatabasedir'] + "/" + etpConst['etpdatabasehashfile'],True)
|
||||
if (rc.startswith("226")):
|
||||
print_info(green(" * ")+red("Upload of ")+bold(etpConst['etpdatabasedir'] + "/" + etpConst['etpdatabasehashfile'])+red(" completed. Disconnecting."))
|
||||
else:
|
||||
print_warning(yellow(" * ")+red("Cannot properly upload to ")+bold(extractFTPHostFromUri(uri))+red(". Please check."))
|
||||
|
||||
downloadLockDatabases(False,[uri])
|
||||
|
||||
def downloadDatabase(uri):
|
||||
|
||||
import gzip
|
||||
|
||||
print_info(green(" * ")+red("Downloading database from ")+bold(extractFTPHostFromUri(uri))+red(" ..."))
|
||||
print_info(green(" * ")+red("Connecting to ")+bold(extractFTPHostFromUri(uri))+red(" ..."), back = True)
|
||||
ftp = databaseTools.handlerFTP(uri)
|
||||
print_info(green(" * ")+red("Changing directory to ")+bold(etpConst['etpurirelativepath'])+red(" ..."), back = True)
|
||||
ftp.setCWD(etpConst['etpurirelativepath'])
|
||||
print_info(green(" * ")+red("Downloading file to ")+bold(dbfile)+red(" ..."), back = True)
|
||||
|
||||
|
||||
# downloading database file
|
||||
rc = ftp.downloadFile(dbfile.split("/")[len(dbfile.split("/"))-1],os.path.dirname(dbfile))
|
||||
print_info(green(" * ")+red("Downloading file to ")+bold(etpConst['etpdatabasefilegzip'])+red(" ..."), back = True)
|
||||
rc = ftp.downloadFile(etpConst['etpdatabasedir'] + "/" + etpConst['etpdatabasefilegzip'],os.path.dirname(etpConst['etpdatabasefilepath']))
|
||||
if (rc.startswith("226")):
|
||||
print_info(green(" * ")+red("Download of ")+bold(dbfile)+red(" completed."))
|
||||
print_info(green(" * ")+red("Download of ")+bold(etpConst['etpdatabasefilegzip'])+red(" completed."))
|
||||
else:
|
||||
print_warning(yellow(" * ")+red("Cannot properly download to ")+bold(extractFTPHostFromUri(uri))+red(". Please check."))
|
||||
print_info(green(" * ")+red("Downloading file to ")+bold(dbfile+".revision")+red(" ..."), back = True)
|
||||
|
||||
# On the fly decompression
|
||||
print_info(green(" * ")+red("Decompressing ")+bold(etpConst['etpdatabasefilegzip'])+red(" ..."), back = True)
|
||||
dbfile = open(etpConst['etpdatabasefilepath'],"wb")
|
||||
dbfilegz = gzip.GzipFile(etpConst['etpdatabasedir'] + "/" + etpConst['etpdatabasefilegzip'],"rb")
|
||||
dbcont = dbfilegz.readlines()
|
||||
dbfilegz.close()
|
||||
dbfile.writelines(dbcont)
|
||||
dbfile.flush()
|
||||
dbfile.close()
|
||||
del dbcont
|
||||
print_info(green(" * ")+red("Decompression of ")+bold(etpConst['etpdatabasefilegzip'])+red(" completed ..."))
|
||||
|
||||
# downloading revision file
|
||||
rc = ftp.downloadFile(dbfile.split("/")[len(dbfile.split("/"))-1]+".revision",os.path.dirname(dbfile),True)
|
||||
print_info(green(" * ")+red("Downloading file to ")+bold(etpConst['etpdatabaserevisionfile'])+red(" ..."), back = True)
|
||||
rc = ftp.downloadFile(etpConst['etpdatabaserevisionfile'],os.path.dirname(etpConst['etpdatabasefilepath']),True)
|
||||
if (rc.startswith("226")):
|
||||
print_info(green(" * ")+red("Download of ")+bold(dbfile+".revision")+red(" completed."))
|
||||
print_info(green(" * ")+red("Download of ")+bold(etpConst['etpdatabaserevisionfile'])+red(" completed."))
|
||||
else:
|
||||
print_warning(yellow(" * ")+red("Cannot properly download to ")+bold(extractFTPHostFromUri(uri))+red(". Please check."))
|
||||
|
||||
# downlading digest
|
||||
print_info(green(" * ")+red("Downloading file to ")+bold(dbfile+".md5")+red(" ..."), back = True)
|
||||
rc = ftp.downloadFile(dbfile.split("/")[len(dbfile.split("/"))-1]+".md5",os.path.dirname(dbfile),True)
|
||||
print_info(green(" * ")+red("Downloading file to ")+bold(etpConst['etpdatabasehashfile'])+red(" ..."), back = True)
|
||||
rc = ftp.downloadFile(etpConst['etpdatabasehashfile'],os.path.dirname(etpConst['etpdatabasefilepath']),True)
|
||||
if (rc.startswith("226")):
|
||||
print_info(green(" * ")+red("Download of ")+bold(dbfile+".md5")+red(" completed. Disconnecting."))
|
||||
print_info(green(" * ")+red("Download of ")+bold(etpConst['etpdatabasehashfile'])+red(" completed. Disconnecting."))
|
||||
else:
|
||||
print_warning(yellow(" * ")+red("Cannot properly download to ")+bold(extractFTPHostFromUri(uri))+red(". Please check."))
|
||||
# removing old tree
|
||||
print_info(green(" * ")+red("Uncompressing downloaded database ..."),back = True)
|
||||
os.system("rm -rf "+etpConst['etpdatabasedir']+"/*")
|
||||
rc = uncompressTarBz2(dbfile,"/")
|
||||
if (rc):
|
||||
print_error(red(" * Cannot uncompress "+dbfile))
|
||||
print_error(red(" *** Cannot continue"))
|
||||
sys.exit(120)
|
||||
else:
|
||||
print_info(green(" * ")+red("Downloaded database succesfully uncompressed."))
|
||||
|
||||
|
||||
# Reports in a list form the lock status of the mirrors
|
||||
|
||||
Reference in New Issue
Block a user