Example #1
0
/**
 * main:
 **/
int
main (int argc, char *argv[])
{
	gboolean relax = FALSE;
	gboolean ret;
	gboolean verbose = FALSE;
	gboolean version = FALSE;
	gchar *config_dump = NULL;
	GError *error = NULL;
	gint retval = EXIT_CODE_SUCCESS;
	gint retval_tmp;
	GKeyFile *config = NULL;
	GOptionContext *context;
	guint i;
	const GOptionEntry options[] = {
		{ "relax", 'r', 0, G_OPTION_ARG_NONE, &relax,
			/* TRANSLATORS: this is the --relax argument */
			_("Be less strict when checking files"), NULL },
		{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
			/* TRANSLATORS: this is the --verbose argument */
			_("Show extra debugging information"), NULL },
		{ "version", '\0', 0, G_OPTION_ARG_NONE, &version,
			/* TRANSLATORS: this is the --version argument */
			_("Show the version number and then quit"), NULL },
		{ NULL}
	};

	setlocale (LC_ALL, "");
	bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);

	g_type_init ();

	context = g_option_context_new ("AppData Validation Program");
	g_option_context_add_main_entries (context, options, NULL);
	ret = g_option_context_parse (context, &argc, &argv, &error);
	if (!ret) {
		/* TRANSLATORS: this is where the user used unknown command
		 * line switches -- the exact error follows */
		g_print ("%s %s\n", _("Failed to parse command line:"), error->message);
		g_error_free (error);
		goto out;
	}

	/* just show the version */
	if (version) {
		g_print ("%s\n", PACKAGE_VERSION);
		goto out;
	}

	/* verbose? */
	if (verbose) {
		g_log_set_fatal_mask (NULL, G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL);
		g_log_set_handler ("AppDataTools",
				   G_LOG_LEVEL_ERROR |
				   G_LOG_LEVEL_CRITICAL |
				   G_LOG_LEVEL_DEBUG |
				   G_LOG_LEVEL_WARNING,
				   appdata_validate_log_handler_cb, NULL);
	} else {
		/* hide all debugging */
		g_log_set_fatal_mask (NULL, G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL);
		g_log_set_handler ("AppDataTools",
				   G_LOG_LEVEL_DEBUG,
				   appdata_validate_log_ignore_cb, NULL);
	}

	if (argc < 2) {
		retval = EXIT_CODE_USAGE;
		/* TRANSLATORS: this is explaining how to use the tool */
		g_print ("%s %s %s\n", _("Usage:"), argv[0], _("<file>"));
		goto out;
	}

	/* set some config values */
	config = g_key_file_new ();
	if (relax || g_getenv ("RELAX") != NULL) {
		g_key_file_set_integer (config, APPDATA_TOOLS_VALIDATE_GROUP_NAME,
					"LengthUpdatecontactMin", 6);
		g_key_file_set_integer (config, APPDATA_TOOLS_VALIDATE_GROUP_NAME,
					"LengthNameMin", 4);
		g_key_file_set_integer (config, APPDATA_TOOLS_VALIDATE_GROUP_NAME,
					"LengthNameMax", 100);
		g_key_file_set_integer (config, APPDATA_TOOLS_VALIDATE_GROUP_NAME,
					"LengthSummaryMin", 8);
		g_key_file_set_integer (config, APPDATA_TOOLS_VALIDATE_GROUP_NAME,
					"LengthSummaryMax", 200);
		g_key_file_set_integer (config, APPDATA_TOOLS_VALIDATE_GROUP_NAME,
					"LengthParaMin", 10);
		g_key_file_set_integer (config, APPDATA_TOOLS_VALIDATE_GROUP_NAME,
					"LengthParaMax", 1000);
		g_key_file_set_integer (config, APPDATA_TOOLS_VALIDATE_GROUP_NAME,
					"LengthListItemMin", 4);
		g_key_file_set_integer (config, APPDATA_TOOLS_VALIDATE_GROUP_NAME,
					"LengthListItemMax", 1000);
		g_key_file_set_integer (config, APPDATA_TOOLS_VALIDATE_GROUP_NAME,
					"NumberParaMin", 1);
		g_key_file_set_integer (config, APPDATA_TOOLS_VALIDATE_GROUP_NAME,
					"NumberParaMax", 10);
		g_key_file_set_integer (config, APPDATA_TOOLS_VALIDATE_GROUP_NAME,
					"NumberScreenshotsMin", 0);
		g_key_file_set_boolean (config, APPDATA_TOOLS_VALIDATE_GROUP_NAME,
					"RequireContactdetails", FALSE);
		g_key_file_set_integer (config, APPDATA_TOOLS_VALIDATE_GROUP_NAME,
					"NumberScreenshotsMax", 10);
		g_key_file_set_boolean (config, APPDATA_TOOLS_VALIDATE_GROUP_NAME,
					"RequireUrl", FALSE);
	} else {
		g_key_file_set_integer (config, APPDATA_TOOLS_VALIDATE_GROUP_NAME,
					"LengthUpdatecontactMin", 6);
		g_key_file_set_integer (config, APPDATA_TOOLS_VALIDATE_GROUP_NAME,
					"LengthNameMin", 4);
		g_key_file_set_integer (config, APPDATA_TOOLS_VALIDATE_GROUP_NAME,
					"LengthNameMax", 30);
		g_key_file_set_integer (config, APPDATA_TOOLS_VALIDATE_GROUP_NAME,
					"LengthSummaryMin", 8);
		g_key_file_set_integer (config, APPDATA_TOOLS_VALIDATE_GROUP_NAME,
					"LengthSummaryMax", 100);
		g_key_file_set_integer (config, APPDATA_TOOLS_VALIDATE_GROUP_NAME,
					"LengthParaMin", 50);
		g_key_file_set_integer (config, APPDATA_TOOLS_VALIDATE_GROUP_NAME,
					"LengthParaMax", 600);
		g_key_file_set_integer (config, APPDATA_TOOLS_VALIDATE_GROUP_NAME,
					"LengthListItemMin", 20);
		g_key_file_set_integer (config, APPDATA_TOOLS_VALIDATE_GROUP_NAME,
					"LengthListItemMax", 100);
		g_key_file_set_integer (config, APPDATA_TOOLS_VALIDATE_GROUP_NAME,
					"NumberParaMin", 2);
		g_key_file_set_integer (config, APPDATA_TOOLS_VALIDATE_GROUP_NAME,
					"NumberParaMax", 4);
		g_key_file_set_integer (config, APPDATA_TOOLS_VALIDATE_GROUP_NAME,
					"NumberScreenshotsMin", 1);
		g_key_file_set_integer (config, APPDATA_TOOLS_VALIDATE_GROUP_NAME,
					"NumberScreenshotsMax", 5);
		g_key_file_set_boolean (config, APPDATA_TOOLS_VALIDATE_GROUP_NAME,
					"RequireContactdetails", TRUE);
		g_key_file_set_boolean (config, APPDATA_TOOLS_VALIDATE_GROUP_NAME,
					"RequireUrl", TRUE);
	}
	config_dump = g_key_file_to_data (config, NULL, &error);
	g_debug ("%s", config_dump);

	/* validate each file */
	for (i = 1; i < argc; i++) {
		retval_tmp = appdata_validate_and_show_results (config, argv[i]);
		if (retval_tmp != EXIT_CODE_SUCCESS)
			retval = retval_tmp;
	}
