コード例 #1
0
ファイル: util.c プロジェクト: peter1000/package-query
void show_results (void)
{
	if (!results) {
		return;
	}

	alpm_list_fn_cmp fn_cmp = NULL;
	switch (config.sort) {
		case S_NAME:  fn_cmp = (alpm_list_fn_cmp) results_cmp; break;
		case S_VOTE:  fn_cmp = (alpm_list_fn_cmp) results_votes_cmp; break;
		case S_POP:   fn_cmp = (alpm_list_fn_cmp) results_popularity_cmp; break;
		case S_IDATE: fn_cmp = (alpm_list_fn_cmp) results_installdate_cmp; break;
		case S_ISIZE: fn_cmp = (alpm_list_fn_cmp) results_isize_cmp; break;
		case S_REL:   fn_cmp = (alpm_list_fn_cmp) results_relevance_cmp; break;
	}
	if (fn_cmp) {
		results = alpm_list_msort (results, alpm_list_count (results), fn_cmp);
	}

	const alpm_list_nav fn_nav = config.rsort ? alpm_list_previous : alpm_list_next;
	const alpm_list_t *i_first = config.rsort ? alpm_list_last (results) : results;

	for (const alpm_list_t *i = i_first; i; i = fn_nav (i)) {
		const results_t *r = i->data;
		if (r && r->type == R_ALPM_PKG) {
			print_package ("", r->ele, alpm_pkg_get_str);
		} else if (r && r->type == R_AUR_PKG) {
			print_package ("", r->ele, aur_get_str);
		}
	}

	alpm_list_free_inner (results, (alpm_list_fn_free) results_free);
	alpm_list_free (results);
	results = NULL;
}
コード例 #2
0
ファイル: util.c プロジェクト: peter1000/package-query
void print_or_add_result (void *pkg, unsigned short type)
{
	if (config.sort == 0) {
		print_package ("", pkg, (type == R_ALPM_PKG) ? alpm_pkg_get_str : aur_get_str);
		return;
	}

	results = alpm_list_add (results, results_new (pkg, type));
}
コード例 #3
0
ファイル: util.c プロジェクト: ava1ar/package-query
void show_results ()
{
	alpm_list_t *i_first;
	alpm_list_t *i;
	alpm_list_nav fn_nav=NULL;;
	alpm_list_fn_cmp fn_cmp=NULL;
	if (results!=NULL)
	{
		switch (config.sort)
		{
			case S_NAME: fn_cmp = (alpm_list_fn_cmp) results_cmp; break;
			case S_VOTE: fn_cmp = (alpm_list_fn_cmp) results_votes_cmp; break;
			case S_IDATE: fn_cmp = (alpm_list_fn_cmp) results_installdate_cmp; break;
			case S_ISIZE: fn_cmp = (alpm_list_fn_cmp) results_isize_cmp; break;
		}
		if (fn_cmp)
			results = alpm_list_msort (results, alpm_list_count (results), fn_cmp);
		if (config.rsort) {
			fn_nav = (alpm_list_nav) alpm_list_previous;
			i_first = alpm_list_last (results);
		} else {
			fn_nav = (alpm_list_nav) alpm_list_next;
			i_first = results;
		}
		for(i = i_first; i; i = fn_nav(i))
		{
			results_t *r = i->data;
			if (r->type == R_ALPM_PKG)
				print_package ("", r->ele, alpm_pkg_get_str);
			else if (r->type == R_AUR_PKG)
				print_package ("", r->ele, aur_get_str);
		}
		alpm_list_free_inner (results, (alpm_list_fn_free) results_free);
		alpm_list_free (results);
		results = NULL;
	}
}
コード例 #4
0
void
opkg_test (void)
{
  int err;
  pkg_t *pkg;

  err = opkg_update_package_lists (progress_callback, "Updating...");
  printf ("\nopkg_update_package_lists returned %d\n", err);

  opkg_list_packages (package_list_callback, NULL);
  printf ("\n");

  if (find_pkg)
  {
    printf ("Finding package \"%s\"\n", find_pkg->name);
    pkg = opkg_find_package (find_pkg->name, find_pkg->version, find_pkg->architecture, find_pkg->src->name);
    if (pkg)
    {
      print_package (pkg);
    }
    else
      printf ("Package \"%s\" not found!\n", find_pkg->name);
  }
  else
    printf ("No package available to test find_package.\n");

  err = opkg_install_package (TEST_PACKAGE, progress_callback, "Installing...");
  printf ("\nopkg_install_package returned %d\n", err);

  err = opkg_upgrade_package (TEST_PACKAGE, progress_callback, "Upgrading...");
  printf ("\nopkg_upgrade_package returned %d\n", err);

  err = opkg_remove_package (TEST_PACKAGE, progress_callback, "Removing...");
  printf ("\nopkg_remove_package returned %d\n", err);

  printf ("Listing upgradable packages...\n");
  opkg_list_upgradable_packages (package_list_upgradable_callback, NULL);

  err = opkg_upgrade_all (progress_callback, "Upgrading all...");
  printf ("\nopkg_upgrade_all returned %d\n", err);

}
コード例 #5
0
ファイル: package-query.c プロジェクト: CRamsan/arch-live
int main (int argc, char **argv)
{
	int ret=0, i;
	int need=0, given=0, cycle_db=0, db_order=0;
	alpm_list_t *t;

	struct sigaction a;
	init_config (argv[0]);
	a.sa_handler = handler;
	sigemptyset(&a.sa_mask);
	a.sa_flags = 0;
	sigaction(SIGINT, &a, NULL);
	sigaction(SIGTERM, &a, NULL);

	int opt;
	int opt_index=0;
	static struct option opts[] =
	{
		{"query",      no_argument,       0, 'Q'},
		{"sync",       no_argument,       0, 'S'},
		{"dbpath",     required_argument, 0, 'b'},
		{"deps",       no_argument,       0, 'd'},
		{"explicit",   no_argument,       0, 'e'},
		{"groups",     no_argument,       0, 'g'},
		{"help",       no_argument,       0, 'h'},
		{"info",       no_argument,       0, 'i'},
		{"list",       no_argument,       0, 'l'},
		{"foreign",    no_argument,       0, 'm'},
		{"file",       no_argument,       0, 'p'},
		{"quiet",      no_argument,       0, 'q'},
		{"root",       required_argument, 0, 'r'},
		{"search",     no_argument,       0, 's'},
		{"unrequired", no_argument,       0, 't'},
		{"upgrades",   no_argument,       0, 'u'},
		{"config",     required_argument, 0, 'c'},
		{"just-one",   no_argument,       0, '1'},
		{"aur",        no_argument,       0, 'A'},
		{"escape",     no_argument,       0, 'x'},
		{"format",     required_argument, 0, 'f'},
		{"list-repo",  required_argument, 0, 'L'},
		{"query-type", required_argument, 0, 1000},
		{"csep",       required_argument, 0, 1001},
		{"delimiter",  required_argument, 0, 1001},
		{"sort",       required_argument, 0, 1002},
		{"nocolor",    no_argument,       0, 1003},
		{"number",     no_argument,       0, 1004},
		{"get-res",    no_argument,       0, 1005},
		{"show-size",  no_argument,       0, 1006},
		{"aur-url",    required_argument, 0, 1007},
		{"insecure",   no_argument,       0, 1008},
		{"qdepends",   no_argument,       0, 1009},
		{"qconflicts", no_argument,       0, 1010},
		{"qprovides",  no_argument,       0, 1011},
		{"qreplaces",  no_argument,       0, 1012},
		{"qrequires",  no_argument,       0, 1013},
		{"color",      no_argument,       0, 1014},
		{"version",    no_argument,       0, 'v'},

		{0, 0, 0, 0}
	};

	
	while ((opt = getopt_long (argc, argv, "1Ac:b:def:ghiLlmpQqr:Sstuvx", opts, &opt_index)) != -1) 
	{
		switch (opt) 
		{
			case '1':
				config.just_one = 1;
				break;
			case 'A':
				if (config.aur) break;
				config.aur = ++db_order;
				given |= N_DB;
				break;
			case 'c':
				FREE (config.configfile);
				config.configfile = strndup (optarg, PATH_MAX);
				break;
			case 'b':
				FREE (config.dbpath);
				config.dbpath = strndup (optarg, PATH_MAX);
				break;
			case 'd':
				config.filter |= F_DEPS;
				break;
			case 'e':
				config.filter |= F_EXPLICIT;
				break;
			case 'x':
				config.escape = 1;
				break;
			case 'f':
				config.custom_out = 1;
				strncpy (config.format_out, optarg, PATH_MAX);
				format_str (config.format_out);
				break;
			case 'g':
				if (config.op) break;
				config.op = OP_LIST_GROUP;
				config.filter |= F_GROUP;
				cycle_db = 1;
				break;
			case 'i':
				if (config.op)
				{
					if (config.op == OP_INFO) config.op = OP_INFO_P;
					break;
				}
				config.op = OP_INFO;
				need |= N_TARGET | N_DB;
				break;
			case 'L':
				config.list = 1;
				break;
			case 'l':
				if (config.op) break;
				config.op = OP_LIST_REPO;
				need |= N_DB;
				cycle_db = 1;
				break;
			case 'm':
				config.filter |= F_FOREIGN;
				break;
			case 'p':
				config.is_file = 1;
				need |= N_TARGET;
				break;
			case 'Q':
				if (config.db_local) break;
				config.db_local = ++db_order;
				given |= N_DB;
				break;
			case 'q':
				config.quiet = 1;
				break;
			case 'r':
				FREE (config.rootdir);
				config.rootdir = strndup (optarg, PATH_MAX);
				break;
			case 's':
				if (config.op) break;
				config.op = OP_SEARCH;
				need |= N_DB;
				cycle_db = 1;
				break;
			case 'S':
				if (config.db_sync) break;
				config.db_sync = ++db_order;
				given |= N_DB;
				break;
			case 't':
				config.filter |= F_UNREQUIRED;
				break;
			case 1000: /* --query-type */
				if (config.op) break;
				config.op = OP_QUERY;
				if (strcmp (optarg, "depends")==0)
					config.query = OP_Q_DEPENDS;
				else if (strcmp (optarg, "conflicts")==0)
					config.query = OP_Q_CONFLICTS;
				else if (strcmp (optarg, "provides")==0)
					config.query = OP_Q_PROVIDES;
				else if (strcmp (optarg, "replaces")==0)
					config.query = OP_Q_REPLACES;
				need |= N_TARGET | N_DB;
				break;
			case 1009: /* --qdepends */
				SETQUERY (OP_Q_DEPENDS); break;
			case 1010: /* --qconflicts */
				SETQUERY (OP_Q_CONFLICTS); break;
			case 1011: /* --qprovides */
				SETQUERY (OP_Q_PROVIDES); break;
			case 1012: /* --qreplaces */
				SETQUERY (OP_Q_REPLACES); break;
			case 1013: /* --qrequires */
				SETQUERY (OP_Q_REQUIRES); break;
			case 1001: /* --delimiter */
				strncpy (config.delimiter, optarg, SEP_LEN);
				format_str (config.delimiter);
				break;
			case 1002: /* --sort */
				config.sort = optarg[0];
				break;
			case 1003: /* --nocolor */
				config.colors=0;
				break;
			case 1004: /* --number */
				config.numbering = 1;
				break;
			case 1005: /* --get-res */
				if (dup2(FD_RES, FD_RES) == FD_RES)
					config.get_res = 1;
				break;
			case 1006: /* --show-size */
				config.show_size = 1;
				break;
			case 1007: /* --aur-url */
				FREE (config.aur_url);
				config.aur_url = strdup (optarg);
				break;
			case 1008: /* --insecure */
				config.insecure = 1;
				break;
			case 1014: /* --color */
				config.colors=1;
				break;
			case 'u':
				config.filter |= F_UPGRADES;
				break;
			case 'v':
				version(); break;
			case 'h': usage (0); break;
			default: /* '?' */
				usage (1);
		}
	}
	if (config.list)
	{
		/* -L displays respository list and exits. */
		alpm_list_t *dbs = get_db_sync ();
		if (dbs)
		{
			for(t = dbs; t; t = alpm_list_next(t))
				printf ("%s\n", (char *)t->data);
			FREELIST (dbs);
		}
		cleanup (0);
	}
	if (!config.custom_out)
	{
		if (config.colors)
			color_init();
#if defined(HAVE_GETTEXT) && defined(ENABLE_NLS)
		/* TODO: specific package-query locale ? */
		setlocale (LC_ALL, "");
		bindtextdomain ("yaourt", LOCALEDIR);
		textdomain ("yaourt");
#endif
	}
	if ((need & N_DB) && !(given & N_DB))
	{
		fprintf(stderr, "search or information must have database target (-{Q,S,A}).\n");
		exit(1);
	}
	for (i = optind; i < argc; i++)
	{
		if (!config.just_one ||
		    !alpm_list_find_str (targets, argv[i]))
			targets = alpm_list_add(targets, strdup(argv[i]));
	}
	if (i!=optind) 
	{
		given |= N_TARGET;
	}
	if ((need & N_TARGET) && !(given & N_TARGET))
	{
		fprintf(stderr, "no targets specified.\n");
		usage(1);
	}
	if (targets == NULL)
	{
		if (config.op == OP_SEARCH)	config.op = OP_LIST_REPO_S;
	}
	else if (!config.op && (given & N_DB)) /* Show info by default */
		config.op = OP_INFO;
	// init_db_sync initializes alpm after parsing [options]
	if (!init_db_sync ()) cleanup(1);
	if (config.is_file)
	{
		for(t = targets; t; t = alpm_list_next(t))
		{
			alpm_pkg_t *pkg=NULL;
			const char *filename = t->data;
			if (alpm_pkg_load (config.handle, filename, 0, ALPM_SIG_USE_DEFAULT, &pkg)!=0 || pkg==NULL)
			{
				fprintf(stderr, "unable to read %s.\n", filename);
				continue;
			}
			print_package (filename, pkg, alpm_pkg_get_str);
			ret++;
		}
		cleanup(!ret);
	}

	if  (cycle_db || targets)
	{
		for (i=1; i<=db_order && (cycle_db || targets); i++)
		{
			/*printf ("%d, aur %d, local %d, sync %d\n", i, config.aur, config.db_local, config.db_sync);*/
			if (config.db_sync == i)
			{
				for(t = alpm_get_syncdbs(config.handle); t; t = alpm_list_next(t))
					ret += deal_db (t->data);
				if (!ret && config.op == OP_INFO_P)
				{
					config.op = OP_QUERY;
					config.query = OP_Q_PROVIDES;
					for(t = alpm_get_syncdbs(config.handle); t; t = alpm_list_next(t))
						ret += deal_db (t->data);
					config.op = OP_INFO_P;
				}
			}
			else if (config.db_local == i)
				ret += deal_db (alpm_get_localdb(config.handle));
			else if (config.aur == i)
				switch (config.op)
				{
					case OP_INFO:
					case OP_INFO_P: ret += aur_info (&targets); break;
					case OP_SEARCH: ret += aur_search (targets); break;
					default: break;
				}
		}
	}
	else if (!config.aur && config.db_local)
		ret += alpm_search_local (config.filter, NULL, NULL);
	else if (config.aur && !(given & N_TARGET))
	{
		if (config.filter & F_FOREIGN)
		{
			/* -Am */
			config.aur_foreign = 1;
			config.just_one = 1;
			alpm_search_local (config.filter, "%n", &targets);
			ret += aur_info (&targets);
			if (config.db_local)
				/* -AQm */
				ret += search_pkg_by_name (alpm_get_localdb(config.handle), &targets);
		}
		else if (config.filter & F_UPGRADES)
		{
			/* -Au */
			config.aur_upgrades = 1;
			if (config.db_local)
				/* -AQu */
				ret += alpm_search_local (config.filter, NULL, NULL);
			alpm_search_local (F_FOREIGN | (config.filter & ~F_UPGRADES), "%n>%v", &targets);
			ret += aur_info (&targets);
		}
	}

	show_results();

	/* Some cleanups */
	cleanup(!ret);
	return 0;
}
コード例 #6
0
int
main (int argc, char **argv)
{
  pkg_t *pkg;
  int err;

  if (argc < 2)
  {
    printf ("Usage: %s command\n"
            "\nCommands:\n"
	    "\tupdate - Update package lists\n"
	    "\tfind [package] - Print details of the specified package\n"
	    "\tinstall [package] - Install the specified package\n"
	    "\tupgrade [package] - Upgrade the specified package\n"
	    "\tlist upgrades - List the available upgrades\n"
	    "\tlist all - List all available packages\n"
	    "\tlist installed - List all the installed packages\n"
	    "\tremove [package] - Remove the specified package\n"
	    "\trping - Reposiroties ping, check the accessibility of repositories\n"
	    "\ttest - Run test script\n"
    , basename (argv[0]));
    exit (0);
  }

  setenv("OFFLINE_ROOT", "/tmp", 0);

  if (opkg_new ()) {
	  printf("opkg_new() failed. This sucks.\n");
	  print_error_list();
	  return 1;
  }

  switch (argv[1][0])
  {
    case 'f':
      pkg = opkg_find_package (argv[2], NULL, NULL, NULL);
      if (pkg)
      {
	print_package (pkg);
      }
      else
	printf ("Package \"%s\" not found!\n", find_pkg->name);
      break;
    case 'i':
      err = opkg_install_package (argv[2], progress_callback, "Installing...");
      printf ("\nopkg_install_package returned %d\n", err);
      break;

    case 'u':
      if (argv[1][2] == 'd')
      {
        err = opkg_update_package_lists (progress_callback, "Updating...");
        printf ("\nopkg_update_package_lists returned %d\n", err);
        break;
      }
      else
      {
        if (argc < 3)
        {
          err = opkg_upgrade_all (progress_callback, "Upgrading all...");
          printf ("\nopkg_upgrade_all returned %d\n", err);
        }
        else
        {
          err = opkg_upgrade_package (argv[2], progress_callback, "Upgrading...");
          printf ("\nopkg_upgrade_package returned %d\n", err);
        }
      }
      break;

    case 'l':
      if (argc < 3)
      {
        printf ("Please specify one either all, installed or upgrades\n");
      }
      else
      {
        switch (argv[2][0])
        {
          case 'u':
            printf ("Listing upgradable packages...\n");
            opkg_list_upgradable_packages (package_list_upgradable_callback, NULL);
            break;
          case 'a':
            printf ("Listing all packages...\n");
            opkg_list_packages (package_list_callback, NULL);
            printf ("\n");
            break;
          case 'i':
            printf ("Listing installed packages...\n");
            opkg_list_packages (package_list_installed_callback, NULL);
            break;
          default:
            printf ("Unknown list option \"%s\"\n", argv[2]);
        }
      }
      break;

    case 'r':
      if (argv[1][1] == 'e')
      {
      	err = opkg_remove_package (argv[2], progress_callback, "Removing...");
      	printf ("\nopkg_remove_package returned %d\n", err);
	break;
      }else if (argv[1][1] == 'p')
      {
        err = opkg_repository_accessibility_check();
	printf("\nopkg_repository_accessibility_check returned (%d)\n", err);
        break;
      }

    default:
      printf ("Unknown command \"%s\"\n", argv[1]);
  }


  opkg_free ();

  return 0;
}