def PUT(self, catrel_name, arch_name, osrel_name, md5_sum): """Adds package to a catalog. When pycurl calls this function, it often hangs, waiting. A fix for that is to add the 'Content-Length' header. However, it sometimes still gets stuck and I don't know why. """ configuration.SetUpSqlobjectConnection() if catrel_name != 'unstable': # Updates via web are allowed only for the unstable catalog. # We should return an error message instead. raise web.notfound() try: if arch_name == 'all': raise checkpkg_lib.CatalogDatabaseError( "Cannot add to 'all' catalog.") srv4 = models.Srv4FileStats.selectBy(md5_sum=md5_sum).getOne() parsed_basename = opencsw.ParsePackageFileName(srv4.basename) if parsed_basename["vendortag"] != "CSW": raise checkpkg_lib.CatalogDatabaseError( "Package vendor tag is %s instead of CSW." % parsed_basename["vendortag"]) if not srv4.registered: # Package needs to be registered for releases stats = srv4.GetStatsStruct() # This can throw CatalogDatabaseError if the db user doesn't have # enough permissions. package_stats.PackageStats.ImportPkg(stats, True) srv4 = models.Srv4FileStats.selectBy(md5_sum=md5_sum).getOne() c = checkpkg_lib.Catalog() # See if there already is a package with that catalogname. sqo_osrel, sqo_arch, sqo_catrel = pkgdb.GetSqoTriad( osrel_name, arch_name, catrel_name) res = c.GetConflictingSrv4ByCatalognameResult( srv4, srv4.catalogname, sqo_osrel, sqo_arch, sqo_catrel) if res.count() == 1: # Removing old version of the package from the catalog for pkg_in_catalog in res: srv4_to_remove = pkg_in_catalog.srv4file c.RemoveSrv4(srv4_to_remove, osrel_name, arch_name, catrel_name) c.AddSrv4ToCatalog(srv4, osrel_name, arch_name, catrel_name) web.header('Content-type', 'application/x-vnd.opencsw.pkg;type=catalog-update') response = json.dumps([ u"Added to catalog %s %s %s" % (catrel_name, arch_name, osrel_name), u"%s" % srv4.basename, ]) web.header('Content-Length', len(response)) return response except (checkpkg_lib.CatalogDatabaseError, sqlobject.dberrors.OperationalError), e: web.header('Content-type', 'application/x-vnd.opencsw.pkg;type=error-message') response = json.dumps({ "error_message": unicode(e), }) web.header('Content-Length', len(response)) return response
def GET(self, catrel_name, arch_name, osrel_name, pkgname): """Get a srv4 reference by catalog ane pkgname.""" configuration.SetUpSqlobjectConnection() sqo_osrel, sqo_arch, sqo_catrel = pkgdb.GetSqoTriad( osrel_name, arch_name, catrel_name) join = [ sqlbuilder.INNERJOINOn( None, models.Srv4FileInCatalog, models.Srv4FileInCatalog.q.srv4file == models.Srv4FileStats.q.id), sqlbuilder.INNERJOINOn( None, models.Pkginst, models.Pkginst.q.id == models.Srv4FileStats.q.pkginst), ] res = models.Srv4FileStats.select( sqlobject.AND( models.Srv4FileInCatalog.q.osrel == sqo_osrel, models.Srv4FileInCatalog.q.arch == sqo_arch, models.Srv4FileInCatalog.q.catrel == sqo_catrel, models.Pkginst.q.pkgname == pkgname, models.Srv4FileStats.q.use_to_generate_catalogs == True), join=join, ) try: srv4 = res.getOne() mimetype, data = srv4.GetRestRepr() web.header('Content-type', mimetype) web.header('Access-Control-Allow-Origin', '*') return cjson.encode(data) except sqlobject.main.SQLObjectNotFound: return cjson.encode(None) except sqlobject.dberrors.OperationalError, e: raise web.internalerror(e)
def GET(self, catrel_name, arch_name, osrel_name): ConnectToDatabase() cat_name = " ".join((catrel_name, arch_name, osrel_name)) sqo_osrel, sqo_arch, sqo_catrel = pkgdb.GetSqoTriad( osrel_name, arch_name, catrel_name) pkgs = models.GetCatPackagesResult(sqo_osrel, sqo_arch, sqo_catrel) return render.CatalogDetail(cat_name, pkgs)
def GET(self, catrel_name, arch_name, osrel_name): ConnectToDatabase() sqo_osrel, sqo_arch, sqo_catrel = pkgdb.GetSqoTriad( osrel_name, arch_name, catrel_name) pkgs = list( models.GetCatPackagesResult(sqo_osrel, sqo_arch, sqo_catrel)) if not len(pkgs): raise web.notfound() web.header('Content-type', 'application/x-vnd.opencsw.pkg;type=srv4-list') pkgs_data = [x.GetRestRepr()[1] for x in pkgs] return json.dumps(pkgs_data)
def GET(self, catrel_name, arch_name, osrel_name): sqo_osrel, sqo_arch, sqo_catrel = pkgdb.GetSqoTriad( osrel_name, arch_name, catrel_name) pkgs = list( models.GetCatPackagesResult(sqo_osrel, sqo_arch, sqo_catrel)) user_data = web.input(quick='') quick = (user_data.quick == "true") if not len(pkgs): raise web.notfound() web.header('Content-type', 'application/x-vnd.opencsw.pkg;type=srv4-list') pkgs_data = [p.GetRestRepr(quick)[1] for p in pkgs] return cjson.encode(pkgs_data)
def GET(self, catrel_name, arch_name, osrel_name): """See if that package is in that catalog.""" configuration.SetUpSqlobjectConnection() sqo_osrel, sqo_arch, sqo_catrel = pkgdb.GetSqoTriad( osrel_name, arch_name, catrel_name) srv4 = models.Srv4FileStats.selectBy(md5_sum=md5_sum).getOne() logging.warning("Srv4CatalogAssignment::GET srv4: %s", srv4.basename) srv4_in_c = models.Srv4FileInCatalog.selectBy(osrel=sqo_osrel, arch=sqo_arch, catrel=sqo_catrel, srv4file=srv4) web.header( 'Content-type', 'application/x-vnd.opencsw.pkg;type=srv4-catalog-assignment') response_data = { 'srv': unicode(srv4), } return json.dumps(response_data)