OSDN Git Service

Implement --download-only and --print-uris options.
authorKeith Marshall <keithmarshall@users.sourceforge.net>
Sun, 7 Aug 2011 05:37:48 +0000 (05:37 +0000)
committerKeith Marshall <keithmarshall@users.sourceforge.net>
Sun, 7 Aug 2011 05:37:48 +0000 (05:37 +0000)
ChangeLog
src/clistub.c
src/pkgbase.h
src/pkgexec.cpp
src/pkginet.cpp
src/pkgopts.h

index 940b1d9..9faf167 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2011-08-07  Keith Marshall  <keithmarshall@users.sourceforge.net>
+
+       Implement --download-only and --print-uris options.
+
+       * src/pkgopts.h (OPTION_DOWNLOAD_ONLY, OPTION_PRINT_URIS):
+       New manifest constants, identifying flag bits; define them.
+       (OPTION_DNLOAD_ONLY): Likewise; an alias for OPTION_DOWNLOAD_ONLY.
+
+       * src/pkgbase.h (pkgActionItem::PrintURI): New private method.
+       * src/pkginet.cpp: Implement it.
+
+       * src/clistub.c (options): Add "download-only" and "print-uris".
+       (help_text): Document them.
+       * src/pkgexec.cpp (pkgActionItem::Execute): Process them.
+
 2011-07-29  Keith Marshall  <keithmarshall@users.sourceforge.net>
 
        mingw-get-0.3-mingw32-alpha-2.1 released.
index 3e7c62d..6b2e03e 100644 (file)
@@ -169,38 +169,55 @@ static const char *help_text =
 "  mingw-get [OPTIONS] {show | list} [package-spec ...]\n\n"
 
 "Options:\n"
-"  --help, -h      Show this help text\n"
-"  --version, -V   Show version and licence information\n"
-"  --verbose, -v   Increase verbosity of diagnostic or\n"
-"                  progress reporting output; repeat up\n"
-"                  to three times for maximum verbosity\n"
-"  --verbose=N     Set verbosity level to N; (0 <= N <= 3)\n"
+"  --help, -h        Show this help text\n"
+"\n"
+"  --version, -V     Show version and licence information\n"
+"\n"
+"  --verbose, -v     Increase verbosity of diagnostic or\n"
+"                    progress reporting output; repeat up\n"
+"                    to three times for maximum verbosity\n"
+"  --verbose=N       Set verbosity level to N; (0 <= N <= 3)\n"
+"\n"
 
 /* The "--trace" option is available only when dynamic tracing
  * debugging support is compiled in; don't advertise it otherwise.
  */
 #if DEBUG_ENABLED( DEBUG_TRACE_DYNAMIC )
-"  --trace=N       Enable tracing feature N; (debugging aid)\n"
+"  --trace=N         Enable tracing feature N; (debugging aid)\n"
+"\n"
 #endif
 
 /* The following are always available...
  */
-"  --reinstall     When performing an install or upgrade\n"
-"                  operation, reinstall any named package\n"
-"                  for which the most recent release is\n"
-"                  already installed\n"
+"  --reinstall       When performing an install or upgrade\n"
+"                    operation, reinstall any named package\n"
+"                    for which the most recent release is\n"
+"                    already installed\n"
+"\n"
+"  --download-only   Download the package archive files which\n"
+"                    would be required to complete the specified\n"
+"                    install, upgrade, or source operation, but\n"
+"                    do not unpack them, or otherwise proceed\n"
+"                    to complete the operation\n"
+"\n"
+"  --print-uris      Display the repository URIs from which\n"
+"                    package archive files would be retrieved\n"
+"                    prior to performing the specified install,\n"
+"                    upgrade, or source operation, but do not\n"
+"                    download any package file, or otherwise\n"
+"                    proceed with the operation\n"
 "\n"
 "Actions:\n"
-"  update          Update local copy of repository catalogues\n"
-"  list, show      List and show details of available packages\n"
-"  install         Install new packages\n"
-"  upgrade         Upgrade previously installed packages\n"
-"  remove          Remove previously installed packages\n\n"
+"  update            Update local copy of repository catalogues\n"
+"  list, show        List and show details of available packages\n"
+"  install           Install new packages\n"
+"  upgrade           Upgrade previously installed packages\n"
+"  remove            Remove previously installed packages\n\n"
 
 "Package Specifications:\n"
 "  [subsystem-]name[-component]:\n"
-"  msys-bash-doc   The 'doc' component of the bash package for MSYS\n"
-"  mingw32-gdb     All components of the gdb package for MinGW\n\n"
+"  msys-bash-doc     The 'doc' component of the bash package for MSYS\n"
+"  mingw32-gdb       All components of the gdb package for MinGW\n\n"
 
 "Use 'mingw-get list' to identify possible package names\n"
 "and the components associated with each.\n\n";
