def getPkgs(): pkgs_pkgdb = getPackagesFromPkgDb() pkgs_local = loadPackages() # Any new or removed packages set_pkgdb = set(pkgs_pkgdb) set_local = set(pkgs_local) return set_pkgdb, set_local
script_dir = os.path.dirname(os.path.realpath(__file__)) def displayMapping(pkg, imap, fmt=False): if fmt: mlen = 0 for arg in imap: mlen = max(mlen, len(arg)) for arg in imap: print "%s%s -> %s" % (arg, " " * (mlen - len(arg)), ",".join(imap[arg])) else: for arg in imap: print "%s:%s:%s" % (arg, pkg, ",".join(imap[arg])) if __name__ == "__main__": packages = loadPackages() for pkg in packages: rsp_obj = RemoteSpecParser('master', pkg) if not rsp_obj.parse(): sys.stderr.write("%s: %s" % (pkg, rsp_obj.getError())) continue provides = rsp_obj.getProvides() imap = inverseMap(provides) displayMapping(pkg, imap)
def createDB(full=False, verbose=False): scan_time_start = time() packages = [] outdated = {} valid = {} if full: packages = loadPackages() else: print "Creating list of updated builds..." err, outdated = LocalDB().getOutdatedBuilds() if err != []: print "Warning: " + "\nWarning: ".join(err) packages = outdated.keys() if verbose: print "Packages to be scanned:" for pkg in packages: print "\t%s" % pkg print "" pkg_cnt = len(packages) pkg_idx = 1 pkg_name_len = 0 for package in packages: l = len(package) if l > pkg_name_len: pkg_name_len = l pkg_cnt_len = len("%s" % pkg_cnt) print "Updating spec file provides..." err, ret = LocalDB().updatePackages(packages) if not ret: print "Error:\n" + "\n".join(err) return False ipdb_cache = ImportPathDBCache() if not ipdb_cache.load(): print "Error: %s" % ipdb_cache.getError() return False golang_pkg = Config().getGolangPkgdb() for package in packages: starttime = time() # len of pkg_idx pkg_idx_len = len("%s" % pkg_idx) sys.stdout.write( "Scanning %s %s %s%s/%s " % (package, (pkg_name_len - len(package) + 3) * ".", (pkg_cnt_len - pkg_idx_len) * " ", pkg_idx, pkg_cnt) ) sys.stdout.flush() pkg = Package(package) info = pkg.getInfo() # save xml into file errs = savePackageInfo(info) if errs != []: print "" print "\n".join(errs) else: if not full: valid[package] = outdated[package] pkg_idx += 1 endtime = time() elapsedtime = endtime - starttime print strftime("[%Hh %Mm %Ss]", gmtime(elapsedtime)) # update cache of imported and provided packages for item in info: devel_name = item # This is hacky and depends on info data type represenation pkg2xml_obj = info[item]["xmlobj"] if pkg2xml_obj.getError() != "": continue imports = pkg2xml_obj.getImportedPackages() provides = pkg2xml_obj.getProvidedPackages() ipdb_cache.updateBuild(devel_name, provides, imports, package) if not ipdb_cache.flush(): print ipdb_cache.getError() scan_time_end = time() print strftime("Elapsed time %Hh %Mm %Ss", gmtime(scan_time_end - scan_time_start)) if not full: LocalDB().updateBuildsInCache(valid) return True
def createDB(full=False, verbose=False): scan_time_start = time() packages = [] outdated = {} valid = {} if full: packages = loadPackages() else: print "Creating list of updated builds..." err, outdated = LocalDB().getOutdatedBuilds() if err != []: print "Warning: " + "\nWarning: ".join(err) packages = outdated.keys() if verbose: print "Packages to be scanned:" for pkg in packages: print "\t%s" % pkg print "" pkg_cnt = len(packages) pkg_idx = 1 pkg_name_len = 0 for package in packages: l = len(package) if l > pkg_name_len: pkg_name_len = l pkg_cnt_len = len("%s" % pkg_cnt) print "Updating spec file provides..." err, ret = LocalDB().updatePackages(packages) if not ret: print "Error:\n" + "\n".join(err) return False ipdb_cache = ImportPathDBCache() if not ipdb_cache.load(): print "Error: %s" % ipdb_cache.getError() return False golang_pkg = Config().getGolangPkgdb() for package in packages: starttime = time() # len of pkg_idx pkg_idx_len = len("%s" % pkg_idx) sys.stdout.write("Scanning %s %s %s%s/%s " % (package, (pkg_name_len - len(package) + 3) * ".", (pkg_cnt_len - pkg_idx_len) * " " , pkg_idx, pkg_cnt)) sys.stdout.flush() pkg = Package(package) info = pkg.getInfo() # save xml into file errs = savePackageInfo(info) if errs != []: print "" print "\n".join(errs) else: if not full: valid[package] = outdated[package] pkg_idx += 1 endtime = time() elapsedtime = endtime - starttime print strftime("[%Hh %Mm %Ss]", gmtime(elapsedtime)) # update cache of imported and provided packages for item in info: devel_name = item # This is hacky and depends on info data type represenation pkg2xml_obj = info[item]['xmlobj'] imports = pkg2xml_obj.getImportedPackages() provides = pkg2xml_obj.getProvidedPackages() ipdb_cache.updateBuild(devel_name, provides, imports, package) if not ipdb_cache.flush(): print ipdb_cache.getError() scan_time_end = time() print strftime("Elapsed time %Hh %Mm %Ss", gmtime(scan_time_end - scan_time_start)) if not full: LocalDB().updateBuildsInCache(valid) return True
dest="update", action="store_true", default=False, help="Update local databases with new golang packages") options, args = parser.parse_args() # new packages if options.new: set_pkgdb, set_local = getPkgs() printPkgs(list(set_pkgdb - set_local)) elif options.removed: set_pkgdb, set_local = getPkgs() printPkgs(list(set_local - set_pkgdb)) elif options.list: pkgs = loadPackages() printPkgs(sorted(pkgs)) elif options.update: set_pkgdb, set_local = getPkgs() ldb = LocalDB() new_pkgs = list(set_pkgdb - set_local) err, ret = ldb.addPackages(new_pkgs) if ret: print "%s packages added" % len(new_pkgs) if err != []: print "\n".join(err) else: print "\n".join(err) else: print "Synopsis: [-n] [-r] [-l] [-u]"