Changeset 4461


Ignore:
Timestamp:
05/30/08 17:12:24 (5 years ago)
Author:
thomas
Message:

opkg: add some command line arguments to libopkg_test

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/target/opkg/tests/libopkg_test.c

    r4458 r4461  
    22#include <stdlib.h> 
    33#include <stdio.h> 
     4#include <string.h> 
    45 
    56opkg_package_t *find_pkg = NULL; 
     
    8384} 
    8485 
    85 int 
    86 main (int argc, char **argv) 
    87 { 
    88   opkg_t *opkg; 
     86 
     87void 
     88opkg_test (opkg_t *opkg) 
     89{ 
     90  int err; 
    8991  opkg_package_t *pkg; 
    90   int err; 
    91    
    92   opkg = opkg_new (); 
    93  
    94   opkg_set_option (opkg, "offline_root", "/tmp/"); 
    95  
    96   opkg_re_read_config_files (opkg); 
    9792 
    9893  err = opkg_update_package_lists (opkg, progress_callback, "Updating..."); 
     
    133128  printf ("\nopkg_upgrade_all returned %d (%s)\n", err, errors[err]); 
    134129 
     130} 
     131 
     132int 
     133main (int argc, char **argv) 
     134{ 
     135  opkg_t *opkg; 
     136  opkg_package_t *pkg; 
     137  int err; 
     138 
     139  if (argc < 2) 
     140  { 
     141    printf ("Usage: %s command\n" 
     142            "\nCommands:\n" 
     143            "\tupdate - Update package lists\n" 
     144            "\tfind [package] - Print details of the specified package\n" 
     145            "\tinstall [package] - Install the specified package\n" 
     146            "\tupgrade [package] - Upgrade the specified package\n" 
     147            "\tlist upgrades - List the available upgrades\n" 
     148            "\tlist all - List all available packages\n" 
     149            "\tlist installed - List all the installed packages\n" 
     150            "\tremove [package] - Remove the specified package\n" 
     151            "\ttest - Run test script\n" 
     152    , basename (argv[0])); 
     153    exit (0); 
     154  } 
     155   
     156  opkg = opkg_new (); 
     157 
     158  opkg_set_option (opkg, "offline_root", "/tmp/"); 
     159 
     160  opkg_re_read_config_files (opkg); 
     161 
     162  switch (argv[1][0]) 
     163  { 
     164    case 'f': 
     165      pkg = opkg_find_package (opkg, argv[2], NULL, NULL, NULL); 
     166      if (pkg) 
     167      { 
     168        print_package (pkg); 
     169        opkg_package_free (pkg); 
     170      } 
     171      else 
     172        printf ("Package \"%s\" not found!\n", find_pkg->name); 
     173      opkg_package_free (pkg); 
     174      break; 
     175    case 'i': 
     176      err = opkg_install_package (opkg, argv[1], progress_callback, "Installing..."); 
     177      printf ("\nopkg_install_package returned %d (%s)\n", err, errors[err]); 
     178      break; 
     179 
     180    case 'u': 
     181      if (strlen (argv[1]) < 4) 
     182        printf (""); 
     183      if (argv[1][3] == 'd') 
     184      { 
     185        err = opkg_update_package_lists (opkg, progress_callback, "Updating..."); 
     186        printf ("\nopkg_update_package_lists returned %d (%s)\n", err, errors[err]); 
     187        break; 
     188      } 
     189      else 
     190      { 
     191        if (argc < 3) 
     192        { 
     193          err = opkg_upgrade_all (opkg, progress_callback, "Upgrading all..."); 
     194          printf ("\nopkg_upgrade_all returned %d (%s)\n", err, errors[err]); 
     195        } 
     196        else 
     197        { 
     198          err = opkg_upgrade_package (opkg, argv[2], progress_callback, "Upgrading..."); 
     199          printf ("\nopkg_upgrade_package returned %d (%s)\n", err, errors[err]); 
     200        } 
     201      } 
     202      break; 
     203 
     204    case 'l': 
     205      if (argc < 3) 
     206      { 
     207        printf ("Please specify one either all, installed or upgrades\n"); 
     208      } 
     209      else 
     210      { 
     211        switch (argv[2][0]) 
     212        { 
     213          case 'u': 
     214            printf ("Listing upgradable packages...\n"); 
     215            opkg_list_upgradable_packages (opkg, package_list_upgradable_callback, NULL); 
     216            break; 
     217          case 'a': 
     218            printf ("Listing all packages...\n"); 
     219            opkg_list_packages (opkg, package_list_callback, NULL); 
     220            printf ("\n"); 
     221            break; 
     222          case 'i': 
     223            printf ("Listing installed packages...\n"); 
     224            break; 
     225          default: 
     226            printf ("Unknown list option \"%s\"", argv[2]); 
     227        } 
     228      } 
     229      break; 
     230           
     231    case 'r': 
     232      err = opkg_remove_package (opkg, argv[2], progress_callback, "Removing..."); 
     233      printf ("\nopkg_remove_package returned %d (%s)\n", err, errors[err]); 
     234      break; 
     235 
     236    default: 
     237      printf ("Unknown command \"%s\"\n", argv[1]); 
     238  } 
     239 
     240 
    135241  opkg_free (opkg); 
    136242 
Note: See TracChangeset for help on using the changeset viewer.