@@ -363,19 +380,21 @@ int main( int argc, char **argv )
     struct option options[] =
     {
       /* Option Name      Argument Category    Store To   Return Value
-       * --------------   ------------------   --------   ----------------
+       * --------------   ------------------   --------   ------------------
        */
-      { "version",        no_argument,         NULL,      'V'              },
-      { "help",           no_argument,         NULL,      'h'              },
-      { "verbose",        optional_argument,   NULL,      OPTION_VERBOSE   },
+      { "version",        no_argument,         NULL,      'V'                },
+      { "help",           no_argument,         NULL,      'h'                },
+      { "verbose",        optional_argument,   NULL,      OPTION_VERBOSE     },
 
-      { "reinstall",      no_argument,         &optref,   OPTION_REINSTALL },
+      { "reinstall",      no_argument,         &optref,   OPTION_REINSTALL   },
+      { "download-only",  no_argument,         &optref,   OPTION_DNLOAD_ONLY },
+      { "print-uris",     no_argument,         &optref,   OPTION_PRINT_URIS  },
 
 #     if DEBUG_ENABLED( DEBUG_TRACE_DYNAMIC )
        /* The "--trace" option is supported only when dynamic tracing
         * debugging support has been compiled in.
         */
-      { "trace",          required_argument,   &optref,   OPTION_TRACE     },
+      { "trace",          required_argument,   &optref,   OPTION_TRACE       },
 #     endif
 
       /* This list must be terminated by a null definition...
index 9210732..593c458 100644 (file)
@@ -223,6 +223,10 @@ class pkgActionItem
      */
     pkgXmlNode* selection[ selection_types ];
 
+    /* Method to display the URI whence a package may be downloaded.
+     */
+    void PrintURI( const char* );
+
     /* Method for retrieving packages from a distribution server.
      */
     void DownloadArchiveFiles( pkgActionItem* );
index d3b0768..a608b22 100644 (file)
@@ -383,79 +383,110 @@ void pkgActionItem::Execute()
     pkgActionItem *current = this;
     bool init_rites_pending = true;
     while( current->prev != NULL ) current = current->prev;
-    do {
-        DownloadArchiveFiles( current );
-       } while( SetAuthorities( current ) > 0 );
-    while( current != NULL )
+
+    /* Unless normal operations have been suppressed by the
+     * --print-uris option, (in order to obtain a list of all
+     * package URIs which the operation would access)...
+     */
+    if( pkgOptions()->Test( OPTION_PRINT_URIS ) < OPTION_PRINT_URIS )
+      do {
+          /* ...we initiate any download requests which may
+           * be necessary to fetch all required archives into
+           * the local package cache.
+           */
+          DownloadArchiveFiles( current );
+        } while( SetAuthorities( current ) > 0 );
+
+    else while( current != NULL )
     {
-      /* Processing only those packages with assigned actions...
+      /* The --print-uris option is in effect: we simply loop
+       * over all packages with an assigned action, printing
+       * the associated download URI for each; (note that this
+       * will print the URI regardless of prior existence of
+       * the associated package in the local cache).
        */
-      if( (current->flags & ACTION_MASK) != 0 )
+      current->PrintURI( current->Selection()->ArchiveName() );
+      current = current->next;
+    }
+
+    /* If the --download-only option is in effect, then we have
+     * nothing more to do...
+     */
+    if( pkgOptions()->Test( OPTION_DOWNLOAD_ONLY ) == 0 )
+    {
+      /* ...otherwise...
+       */
+      while( current != NULL )
       {
-       /* Print a notification of the installation process to be
-        * performed, identifying the package to be processed.
-        */
-       const char *tarname;
-       if( (tarname = current->Selection()->GetPropVal( tarname_key, NULL )) == NULL )
-         tarname = current->Selection( to_remove )->GetPropVal( tarname_key, value_unknown );
-       dmh_printf( "%s: %s\n", action_name(current->flags & ACTION_MASK), tarname );
-
-       /* Check for any outstanding requirement to invoke the
-        * "self upgrade rites" process, so that we may install an
-        * upgrade for mingw-get itself...
+       /* ...processing only those packages with assigned actions...
         */
-       if( init_rites_pending )
-         /*
-          * ...discontinuing the check once this has been completed,
-          * since it need not be performed more than once.
+       if( (current->flags & ACTION_MASK) != 0 )
+       {
+         /* ...print a notification of the installation process to
+          * be performed, identifying the package to be processed.
+          */
+         const char *tarname;
+         if( (tarname = current->Selection()->GetPropVal( tarname_key, NULL )) == NULL )
+           tarname = current->Selection( to_remove )->GetPropVal( tarname_key, value_unknown );
+         dmh_printf( "%s: %s\n", action_name(current->flags & ACTION_MASK), tarname );
+
+         /* Check for any outstanding requirement to invoke the
+          * "self upgrade rites" process, so that we may install an
+          * upgrade for mingw-get itself...
           */
-         init_rites_pending = self_upgrade_rites( tarname );
+         if( init_rites_pending )
+           /*
+            * ...discontinuing the check once this has been completed,
+            * since it need not be performed more than once.
+            */
+           init_rites_pending = self_upgrade_rites( tarname );
 
-       /* If we are performing an upgrade...
-        */
-       if( ((current->flags & ACTION_MASK) == ACTION_UPGRADE)
-       /*
-        * ...and the latest version of the package is already installed...
-        */
-       &&  (current->Selection() == current->Selection( to_remove ))
-       /*
-        * ...and the `--reinstall' option hasn't been specified...
-        */
-       &&  (pkgOptions()->Test( OPTION_REINSTALL ) == 0)  )
+         /* If we are performing an upgrade...
+          */
+         if( ((current->flags & ACTION_MASK) == ACTION_UPGRADE)
          /*
-          * ...then simply report the up-to-date status...
+          * ...and the latest version of the package is already installed...
           */
-         dmh_notify( DMH_INFO, "package %s is up to date\n", tarname );
-
-       else
-       { /* ...otherwise, proceed to perform remove and install
-          * operations, as appropriate.
+         &&  (current->Selection() == current->Selection( to_remove ))
+         /*
+          * ...and the `--reinstall' option hasn't been specified...
           */
-         if( (current->flags & ACTION_REMOVE) == ACTION_REMOVE )
-         {
-           /* The selected package has been marked for removal,
-            * either explicitly, or as an implicit prerequisite for upgrade.
+         &&  (pkgOptions()->Test( OPTION_REINSTALL ) == 0)  )
+           /*
+            * ...then simply report the up-to-date status...
             */
-           pkgRemove( current );
-         }
+           dmh_notify( DMH_INFO, "package %s is up to date\n", tarname );
 
-         if( (current->flags & ACTION_INSTALL) == ACTION_INSTALL )
-         {
-           /* The selected package has been marked for installation,
-            * either explicitly, or implicitly to complete a package upgrade.
+         else
+         { /* ...otherwise, proceed to perform remove and install
+            * operations, as appropriate.
             */
-           pkgXmlNode *tmp = current->Selection( to_remove );
-           if(   pkgOptions()->Test( OPTION_REINSTALL )
-           ||  ((current->flags & ACTION_MASK) == ACTION_UPGRADE)  )
-             current->selection[ to_remove ] = NULL;
-           pkgInstall( current );
-           current->selection[ to_remove ] = tmp;
+           if( (current->flags & ACTION_REMOVE) == ACTION_REMOVE )
+           {
+             /* The selected package has been marked for removal,
+              * either explicitly, or as an implicit prerequisite for upgrade.
+              */
+             pkgRemove( current );
+           }
+
+           if( (current->flags & ACTION_INSTALL) == ACTION_INSTALL )
+           {
+             /* The selected package has been marked for installation,
+              * either explicitly, or implicitly to complete a package upgrade.
+              */
+             pkgXmlNode *tmp = current->Selection( to_remove );
+             if(   pkgOptions()->Test( OPTION_REINSTALL )
+             ||  ((current->flags & ACTION_MASK) == ACTION_UPGRADE)  )
+               current->selection[ to_remove ] = NULL;
+             pkgInstall( current );
+             current->selection[ to_remove ] = tmp;
+           }
          }
        }
+       /* Proceed to the next package, if any, with scheduled actions.
+        */
+       current = current->next;
       }
-      /* Proceed to the next package, if any, with scheduled actions.
-       */
-      current = current->next;
     }
   }
 }
