def testRemoveSrv4FromCatalog(self): self.dbc.InitialDataImport() stats = self.TestPackageStats.ImportPkg(neon_stats[0]) c = self.TestCatalog() sqo_osrel, sqo_arch, sqo_catrel = c.GetSqlobjectTriad( 'SunOS5.9', 'i386', 'unstable') c.AddSrv4ToCatalog(stats, 'SunOS5.9', 'i386', 'unstable') obj = m.Srv4FileInCatalog.select( sqlobject.AND(m.Srv4FileInCatalog.q.arch == sqo_arch, m.Srv4FileInCatalog.q.osrel == sqo_osrel, m.Srv4FileInCatalog.q.catrel == sqo_catrel, m.Srv4FileInCatalog.q.srv4file == stats)).getOne() # At this point, we know that the record is in the db. c.RemoveSrv4(stats, 'SunOS5.9', 'i386', 'unstable') # Make sure that the Srv4FileInCatalog object is now gone. res = m.Srv4FileInCatalog.select( sqlobject.AND(m.Srv4FileInCatalog.q.arch == sqo_arch, m.Srv4FileInCatalog.q.osrel == sqo_osrel, m.Srv4FileInCatalog.q.catrel == sqo_catrel, m.Srv4FileInCatalog.q.srv4file == stats)) self.assertRaises(sqlobject.SQLObjectNotFound, res.getOne) # Retrieved record from the db should now not have the registered flag. updated_stats = m.Srv4FileStats.select( m.Srv4FileStats.q.id == stats.id).getOne() self.assertTrue(updated_stats.registered) # Make sure that files of this package are still in the database. res = m.CswFile.select(m.CswFile.q.srv4_file == updated_stats) self.assertEquals(22, res.count())
def GetPkgByPath(self, full_file_path, osrel, arch, catrel): """Returns a list of packages.""" # Memoization for performance # Memoization won't buy us much. Perhaps we can fetch all the files # belonging to the same package, so that we quickly prepopulate the cache. key = (full_file_path, osrel, arch, catrel) if key not in self.pkgs_by_path_cache: file_path, basename = os.path.split(full_file_path) sqo_osrel, sqo_arch, sqo_catrel = self.GetSqlobjectTriad( osrel, arch, catrel) oac = sqlobject.AND(m.Srv4FileInCatalog.q.osrel == sqo_osrel, m.Srv4FileInCatalog.q.arch == sqo_arch, m.Srv4FileInCatalog.q.catrel == sqo_catrel) path_filter = sqlobject.AND(oac, m.CswFile.q.path == file_path, m.CswFile.q.basename == basename, m.Srv4FileStats.q.registered == True) join = [ sqlbuilder.INNERJOINOn( None, m.Srv4FileStats, m.Pkginst.q.id == m.Srv4FileStats.q.pkginst), sqlbuilder.INNERJOINOn( None, m.Srv4FileInCatalog, m.Srv4FileStats.q.id == m.Srv4FileInCatalog.q.srv4file), sqlbuilder.INNERJOINOn( None, m.CswFile, m.Srv4FileStats.q.id == m.CswFile.q.srv4_file), ] res = m.Pkginst.select(path_filter, join=join) pkgs = [x.pkgname for x in res] self.pkgs_by_path_cache[key] = frozenset(pkgs) return self.pkgs_by_path_cache[key]
def GetPkgByPath(self, full_file_path, osrel, arch, catrel): """Returns a list of packages.""" # TODO(maciej): Move this to models.py and have pkgdb_web return the JSON # structure. This is a step towards RESTification. key = (full_file_path, osrel, arch, catrel) if key not in self.pkgs_by_path_cache: file_path, basename = os.path.split(full_file_path) sqo_osrel, sqo_arch, sqo_catrel = self.GetSqlobjectTriad( osrel, arch, catrel) oac = sqlobject.AND( m.Srv4FileInCatalog.q.osrel==sqo_osrel, m.Srv4FileInCatalog.q.arch==sqo_arch, m.Srv4FileInCatalog.q.catrel==sqo_catrel) path_filter = sqlobject.AND( oac, m.CswFile.q.path==file_path, m.CswFile.q.basename==basename, m.Srv4FileStats.q.registered_level_two==True) join = [ sqlbuilder.INNERJOINOn(None, m.Srv4FileStats, m.Pkginst.q.id==m.Srv4FileStats.q.pkginst), sqlbuilder.INNERJOINOn(None, m.Srv4FileInCatalog, m.Srv4FileStats.q.id==m.Srv4FileInCatalog.q.srv4file), sqlbuilder.INNERJOINOn(None, m.CswFile, m.Srv4FileStats.q.id==m.CswFile.q.srv4_file), ] res = m.Pkginst.select(path_filter, join=join) pkgs = [x.pkgname for x in res] self.pkgs_by_path_cache[key] = frozenset(pkgs) return self.pkgs_by_path_cache[key]
def AddSrv4ToCatalog(self, sqo_srv4, osrel, arch, catrel): """Registers a srv4 file in a catalog.""" logging.debug("AddSrv4ToCatalog(%s, %s, %s, %s)", sqo_srv4, osrel, arch, catrel) # There are only i386 and sparc catalogs. if arch != 'i386' and arch != 'sparc': raise CatalogDatabaseError("Wrong architecture: %s" % arch) sqo_osrel, sqo_arch, sqo_catrel = self.GetSqlobjectTriad( osrel, arch, catrel) if not self.Srv4MatchesCatalog(sqo_srv4, sqo_arch): raise CatalogDatabaseError( "Specified package does not match the catalog. " "Package: %s, catalog: %s %s %s" % (sqo_srv4, osrel, arch, catrel)) if not sqo_srv4.registered: raise CatalogDatabaseError( "Package %s (%s) is not registered for releases." % (sqo_srv4.basename, sqo_srv4.md5_sum)) # TODO(maciej): Make sure the package's files are present in the database. # Checking for presence of a different srv4 with the same pkginst in the # same catalog pkginst = sqo_srv4.pkginst res = m.Srv4FileStats.select( m.Srv4FileStats.q.pkginst == pkginst).throughTo.in_catalogs.filter( sqlobject.AND(m.Srv4FileInCatalog.q.osrel == sqo_osrel, m.Srv4FileInCatalog.q.arch == sqo_arch, m.Srv4FileInCatalog.q.catrel == sqo_catrel, m.Srv4FileInCatalog.q.srv4file != sqo_srv4)) if res.count(): raise CatalogDatabaseError( "There already is a package with that pkgname: %s" % pkginst.pkgname) res = self.GetConflictingSrv4ByCatalognameResult( sqo_srv4, sqo_srv4.catalogname, sqo_osrel, sqo_arch, sqo_catrel) if res.count(): raise CatalogDatabaseError( "There already is a package with that catalogname: %s" % sqo_srv4.catalogname) # Checking for presence of the same srv4 already in the catalog. res = m.Srv4FileInCatalog.select( sqlobject.AND(m.Srv4FileInCatalog.q.osrel == sqo_osrel, m.Srv4FileInCatalog.q.arch == sqo_arch, m.Srv4FileInCatalog.q.catrel == sqo_catrel, m.Srv4FileInCatalog.q.srv4file == sqo_srv4)) if res.count(): logging.warning("%s is already part of %s %s %s", sqo_srv4, osrel, arch, catrel) # Our srv4 is already part of that catalog. return obj = m.Srv4FileInCatalog(arch=sqo_arch, osrel=sqo_osrel, catrel=sqo_catrel, srv4file=sqo_srv4)
def GET(self, catrel_name, arch_name, osrel_name, catalogname): """Get a srv4 reference by catalog ane catalogname.""" web.header('Access-Control-Allow-Origin', '*') try: sqo_osrel, sqo_arch, sqo_catrel = models.GetSqoTriad( osrel_name, arch_name, catrel_name) except sqlobject.main.SQLObjectNotFound: raise web.notfound( cjson.encode({'message': 'catalog %s %s %s not found' % (osrel_name, arch_name, catrel_name)})) join = [ sqlbuilder.INNERJOINOn(None, models.Srv4FileInCatalog, models.Srv4FileInCatalog.q.srv4file==models.Srv4FileStats.q.id), ] 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.Srv4FileStats.q.catalogname==catalogname, models.Srv4FileStats.q.use_to_generate_catalogs==True), join=join, ) try: srv4 = res.getOne() mimetype, data = srv4.GetRestRepr(quick=True) web.header('Content-type', mimetype) return cjson.encode(data) except sqlobject.main.SQLObjectNotFound: data = {'message': 'no %s %s %s %s packages found' % (catrel_name, arch_name, osrel_name, catalogname)} raise web.notfound(cjson.encode(data)) except sqlobject.dberrors.OperationalError as exc: raise web.internalerror(exc)
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 VerifyContents(self, sqo_osrel, sqo_arch): "Verify that we know the system files on the OS release and architecture." res = m.Srv4FileStats.select( sqlobject.AND(m.Srv4FileStats.q.use_to_generate_catalogs == False, m.Srv4FileStats.q.registered == True, m.Srv4FileStats.q.os_rel == sqo_osrel, m.Srv4FileStats.q.arch == sqo_arch)) # logging.warning("VerifyContents(): Packages Count: %s", res.count()) system_pkgs = res.count() logging.debug("VerifyContents(%s, %s): %s", sqo_osrel, sqo_arch, system_pkgs) if system_pkgs < 10: raise DatabaseError( "Checkpkg can't find system files for %s %s in the cache database. " "These are files such as /usr/lib/libc.so.1. " "Private DB setup: " "you can only check packages built for the same Solaris version " "you're running on this machine. " "For instance, you can't check a SunOS5.9 package on SunOS5.10. " "Shared DB setup (e.g. OpenCSW maintainers): " "If you have one home directory on multiple hosts, make sure you " "run checkpkg on the host you intended to. " "To fix, go to a %s %s host and execute: pkgdb system-files-to-file; " "pkgdb import-system-file install-contents-%s-%s.pickle; " "See http://wiki.opencsw.org/checkpkg for more information." % (sqo_osrel.short_name, sqo_arch.name, sqo_arch.name, sqo_osrel.short_name, sqo_osrel.short_name, sqo_arch.name))
def testImportPkgLatin1EncodedFile(self): """Registers the package in the database.""" neon_stats2 = copy.deepcopy(neon_stats[0]) latin1_pkgmap_entry = { 'class': 'none', 'group': 'bin', 'line': ('1 f none /opt/csw/lib/aspell/espa\xf1ol.alias ' '0644 root bin 70 6058 1030077183'), 'mode': '0644', 'path': '/opt/csw/lib/aspell/espa\xf1ol.alias', 'type': 'f', 'user': '******' } neon_stats2["pkgmap"].append(latin1_pkgmap_entry) package_stats.PackageStats.ImportPkg(neon_stats2) res = m.CswFile.select( sqlobject.AND( m.CswFile.q.basename == 'espa\xc3\xb1ol.alias'.decode('utf-8'), m.CswFile.q.path == u'/opt/csw/lib/aspell')) f = res.getOne() expected_line = (u'1 f none /opt/csw/lib/aspell/espa\xf1ol.alias 0644 ' u'root bin 70 6058 1030077183') self.assertEqual(expected_line, f.line)
def AddSrv4ToCatalog(self, sqo_srv4, osrel, arch, catrel, who, trans): """Registers a srv4 file in a catalog.""" self.logger.debug( "AddSrv4ToCatalog(%s, %r, %r, %r, %r)", sqo_srv4, osrel, arch, catrel, who) if not who: who = 'unknown' # There are only i386 and sparc architectures. if arch not in ('i386', 'sparc'): raise CatalogDatabaseError("Wrong architecture: %s" % arch) sqo_osrel, sqo_arch, sqo_catrel = self.GetSqlobjectTriad( osrel, arch, catrel) if not self.Srv4MatchesCatalog(sqo_srv4, sqo_arch): raise CatalogDatabaseError( "Specified package does not match the catalog. " "Package: %s, catalog: %s %s %s" % (sqo_srv4, osrel, arch, catrel)) if not sqo_srv4.registered_level_two: raise CatalogDatabaseError( "Package %s (%s) is not registered for releases." % (sqo_srv4.basename, sqo_srv4.md5_sum)) # Checking for presence of a different srv4 with the same pkginst in the # same catalog res = self.GetConflictingSrv4ByPkgnameResult( sqo_srv4, sqo_srv4.pkginst.pkgname, sqo_osrel, sqo_arch, sqo_catrel, trans) if res.count(): raise CatalogDatabaseError( "There already is a package with that pkgname: %s" % pkginst.pkgname) res = self.GetConflictingSrv4ByCatalognameResult( sqo_srv4, sqo_srv4.catalogname, sqo_osrel, sqo_arch, sqo_catrel, trans) if res.count(): raise CatalogDatabaseError( "There already is a package with that catalogname: %s" % sqo_srv4) # Checking for presence of the same srv4 already in the catalog. res = m.Srv4FileInCatalog.select( sqlobject.AND( m.Srv4FileInCatalog.q.osrel==sqo_osrel, m.Srv4FileInCatalog.q.arch==sqo_arch, m.Srv4FileInCatalog.q.catrel==sqo_catrel, m.Srv4FileInCatalog.q.srv4file==sqo_srv4), connection=trans) if res.count(): self.logger.debug( "%s is already part of %s %s %s, count=%d", sqo_srv4, osrel, arch, catrel, res.count()) # Our srv4 is already part of that catalog. return # SQL INSERT happens here. pkg_in_cat = m.Srv4FileInCatalog( arch=sqo_arch, osrel=sqo_osrel, catrel=sqo_catrel, srv4file=sqo_srv4, created_by=who, connection=trans) self.logger.debug('The package %s was inserted into catalog %s %s %s: %s', sqo_srv4.basename, osrel, arch, catrel, pkg_in_cat)
def GetPathsAndPkgnamesByBasedir(self, basedir, osrel, arch, catrel): sqo_osrel, sqo_arch, sqo_catrel = self.GetSqlobjectTriad( osrel, arch, catrel) connection = m.CswFile._connection join = [ sqlbuilder.INNERJOINOn(None, m.Pkginst, m.CswFile.q.pkginst==m.Pkginst.q.id), sqlbuilder.INNERJOINOn(None, m.Srv4FileStats, m.CswFile.q.srv4_file==m.Srv4FileStats.q.id), sqlbuilder.INNERJOINOn(None, m.Srv4FileInCatalog, m.Srv4FileStats.q.id==m.Srv4FileInCatalog.q.srv4file), ] where = sqlobject.AND( m.CswFile.q.path==basedir, m.Srv4FileInCatalog.q.osrel==sqo_osrel, m.Srv4FileInCatalog.q.arch==sqo_arch, m.Srv4FileInCatalog.q.catrel==sqo_catrel, ) query = connection.sqlrepr( sqlbuilder.Select( [m.CswFile.q.basename, m.Pkginst.q.pkgname], where=where, join=join)) rows = connection.queryAll(query) pkgs = {} for row in rows: basename, pkginst = row pkgs.setdefault(pkginst, []).append(basename) return pkgs
def GET(self, id): maintainer = models.Maintainer.selectBy(id=id).getOne() pkgs = models.Srv4FileStats.select( sqlobject.AND( models.Srv4FileStats.q.maintainer == maintainer, models.Srv4FileStats.q.registered == True, ), ).orderBy('basename') return render.MaintainerDetail(maintainer, pkgs)
def testImportPkgIdempotenceWithReplace(self): """Files shouldn't be imported twice for one package.""" package_stats.PackageStats.ImportPkg(neon_stats[0]) package_stats.PackageStats.ImportPkg(neon_stats[0], replace=True) res = m.CswFile.select( sqlobject.AND(m.CswFile.q.basename == u'libneon.so.26.0.4', m.CswFile.q.path == u'/opt/csw/lib')) self.assertEquals(1, res.count())
def find_el(self, y, m, d): """Find day""" elem = list( Calendar.select( sqlobject.AND(Calendar.q.year == y, Calendar.q.month == m, Calendar.q.day == d))) if elem == []: return None return elem[0]
def _query(self, kwargs): """ Get products filtered by date. """ if len(kwargs) == 3: date = "{}-{}-{}".format(kwargs['year'], kwargs['month'], kwargs['day']) products = Product.select(Product.q.date == date) elif "month" in kwargs.keys() and "year" in kwargs.keys(): prev_month = datetime.date(kwargs['year'], kwargs['month'], 1) - relativedelta(months=1) next_mounth = datetime.date(kwargs['year'], kwargs['month'], 1) + relativedelta(months=1) products = Product.select(sqlobject.AND(Product.q.date > prev_month,\ Product.q.date < next_mounth)) elif "year" in kwargs.keys(): now = datetime.datetime.now() products = Product.select(sqlobject.AND(Product.q.date > datetime.date(kwargs['year'] -1, 12, 31),\ Product.q.date < datetime.date(kwargs['year'] + 1, 1, 1))) return products
def GetErrorTagsResult(self, os_rel, arch, catrel): assert arch.name != 'all', ( "Asked for the 'all' architecture, this is not valid " "for GetErrorTagsResult().") return CheckpkgErrorTag.select( sqlobject.AND(CheckpkgErrorTag.q.srv4_file == self, CheckpkgErrorTag.q.os_rel == os_rel, CheckpkgErrorTag.q.arch == arch, CheckpkgErrorTag.q.catrel == catrel))
def _RemoveSystemPackagesFromCatalog(self, data): sqo_osrel, sqo_arch = self._GetSqoOsrelAndArch(data["osrel"], data["arch"]) res = m.Srv4FileStats.select( sqlobject.AND( m.Srv4FileStats.q.use_to_generate_catalogs==False, m.Srv4FileStats.q.arch==sqo_arch, m.Srv4FileStats.q.os_rel==sqo_osrel)) for sqo_srv4 in res: for srv4_in_cat in sqo_srv4.in_catalogs: srv4_in_cat.destroySelf()
def GetConflictingSrv4ByCatalognameResult(self, sqo_srv4, catalogname, sqo_osrel, sqo_arch, sqo_catrel): res = m.Srv4FileStats.select( m.Srv4FileStats.q.catalogname == catalogname).throughTo.in_catalogs.filter( sqlobject.AND(m.Srv4FileInCatalog.q.osrel == sqo_osrel, m.Srv4FileInCatalog.q.arch == sqo_arch, m.Srv4FileInCatalog.q.catrel == sqo_catrel, m.Srv4FileInCatalog.q.srv4file != sqo_srv4)) return res
def GetPathsAndPkgnamesByBasename(self, basename, osrel, arch, catrel): """Retrieves pkginst names of packages that have certain files. Since it needs to match a specific catalog, a table join is required: - CswFile (basename) - related Srv4FileStats - related Srv4FileInCatalog Args: basename: u'libfoo.so.1' osrel: u'5.9' arch: 'sparc', 'x86' catrel: 'stable' Returns: {"/opt/csw/lib": ["CSWfoo", "CSWbar"], "/opt/csw/1/lib": ["CSWfoomore"]} """ pkgs = {} sqo_osrel, sqo_arch, sqo_catrel = self.GetSqlobjectTriad( osrel, arch, catrel) connection = m.CswFile._connection join = [ sqlbuilder.INNERJOINOn(None, m.Pkginst, m.CswFile.q.pkginst==m.Pkginst.q.id), sqlbuilder.INNERJOINOn(None, m.Srv4FileStats, m.CswFile.q.srv4_file==m.Srv4FileStats.q.id), sqlbuilder.INNERJOINOn(None, m.Srv4FileInCatalog, m.Srv4FileStats.q.id==m.Srv4FileInCatalog.q.srv4file), ] where = sqlobject.AND( m.CswFile.q.basename==basename, m.Srv4FileInCatalog.q.osrel==sqo_osrel, m.Srv4FileInCatalog.q.arch==sqo_arch, m.Srv4FileInCatalog.q.catrel==sqo_catrel, ) query = connection.sqlrepr( sqlbuilder.Select( [m.CswFile.q.path, m.Pkginst.q.pkgname], where=where, join=join)) rows = connection.queryAll(query) pkgs = {} for row in rows: file_path, pkginst = row pkgs.setdefault(file_path, []).append(pkginst) logging.debug("self.error_mgr_mock.GetPathsAndPkgnamesByBasename(%s)" ".AndReturn(%s)", repr(basename), pprint.pformat(pkgs)) return pkgs
def RemoveCheckpkgResults(self, os_rel, arch, catrel): logger.debug("%s: RemoveCheckpkgResults(%s, %s, %s)", self, os_rel, arch, catrel) sqlobject.sqlhub.processConnection.query( sqlobject.sqlhub.processConnection.sqlrepr(sqlbuilder.Delete( CheckpkgErrorTag.sqlmeta.table, sqlobject.AND( CheckpkgErrorTag.q.srv4_file==self, CheckpkgErrorTag.q.os_rel==os_rel, CheckpkgErrorTag.q.arch==arch, CheckpkgErrorTag.q.catrel==catrel))))
def update_display(self, display, max_action): #set non hidden mines actions = Action.select( SO.AND(Action.q.chunk == self, Action.q.id <= max_action)) for action in actions: if action.action == 'DIG': display[action.y][action.x]['is_hidden'] = False else: display[action.y][ action.x]['flag'] = not display[action.y][action.x]['flag'] return display
def testImportPkg(self): """Registers the package in the database.""" package_stats.PackageStats.ImportPkg(neon_stats[0]) # basename=u'libneon.so.26.0.4' path=u'/opt/csw/lib' res = m.CswFile.select( sqlobject.AND(m.CswFile.q.basename == u'libneon.so.26.0.4', m.CswFile.q.path == u'/opt/csw/lib')) f = res.getOne() line = (u'1 f none /opt/csw/lib/libneon.so.26.0.4 ' u'0755 root bin 168252 181 1252917142') self.assertEqual(line, f.line)
def _RemoveSystemPackagesFromCatalog(self, data): # TODO(maciej): Move this functionality to the server side. sqo_osrel, sqo_arch = self._GetSqoOsrelAndArch(data["osrel"], data["arch"]) # We need to delete assignments from only the system packages, not # the CSW packages. result = m.Srv4FileInCatalog.select( sqlobject.AND( m.Srv4FileInCatalog.q.arch==sqo_arch, m.Srv4FileInCatalog.q.osrel==sqo_osrel)) for catalog_assignment in result: if not catalog_assignment.srv4file.use_to_generate_catalogs: catalog_assignment.destroySelf()
def get_num_entries_id(cls, uid): from sqlobject.sqlbuilder import * import sqlobject conn = cls._connection sel = conn.sqlrepr(Select((User.q.user_name,\ func.COUNT(Sweets.q.id)), \ sqlobject.AND(Sweets.q.userID == User.q.id, Sweets.q.userID == uid),\ groupBy=User.q.user_name, orderBy=-func.COUNT(Sweets.q.id))) tal = list(conn.queryAll(sel)) if len(tal) > 0: return tal[0] else: return ['', 0]
def testAddSrv4ToCatalog(self): self.dbc.InitialDataImport() sqo_srv4 = self.TestPackageStats.ImportPkg(neon_stats[0]) c = self.TestCatalog() c.AddSrv4ToCatalog(sqo_srv4, 'SunOS5.9', 'i386', 'unstable') sqo_osrel, sqo_arch, sqo_catrel = c.GetSqlobjectTriad( 'SunOS5.9', 'i386', 'unstable') sqo_srv4_in_cat = m.Srv4FileInCatalog.select( sqlobject.AND( m.Srv4FileInCatalog.q.arch == sqo_arch, m.Srv4FileInCatalog.q.osrel == sqo_osrel, m.Srv4FileInCatalog.q.catrel == sqo_catrel, m.Srv4FileInCatalog.q.srv4file == sqo_srv4)).getOne()
def GetConflictingSrv4ByPkgnameResult(self, sqo_srv4, pkgname, sqo_osrel, sqo_arch, sqo_catrel): join = [ sqlbuilder.INNERJOINOn( None, m.Pkginst, m.Srv4FileStats.q.pkginst == m.Pkginst.q.id), ] res = m.Srv4FileStats.select( m.Pkginst.q.pkgname == pkgname, join=join).throughTo.in_catalogs.filter( sqlobject.AND(m.Srv4FileInCatalog.q.osrel == sqo_osrel, m.Srv4FileInCatalog.q.arch == sqo_arch, m.Srv4FileInCatalog.q.catrel == sqo_catrel, m.Srv4FileInCatalog.q.srv4file != sqo_srv4)) return res
def temp(self, y, m): """Average temperature calculation function.""" t = d = 0 elems = list( Calendar.select( sqlobject.AND(Calendar.q.year == y, Calendar.q.month == m))) for i in elems: t += int(i.temperature) d += 1 if d != 0: return (t / d) else: return None
def GET(self): try: connection = models.Srv4FileStats._connection rows = connection.queryAll( connection.sqlrepr( sqlbuilder.Select( [models.Srv4FileStats.q.catalogname], distinct=True, where=sqlobject.AND( models.Srv4FileStats.q.use_to_generate_catalogs == True, models.Srv4FileStats.q.registered == True), orderBy=models.Srv4FileStats.q.catalogname))) return render.CatalognameList(rows) except sqlobject.main.SQLObjectNotFound, e: raise web.notfound()
def GetConflictingSrv4ByPkgnameResult(self, sqo_srv4, pkgname, sqo_osrel, sqo_arch, sqo_catrel, trans): pkginst = sqo_srv4.pkginst res = m.Srv4FileStats.select( m.Srv4FileStats.q.pkginst==pkginst, forUpdate=True, connection=trans ).throughTo.in_catalogs.filter( sqlobject.AND( m.Srv4FileInCatalog.q.osrel==sqo_osrel, m.Srv4FileInCatalog.q.arch==sqo_arch, m.Srv4FileInCatalog.q.catrel==sqo_catrel, m.Srv4FileInCatalog.q.srv4file!=sqo_srv4)) return res
def RemoveSrv4(self, sqo_srv4, osrel, arch, catrel): sqo_osrel, sqo_arch, sqo_catrel = self.GetSqlobjectTriad( osrel, arch, catrel) try: sqo_srv4_in_cat = m.Srv4FileInCatalog.select( sqlobject.AND( m.Srv4FileInCatalog.q.arch == sqo_arch, m.Srv4FileInCatalog.q.osrel == sqo_osrel, m.Srv4FileInCatalog.q.catrel == sqo_catrel, m.Srv4FileInCatalog.q.srv4file == sqo_srv4)).getOne() # Files belonging to this package should not be removed from the catalog # as the package might be still present in another catalog. sqo_srv4_in_cat.destroySelf() except sqlobject.main.SQLObjectNotFound, e: logging.warning(e)
def GET(self, tag_name): join = [ sqlbuilder.INNERJOINOn(None, models.Srv4FileStats, models.CheckpkgErrorTag.q.srv4_file==models.Srv4FileStats.q.id), ] tags = models.CheckpkgErrorTag.select( sqlobject.AND( models.CheckpkgErrorTag.q.tag_name==tag_name, models.Srv4FileStats.q.registered_level_two==True, models.Srv4FileStats.q.use_to_generate_catalogs==True, ), join=join, ).orderBy(('basename', 'tag_info', 'os_rel_id', 'arch_id', 'catrel_id')) return render.ErrorTagDetail(tag_name, tags)