out:
	if (config != NULL)
		g_key_file_free (config);
	g_free (config_dump);
	g_option_context_free (context);
	return retval;
}
Example #2
0
/**
 * main:
 **/
int
main (int argc, char *argv[])
{
	AsAppValidateFlags validate_flags = 0;
	gboolean nonet = FALSE;
	gboolean relax = FALSE;
	gboolean ret;
	gboolean strict = FALSE;
	gboolean verbose = FALSE;
	gboolean version = FALSE;
	gchar *filename = NULL;
	gchar *output_format = NULL;
	GError *error = NULL;
	gint i;
	gint retval = EXIT_CODE_SUCCESS;
	gint retval_tmp;
	GOptionContext *context;
	const GOptionEntry options[] = {
		{ "relax", 'r', 0, G_OPTION_ARG_NONE, &relax,
			/* TRANSLATORS: this is the --relax argument */
			_("Be less strict when checking files"), NULL },
		{ "strict", 's', 0, G_OPTION_ARG_NONE, &strict,
			/* TRANSLATORS: this is the --relax argument */
			_("Be more strict when checking files"), NULL },
		{ "nonet", '\0', 0, G_OPTION_ARG_NONE, &nonet,
			/* TRANSLATORS: this is the --nonet argument */
			_("Do not use network access"), NULL },
		{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
			/* TRANSLATORS: this is the --verbose argument */
			_("Show extra debugging information"), NULL },
		{ "version", '\0', 0, G_OPTION_ARG_NONE, &version,
			/* TRANSLATORS: this is the --version argument */
			_("Show the version number and then quit"), NULL },
		{ "filename", '\0', 0, G_OPTION_ARG_STRING, &filename,
			/* TRANSLATORS: this is the --filename argument */
			_("The source filename when using a temporary file"), NULL },
		{ "output-format", '\0', 0, G_OPTION_ARG_STRING, &output_format,
			/* TRANSLATORS: this is the --output-format argument */
			_("The output format [text|html|xml]"), NULL },
		{ NULL}
	};

	setlocale (LC_ALL, "");
	bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);

