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);
}
Exemplo n.º 2
0
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

    g_log_set_default_handler(cr_log_fn, NULL);
    if (options.verbose) {
        // Verbose mode
        GLogLevelFlags levels = G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG | G_LOG_LEVEL_WARNING;
        g_log_set_handler(NULL, levels, cr_log_fn, NULL);
        g_log_set_handler("C_CREATEREPOLIB", levels, cr_log_fn, NULL);
    } else {
        // Standard mode
        GLogLevelFlags levels = G_LOG_LEVEL_DEBUG;
        g_log_set_handler(NULL, levels, cr_null_log_fn, NULL);
        g_log_set_handler("C_CREATEREPOLIB", levels, cr_null_log_fn, NULL);
    }

    // Print version if required

    if (options.version) {
        printf("Version: %d.%d.%d\n", CR_VERSION_MAJOR,
                                      CR_VERSION_MINOR,
                                      CR_VERSION_PATCH);
        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);
    }

    g_thread_init(NULL); // Initialize threading

    // 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);
}