def setUp(self): super(Srv4FileStatsUnitTest, self).setUp() self.dbc.InitialDataImport() self.sqo_arch = models.Architecture.selectBy(id=1).getOne() self.sqo_osrel = models.OsRelease.selectBy(id=1).getOne() self.sqo_catrel = models.CatalogRelease.selectBy(id=1).getOne() self.pkginst = models.Pkginst(pkgname="CSWfoo") self.maintainer = models.Maintainer(email='*****@*****.**', full_name='Joe Bloggs') self.p = models.Srv4FileStats( arch=self.sqo_arch, basename="foo.pkg", catalogname="foo", data_obj=None, filename_arch=self.sqo_arch, latest=True, maintainer=self.maintainer, md5_sum="not a real one", size=1L, mtime=datetime.datetime.now(), os_rel=self.sqo_osrel, pkginst=self.pkginst, registered=True, use_to_generate_catalogs=True, rev="2011.01.01", stats_version=0, version_string="1.0,REV=2011.01.01", )
def _GetFakeMaintainer(self): fake_email = "*****@*****.**" fake_name = "Placeholder for an external maintainer" try: sqo_maintainer = m.Maintainer.select( m.Maintainer.q.email == fake_email).getOne() except sqlobject.main.SQLObjectNotFound, e: sqo_maintainer = m.Maintainer(email=fake_email, full_name=fake_name)
basename = pkg_stats["basic_stats"]["parsed_basename"] parsed_basename = basename os_rel_name = parsed_basename["osrel"] try: os_rel = m.OsRelease.select( m.OsRelease.q.short_name == os_rel_name).getOne() except sqlobject.main.SQLObjectNotFound, e: logging.debug(e) os_rel = m.OsRelease(short_name=os_rel_name, full_name=os_rel_name) try: maint_email = pkg_stats["pkginfo"]["EMAIL"] maintainer = m.Maintainer.select( m.Maintainer.q.email == maint_email).getOne() except sqlobject.main.SQLObjectNotFound, e: logging.debug(e) maintainer = m.Maintainer(email=maint_email) # If there are any previous records of the same pkginst, arch and os_rel, # we're marking them as not-latest. # This assumes that the packages are examined in a chronological order. res = m.Srv4FileStats.select( sqlobject.AND(m.Srv4FileStats.q.pkginst == pkginst, m.Srv4FileStats.q.arch == arch, m.Srv4FileStats.q.os_rel == os_rel)) for obj in res: obj.latest = False rev = None if "revision_info" in parsed_basename: if "REV" in parsed_basename["revision_info"]: rev = parsed_basename["revision_info"]["REV"]