index 02455ec..7d5228c 100644 (file)
@@ -635,6 +635,37 @@ int pkgInternetStreamingAgent::Get( const char *from_url )
   return dl_status;
 }
 
+void pkgActionItem::PrintURI( const char *package_name )
+{
+  /* Private method to display the URI from which a package archive
+   * may be downloaded; called with "package_name" assigned by either
+   * ArchiveName() or SourceArchiveName() as appropriate, and...
+   */
+  if( ! match_if_explicit( package_name, value_none ) )
+  {
+    /* ...applicable only to real (i.e. not meta) packages.
+     *
+     * We begin by retrieving the URI template associated with
+     * the specified package...
+     */
+    const char *url_template = get_host_info( Selection(), uri_key );
+    if( url_template != NULL )
+    {
+      /* ...then filling in the package name and preferred mirror
+       * assignment, as if preparing to initiate a download...
+       */
+      const char *mirror = get_host_info( Selection(), mirror_key );
+      char package_url[mkpath( NULL, url_template, package_name, mirror )];
+      mkpath( package_url, url_template, package_name, mirror );
+
+      /* ...then, rather than actually initiate the download,
+       * we simply write out the generated URI to stdout.
+       */
+      printf( "%s\n", package_url );
+    }
+  }
+}
+
 void pkgActionItem::DownloadArchiveFiles( pkgActionItem *current )
 {
   /* Update the local package cache, to ensure that all packages needed
index 017e81d..9fa45ea 100644 (file)
@@ -85,6 +85,9 @@ struct pkgopts
 #define OPTION_VERBOSE_MAX     (0x00000003)
 
 #define OPTION_REINSTALL       (0x00000010)
+#define OPTION_DNLOAD_ONLY     (0x00000020)
+#define OPTION_DOWNLOAD_ONLY   (0x00000020)
+#define OPTION_PRINT_URIS      (0x00000060)
 
 #if __cplusplus
 /*