Beispiel #1
0
 def test_3(self):
     """One override, matching by tag name, mismatching tag info, no pkgname."""
     tags = [tag.CheckpkgTag("CSWfoo", "foo-tag", "tag-info-1")]
     oo = [overrides.Override(None, "foo-tag", "tag-info-2")]
     self.assertEqual((tags, set(oo)), overrides.ApplyOverrides(tags, oo))
Beispiel #2
0
 def test_5(self):
     tags = [tag.CheckpkgTag("CSWfoo", "foo-tag", "tag-info-1")]
     oo = [overrides.Override("CSWfoo", "foo-tag", "tag-info-1")]
     self.assertEqual(([], set([])), overrides.ApplyOverrides(tags, oo))
Beispiel #3
0
 def test_2(self):
     """One override, matching by tag name and tag info, no pkgname."""
     tags = [tag.CheckpkgTag("CSWfoo", "foo-tag")]
     oo = [overrides.Override(None, "foo-tag", None)]
     self.assertEqual(([], set([])), overrides.ApplyOverrides(tags, oo))
Beispiel #4
0
 def test_1a(self):
     """One tag, no overrides."""
     tags = [tag.CheckpkgTag("CSWfoo", "foo-tag")]
     oo = []
     self.assertEqual((tags, set([])), overrides.ApplyOverrides(tags, oo))
Beispiel #5
0
 def test_6(self):
     """Pkgname mismatch."""
     tags = [tag.CheckpkgTag("CSWfoo", "foo-tag", "tag-info-1")]
     oo = [overrides.Override("CSWbar", "foo-tag", "tag-info-1")]
     self.assertEqual((tags, set(oo)), overrides.ApplyOverrides(tags, oo))
