def scanDist(): sql.sql_delete_distrib("/serveur/ftp/linux/SuSE-Linux") sql.sql_delete_distrib("/serveur/ftp/linux/freshrpms") scanRedHat("/serveur/ftp/linux/redhat") scanSuSE("/serveur/ftp/linux/SuSE-Linux") scanFreshrpms("/serveur/ftp/linux/freshrpms") print("Found %d distributions" % (nb_distribs))
def sync_mirror(name, URL): query = string.replace(URL, 'search.php', 'servers.php') try: doc = libxml2.parseFile(query) except: print("failed to lookup servers from %s" % (name)) return ctxt = doc.xpathNewContext() try: count = ctxt.xpathEval("string(/servers/@count)"); servers = ctxt.xpathEval("//server") except: print("failed to find servers from %s servers list" % (name)) return print("%s exports %s servers" % (name, count)) for server in servers: try: Rname = server.xpathEval("string(name)"); RURL = server.xpathEval("string(URL)"); query = "INSERT INTO Searches (URL, name, active) VALUES \ ('%s', '%s', 1)" % (RURL, Rname) try: sql.cursor.execute(query) except: # ignore overwrites pass except: print("failed to read record from %s servers list" % (name)) doc.freeDoc() query = string.replace(URL, 'search.php', 'distribs.php') try: doc = libxml2.parseFile(query) except: print("failed to lookup distribs from %s" % (name)) return ctxt = doc.xpathNewContext() try: count = ctxt.xpathEval("string(/distribs/@count)"); distribs = ctxt.xpathEval("//distrib") except: print("failed to find distribs from %s distribs list" % (name)) return print("%s exports %s distribs" % (name, count)) for distrib in distribs: try: Directory = distrib.xpathEval("string(Directory)"); if exists(Directory): table = 'Distribs' else: table = 'OldDistribs' id = int(sql.sql_get_key(table, 'Directory', Directory)) Name = distrib.xpathEval("string(Name)"); if Name != None and Name != '': sql.sql_update_id(table, id, "Name", Name) Vendor = distrib.xpathEval("string(Vendor)"); if Vendor != None and Vendor != '': sql.sql_update_id(table, id, "Vendor", Vendor) Path = distrib.xpathEval("string(Path)"); if Path != None and Path != '': sql.sql_update_id(table, id, "Path", Path) RURL = distrib.xpathEval("string(URL)"); if RURL != None and RURL != '': sql.sql_update_id(table, id, "URL", RURL) URLSrc = distrib.xpathEval("string(URLSrc)"); if URLSrc != None and URLSrc != '': sql.sql_update_id(table, id, "URLSrc", URLSrc) Html = distrib.xpathEval("string(Html)"); if Html != None and Html != '': sql.sql_update_id(table, id, "Html", Html) Color = distrib.xpathEval("string(Color)"); if Color != None and Color != '': sql.sql_update_id(table, id, "Color", Color) Description = distrib.xpathEval("string(Description)"); if Description != None and Description != '': sql.sql_update_id(table, id, "Description", Description) except: print("failed to read record from %s servers list" % (name)) doc.freeDoc() query = string.replace(URL, 'search.php', 'mirrors.php') try: doc = libxml2.parseFile(query) except: print("failed to lookup mirrors from %s" % (name)) return ctxt = doc.xpathNewContext() try: count = ctxt.xpathEval("string(/mirrors/@count)"); dists = ctxt.xpathEval("//dist") except: print("failed to find mirrors from %s mirrors list" % (name)) return print("%s exports %s mirrors" % (name, count)) for dist in dists: try: rname = dist.xpathEval("string(@name)"); id = int(sql.sql_read_key('Distribs', rname)) mirrors = dist.xpathEval(".//mirror"); for mirror in mirrors: try: RURL=mirror.xpathEval("string(.)"); country=mirror.xpathEval("string(@country)"); if country != None and country != "": sql.cursor.execute("INSERT INTO Mirrors (ID,URL,Country) \ VALUES (%s,'%s', '%s')" % (id, RURL, country)) else: sql.cursor.execute("INSERT INTO Mirrors (ID,URL) \ VALUES (%s,'%s')" % (id, RURL)) except: pass except: print("failed to read record from %s mirrors list" % (name)) doc.freeDoc() # # Avoid reintroducing deleted distro after mirroring # sql.sql_delete_distrib("/serveur/ftp/linux/SuSE-Linux") sql.sql_delete_distrib("/serveur/ftp/linux/freshrpms")