Exemple #1
0
def main():
    parser = optparse.OptionParser(USAGE)
    parser.add_option("-d",
                      "--debug",
                      dest="debug",
                      default=False,
                      action="store_true",
                      help="Turn on debugging messages")
    parser.add_option(
        "-t",
        "--pkg-review-template",
        dest="pkg_review_template",
        help="A Cheetah template used for package review reports.")
    parser.add_option("-r",
                      "--os-release",
                      dest="osrel",
                      default="SunOS5.9",
                      help="E.g. SunOS5.9")
    parser.add_option("-a",
                      "--arch",
                      dest="arch",
                      default="sparc",
                      help="'i386' or 'sparc'")
    parser.add_option("-c",
                      "--catalog-release",
                      dest="catrel",
                      default="unstable",
                      help="E.g. unstable, dublin")
    parser.add_option("--replace",
                      dest="replace",
                      default=False,
                      action="store_true",
                      help="Replace packages when importing (importpkg)")
    parser.add_option("--profile",
                      dest="profile",
                      default=False,
                      action="store_true",
                      help="Turn on profiling")
    parser.add_option("--force-unpack",
                      dest="force_unpack",
                      default=False,
                      action="store_true",
                      help="Force unpacking of packages")
    options, args = parser.parse_args()
    if options.debug:
        logging.basicConfig(level=logging.DEBUG)
        logging.debug("Debugging on")
    else:
        logging.basicConfig(level=logging.INFO)
    if not args:
        raise UsageError("Please specify a command.  Se --help.")
    # SetUpSqlobjectConnection needs to be called after
    # logging.basicConfig
    configuration.SetUpSqlobjectConnection()
    command = args[0]
    args = args[1:]
    if command == 'show':
        subcommand = args[0]
        args = args[1:]
    elif command == 'pkg':
        subcommand = args[0]
        args = args[1:]
    else:
        subcommand = None

    md5_sums = args

    dm = database.DatabaseManager()
    # Automanage is not what we want to do, if the intention is to initialize
    # the database.
    if command != 'initdb':
        dm.AutoManage()

    if (command, subcommand) == ('show', 'errors'):
        for md5_sum in md5_sums:
            srv4 = GetPkg(md5_sum)
            res = m.CheckpkgErrorTag.select(
                m.CheckpkgErrorTag.q.srv4_file == srv4)
            for row in res:
                print row.pkgname, row.tag_name, row.tag_info, row.catrel.name, row.arch.name,
                print row.os_rel.short_name
    elif (command, subcommand) == ('show', 'overrides'):
        for md5_sum in md5_sums:
            srv4 = GetPkg(md5_sum)
            res = m.CheckpkgOverride.select(
                m.CheckpkgOverride.q.srv4_file == srv4)
            for row in res:
                print row.pkgname, row.tag_name, row.tag_info
    elif (command, subcommand) == ('show', 'pkg'):
        for md5_sum in md5_sums:
            srv4 = GetPkg(md5_sum)
            t = Template(SHOW_PKG_TMPL, searchList=[srv4])
            sys.stdout.write(unicode(t))
    elif command == 'gen-html':
        g = HtmlGenerator(md5_sums, options.pkg_review_template)
        sys.stdout.write(g.GenerateHtml())
    elif command == 'initdb':
        config = configuration.GetConfig()
        db_uri = configuration.ComposeDatabaseUri(config)
        dbc = database.CatalogDatabase(uri=db_uri)
        dbc.CreateTables()
        dbc.InitialDataImport()
    elif command == 'importpkg':
        collector = package_stats.StatsCollector(logger=logging,
                                                 debug=options.debug)
        file_list = args
        try:
            stats_list = collector.CollectStatsFromFiles(
                file_list, None, force_unpack=options.force_unpack)
        except sqlobject.dberrors.OperationalError, e:
            exception_msg = (
                "DELETE command denied to user "
                "'pkg_maintainer'@'192.168.1.2' for table 'csw_file'")
            if exception_msg in str(e):
                logging.fatal(
                    "You don't have sufficient privileges to overwrite previously "
                    "imported package. Did you run checkpkg before running "
                    "csw-upload-pkg?")
                sys.exit(1)
            else:
                raise e
        for stats in stats_list:
            logging.debug("Importing %s, %s", stats["basic_stats"]["md5_sum"],
                          stats["basic_stats"]["pkg_basename"])
            try:
                package_stats.PackageStats.ImportPkg(stats, options.replace)
            except sqlobject.dberrors.OperationalError, e:
                logging.fatal(
                    "A problem when importing package data has occurred: %s",
                    e)
                sys.exit(1)