Beispiel #6
0
def main():
  parser = optparse.OptionParser(USAGE)
  parser.add_option("-d", "--debug",
      dest="debug",
      action="store_true",
      default=False,
      help="Switch on debugging messages")
  parser.add_option("-q", "--quiet",
      dest="quiet",
      action="store_true",
      default=False,
      help="Display less messages")
  parser.add_option("--catalog-release",
      dest="catrel",
      default="current",
      help="A catalog release: current, unstable, testing, stable.")
  parser.add_option("-r", "--os-releases",
      dest="osrel_commas",
      help=("Comma separated list of ['SunOS5.9', 'SunOS5.10'], "
            "e.g. 'SunOS5.9,SunOS5.10'."))
  parser.add_option("-a", "--architecture",
      dest="arch",
      help="Architecture: i386, sparc.")
  parser.add_option("--profile", dest="profile",
      default=False, action="store_true",
      help="Enable profiling (a developer option).")
  options, args = parser.parse_args()
  assert len(args), "The list of files or md5 sums must be not empty."
  logging_level = logging.INFO
  if options.quiet:
    logging_level = logging.WARNING
  elif options.debug:
    # If both flags are set, debug wins.
    logging_level = logging.DEBUG
  logging.basicConfig(level=logging_level)
  logging.debug("Starting.")

  configuration.SetUpSqlobjectConnection()
  dm = database.DatabaseManager()
  dm.AutoManage()


  err_msg_list = []
  if not options.osrel_commas:
    err_msg_list.append("Please specify --os-releases.")
  if not options.arch:
    err_msg_list.append("Please specify --architecture.")
  if options.arch not in cc.PHYSICAL_ARCHITECTURES:
    err_msg_list.append(
        "Valid --architecture values are: %s, you passed: %r"
        % (cc.PHYSICAL_ARCHITECTURES, options.arch))
  if err_msg_list:
    raise UsageError(" ".join(err_msg_list))

  stats_list = []
  collector = package_stats.StatsCollector(
      logger=logging,
      debug=options.debug)
  # We need to separate files and md5 sums.
  md5_sums, file_list = [], []
  for arg in args:
    if struct_util.IsMd5(arg):
      md5_sums.append(arg)
    else:
      file_list.append(arg)
  if file_list:
    stats_list = collector.CollectStatsFromFiles(file_list, None)
  # We need the md5 sums of these files
  md5_sums.extend([x["basic_stats"]["md5_sum"] for x in stats_list])
  assert md5_sums, "The list of md5 sums must not be empty."
  logging.debug("md5_sums: %s", md5_sums)
  osrel_list = options.osrel_commas.split(",")
  logging.debug("Reading packages data from the database.")
  # This part might need improvements in order to handle a whole
  # catalog.  On the other hand, if we already have the whole catalog in
  # the database, we can do it altogether differently.
  # Transforming the result to a list in order to force object
  # retrieval.
  sqo_pkgs = list(models.Srv4FileStats.select(
    sqlobject.IN(models.Srv4FileStats.q.md5_sum, md5_sums)))
  tags_for_all_osrels = []
  try:
    sqo_catrel = models.CatalogRelease.selectBy(name=options.catrel).getOne()
  except sqlobject.main.SQLObjectNotFound as e:
    logging.fatal("Fetching from the db has failed: catrel=%s",
                  repr(str(options.catrel)))
    logging.fatal("Available catalog releases:")
    sqo_catrels = models.CatalogRelease.select()
    for sqo_catrel in sqo_catrels:
      logging.fatal(" - %s", sqo_catrel.name)
    raise
  sqo_arch = models.Architecture.selectBy(name=options.arch).getOne()
  for osrel in osrel_list:
    sqo_osrel = models.OsRelease.selectBy(short_name=osrel).getOne()
    dm.VerifyContents(sqo_osrel, sqo_arch)
    check_manager = checkpkg_lib.CheckpkgManager2(
        CHECKPKG_MODULE_NAME,
        sqo_pkgs,
        osrel,
        options.arch,
        options.catrel,
        debug=options.debug,
        show_progress=(os.isatty(1) and not options.quiet))
    # Running the checks, reporting and exiting.
    exit_code, screen_report, tags_report = check_manager.Run()
    screen_report = unicode(screen_report)
    if not options.quiet and screen_report:
      # TODO: Write this to screen only after overrides are applied.
      sys.stdout.write(screen_report)
    else:
      logging.debug("No screen report.")

    overrides_list = [list(pkg.GetOverridesResult()) for pkg in sqo_pkgs]
    override_list = reduce(operator.add, overrides_list)
    args = (sqo_osrel, sqo_arch, sqo_catrel)
    tag_lists = [list(pkg.GetErrorTagsResult(*args)) for pkg in sqo_pkgs]
    error_tags = reduce(operator.add, tag_lists)
    (tags_after_overrides,
     unapplied_overrides) = overrides.ApplyOverrides(error_tags, override_list)
    tags_for_all_osrels.extend(tags_after_overrides)
    if not options.quiet:
      if tags_after_overrides:
        print(textwrap.fill(BEFORE_OVERRIDES, 80))
        for checkpkg_tag in tags_after_overrides:
          print checkpkg_tag.ToGarSyntax()
        print textwrap.fill(AFTER_OVERRIDES, 80)
      if unapplied_overrides:
        print textwrap.fill(UNAPPLIED_OVERRIDES, 80)
        for override in unapplied_overrides:
          print u"* Unused %s" % override
  exit_code = bool(tags_for_all_osrels)
  sys.exit(exit_code)
Beispiel #7
0
    # Running the checks, reporting and exiting.
    exit_code, screen_report, tags_report = check_manager.Run()
    screen_report = unicode(screen_report)
    if not options.quiet and screen_report:
      # TODO: Write this to screen only after overrides are applied.
      sys.stdout.write(screen_report)
    else:
      logging.debug("No screen report.")

    overrides_list = [list(pkg.GetOverridesResult()) for pkg in sqo_pkgs]
    override_list = reduce(operator.add, overrides_list)
    args = (sqo_osrel, sqo_arch, sqo_catrel)
    tag_lists = [list(pkg.GetErrorTagsResult(*args)) for pkg in sqo_pkgs]
    error_tags = reduce(operator.add, tag_lists)
    (tags_after_overrides,
     unapplied_overrides) = overrides.ApplyOverrides(error_tags, override_list)
    tags_for_all_osrels.extend(tags_after_overrides)
    if not options.quiet:
      if tags_after_overrides:
        print textwrap.fill(BEFORE_OVERRIDES, 80)
        for checkpkg_tag in tags_after_overrides:
          print checkpkg_tag.ToGarSyntax()
        print textwrap.fill(AFTER_OVERRIDES, 80)
      if unapplied_overrides:
        print textwrap.fill(UNAPPLIED_OVERRIDES, 80)
        for override in unapplied_overrides:
          print u"* Unused %s" % override
  exit_code = bool(tags_for_all_osrels)
  sys.exit(exit_code)