Example #1
0
/**
 * Main
 */
int
main(int argc, char **argv)
{
    gboolean ret = TRUE;
    _cleanup_sqliterepocmdoptions_free_ SqliterepoCmdOptions *options = NULL;
    _cleanup_error_free_ GError *tmp_err = NULL;

    // Parse arguments
    options = sqliterepocmdoptions_new();
    if (!parse_sqliterepo_arguments(&argc, &argv, options, &tmp_err)) {
        g_printerr("%s\n", tmp_err->message);
        exit(EXIT_FAILURE);
    }

    // Set logging
    cr_setup_logging(FALSE, options->verbose);

    // Print version if required
    if (options->version) {
        printf("Version: %s\n", cr_version_string_with_features());
        exit(EXIT_SUCCESS);
    }

    // Check arguments
    if (!check_arguments(options, &tmp_err)) {
        g_printerr("%s\n", tmp_err->message);
        exit(EXIT_FAILURE);
    }

    if (argc != 2) {
        g_printerr("Must specify exactly one repo directory to work on\n");
        exit(EXIT_FAILURE);
    }

    // Emit debug message with version
    g_debug("Version: %s", cr_version_string_with_features());

    g_thread_init(NULL); // Initialize threading

    // Gen the databases
    ret = generate_sqlite_from_xml(argv[1],
                                   options->compression_type,
                                   options->checksum_type,
                                   options->local_sqlite,
                                   options->force,
                                   options->keep_old,
                                   &tmp_err);
    if (!ret) {
        g_printerr("%s\n", tmp_err->message);
        exit(EXIT_FAILURE);
    }

    exit(EXIT_SUCCESS);
}
int
main(int argc, char **argv)
{
    gboolean ret = TRUE;
    RawCmdOptions options;
    GError *err = NULL;

    // Parse arguments

    parse_arguments(&argc, &argv, &options, &err);
    if (err) {
        g_printerr("%s\n", err->message);
        print_usage();
        g_error_free(err);
        exit(EXIT_FAILURE);
    }

    // Set logging

    cr_setup_logging(FALSE, options.verbose);


    // Print version if required

    if (options.version) {
        printf("Version: %s\n", cr_version_string_with_features());
        exit(EXIT_SUCCESS);
    }

    // Check arguments

    check_arguments(&options, &err);
    if (err) {
        g_printerr("%s\n", err->message);
        print_usage();
        g_error_free(err);
        exit(EXIT_FAILURE);
    }

    // Emit debug message with version

    g_debug("Version: %s", cr_version_string_with_features());

    // Prepare list of tasks to do

    gchar *repodatadir = NULL;
    GSList *modifyrepotasks = NULL;

    if (!options.batchfile && !options.remove && argc == 3) {
        // three arguments (prog, metadata, repodata_dir)
        repodatadir = argv[2];
        ret = cmd_options_to_task(&modifyrepotasks,
                                  &options,
                                  argv[1],
                                  &err);
    } else if (options.batchfile && argc == 2) {
        // two arguments (prog, repodata_dir)
        repodatadir = argv[1];
        ret = cr_modifyrepo_parse_batchfile(options.batchfile,
                                            &modifyrepotasks,
                                            &err);
    } else if (!options.batchfile && options.remove && argc == 2) {
        // two arguments (prog, repodata_dir)
        repodatadir = argv[1];
        ret = cmd_options_to_task(&modifyrepotasks,
                                  &options,
                                  NULL,
                                  &err);
    } else {
        // Bad arguments
        print_usage();
        exit(EXIT_FAILURE);
    }

    if (!ret) {
        g_printerr("%s\n", err->message);
        g_error_free(err);
        exit(EXIT_FAILURE);
    }

    // Process the tasks

    ret = cr_modifyrepo(modifyrepotasks, repodatadir, &err);
    cr_slist_free_full(modifyrepotasks, (GDestroyNotify)cr_modifyrepotask_free);

    if (!ret) {
        g_printerr("%s\n", err->message);
        g_error_free(err);
        exit(EXIT_FAILURE);
    }

    exit(EXIT_SUCCESS);
}