Exemple #2
0
def main():
    parser = optparse.OptionParser(USAGE)
    parser.add_option("-d",
                      "--debug",
                      dest="debug",
                      default=False,
                      action="store_true",
                      help="Turn on debugging messages")
    parser.add_option(
        "-t",
        "--pkg-review-template",
        dest="pkg_review_template",
        help="A Cheetah template used for package review reports.")
    parser.add_option("-r",
                      "--os-release",
                      dest="osrel",
                      default="SunOS5.9",
                      help="E.g. SunOS5.9")
    parser.add_option("-a",
                      "--arch",
                      dest="arch",
                      default="sparc",
                      help="'i386' or 'sparc'")
    parser.add_option("-c",
                      "--catalog-release",
                      dest="catrel",
                      default="current",
                      help="E.g. current, unstable, testing, stable")
    parser.add_option("--replace",
                      dest="replace",
                      default=False,
                      action="store_true",
                      help="Replace packages when importing (importpkg)")
    parser.add_option("--profile",
                      dest="profile",
                      default=False,
                      action="store_true",
                      help="Turn on profiling")
    parser.add_option("--force-unpack",
                      dest="force_unpack",
                      default=False,
                      action="store_true",
                      help="Force unpacking of packages")
    options, args = parser.parse_args()
    if options.debug:
        logging.basicConfig(level=logging.DEBUG)
        logging.debug("Debugging on")
    else:
        logging.basicConfig(level=logging.INFO)
    if not args:
        raise UsageError("Please specify a command.  Se --help.")
    # SetUpSqlobjectConnection needs to be called after
    # logging.basicConfig
    configuration.SetUpSqlobjectConnection()
    command = args[0]
    args = args[1:]
    if command == 'show':
        subcommand = args[0]
        args = args[1:]
    elif command == 'pkg':
        subcommand = args[0]
        args = args[1:]
    else:
        subcommand = None

    md5_sums = args

    dm = database.DatabaseManager()
    # Automanage is not what we want to do, if the intention is to initialize
    # the database.
    if command != 'initdb':
        dm.AutoManage()

    if (command, subcommand) == ('show', 'errors'):
        for md5_sum in md5_sums:
            srv4 = GetPkg(md5_sum)
            res = m.CheckpkgErrorTag.select(
                m.CheckpkgErrorTag.q.srv4_file == srv4)
            for row in res:
                print row.pkgname, row.tag_name, row.tag_info, row.catrel.name, row.arch.name,
                print row.os_rel.short_name
    elif (command, subcommand) == ('show', 'overrides'):
        for md5_sum in md5_sums:
            srv4 = GetPkg(md5_sum)
            res = m.CheckpkgOverride.select(
                m.CheckpkgOverride.q.srv4_file == srv4)
            for row in res:
                print row.pkgname, row.tag_name, row.tag_info
    elif (command, subcommand) == ('show', 'pkg'):
        for md5_sum in md5_sums:
            srv4 = GetPkg(md5_sum)
            t = Template(SHOW_PKG_TMPL, searchList=[srv4])
            sys.stdout.write(unicode(t))
    elif command == 'gen-html':
        g = HtmlGenerator(md5_sums, options.pkg_review_template)
        sys.stdout.write(g.GenerateHtml())
    elif command == 'initdb':
        config = configuration.GetConfig()
        db_uri = configuration.ComposeDatabaseUri(config)
        dbc = database.CatalogDatabase(uri=db_uri)
        dbc.CreateTables()
        dbc.InitialDataImport()
    elif command == 'importpkg':
        collector = package_stats.StatsCollector(logger=logging,
                                                 debug=options.debug)
        file_list = args
        stats_list = collector.CollectStatsFromFiles(
            file_list, None, force_unpack=options.force_unpack)
        for stats in stats_list:
            logging.debug("Importing %s, %s", stats["basic_stats"]["md5_sum"],
                          stats["basic_stats"]["pkg_basename"])
            package_stats.PackageStats.ImportPkg(stats, options.replace)
    elif command == 'removepkg':
        for md5_sum in md5_sums:
            srv4 = GetPkg(md5_sum)
            in_catalogs = list(srv4.in_catalogs)
            if in_catalogs:
                for in_catalog in in_catalogs:
                    logging.warning("%s", in_catalog)
                logging.warning(
                    "Not removing from the database, because the package "
                    "in question is part of at least one catalog.")
            else:
                logging.info("Removing %s", srv4)
                srv4.DeleteAllDependentObjects()
                srv4.destroySelf()
    elif command == 'add-to-cat':
        if len(args) <= 3:
            raise UsageError("Not enough arguments, see usage.")
        osrel, arch, catrel = args[:3]
        c = checkpkg_lib.Catalog()
        md5_sums = args[3:]
        for md5_sum in md5_sums:
            logging.debug("Adding %s to the catalog", md5_sum)
            try:
                sqo_srv4 = m.Srv4FileStats.select(
                    m.Srv4FileStats.q.md5_sum == md5_sum).getOne()
                c.AddSrv4ToCatalog(sqo_srv4, osrel, arch, catrel)
            except sqlobject.main.SQLObjectNotFound, e:
                logging.warning("Srv4 file %s was not found in the database.",
                                md5_sum)
Exemple #3
0
 def testCanCreateTablesAndImportData(self):
     dbc = database.CatalogDatabase(uri="sqlite:/:memory:")
     dbc.CreateTables()
     dbc.InitialDataImport()
Exemple #4
0
 def testCanCreateTables(self):
     # This test succeeds when run with sqlite, but fails with MySQL.
     # We don't want to add a dependency on a running MySQL database to run tests, so
     # we'll leave it unsolved for now.
     dbc = database.CatalogDatabase(uri="sqlite:/:memory:")
     dbc.CreateTables()
Exemple #5
0
 def setUp(self):
   super(SqlObjectTestMixin, self).setUp()
   self.dbc = database.CatalogDatabase(uri="sqlite:/:memory:")
   self.dbc.CreateTables()