#if !GLIB_CHECK_VERSION(2,36,0)
	g_type_init ();
#endif
	context = g_option_context_new ("AppData Validation Program");
	g_option_context_add_main_entries (context, options, NULL);
	ret = g_option_context_parse (context, &argc, &argv, &error);
	if (!ret) {
		/* TRANSLATORS: this is where the user used unknown command
		 * line switches -- the exact error follows */
		g_print ("%s %s\n", _("Failed to parse command line:"), error->message);
		g_error_free (error);
		goto out;
	}

	/* big fat warning */
	g_print ("THIS TOOL IS *DEPRECATED* AND WILL BE REMOVED SOON.\n");
	g_print ("Please use 'apstream-util validate' in appstream-glib.\n\n");

	/* just show the version */
	if (version) {
		g_print ("%s\n", PACKAGE_VERSION);
		goto out;
	}

	/* verbose? */
	if (verbose) {
		g_log_set_fatal_mask (NULL, G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL);
		g_log_set_handler ("AppDataTools",
				   G_LOG_LEVEL_ERROR |
				   G_LOG_LEVEL_CRITICAL |
				   G_LOG_LEVEL_DEBUG |
				   G_LOG_LEVEL_WARNING,
				   appdata_validate_log_handler_cb, NULL);
	} else {
		/* hide all debugging */
		g_log_set_fatal_mask (NULL, G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL);
		g_log_set_handler ("AppDataTools",
				   G_LOG_LEVEL_DEBUG,
				   appdata_validate_log_ignore_cb, NULL);
	}

	if (argc < 2) {
		retval = EXIT_CODE_USAGE;
		/* TRANSLATORS: this is explaining how to use the tool */
		g_print ("%s %s %s\n", _("Usage:"), argv[0], _("<file>"));
		goto out;
	}

	/* make more strict or relaxed */
	if (strict)
		validate_flags |= AS_APP_VALIDATE_FLAG_STRICT;
	else if (relax)
		validate_flags |= AS_APP_VALIDATE_FLAG_RELAX;

	/* the user has forced no network mode */
	if (nonet)
		validate_flags |= AS_APP_VALIDATE_FLAG_NO_NETWORK;

	/* validate each file */
	for (i = 1; i < argc; i++) {
		retval_tmp = appdata_validate_and_show_results (filename,
								argv[i],
								output_format,
								validate_flags);
		if (retval_tmp != EXIT_CODE_SUCCESS)
			retval = retval_tmp;
	}
out:
	g_free (filename);
	g_free (output_format);
	g_option_context_free (context);
	return retval;
}