[Python-checkins] CVS: distutils/misc archive.h,1.4,1.5 extract.c,1.5,1.6 install.c,1.11,1.12 wininst.exe,1.9,1.10

Thomas Heller theller@users.sourceforge.net
Wed, 05 Sep 2001 05:55:56 -0700


Update of /cvsroot/python/distutils/misc
In directory usw-pr-cvs1:/tmp/cvs-serv13479

Modified Files:
	archive.h extract.c install.c wininst.exe 
Log Message:
Implement PEP250 for bdist_wininst: Use Lib/site-packages under windows
(but only for version 2.2 and up).
The scheme has to be determined at runtime.


Index: archive.h
===================================================================
RCS file: /cvsroot/python/distutils/misc/archive.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** archive.h	2001/02/19 09:19:07	1.4
--- archive.h	2001/09/05 12:55:53	1.5
***************
*** 59,68 ****
  #pragma pack()
  
  typedef int (*NOTIFYPROC)(int code, LPSTR text, ...);
  
  extern BOOL extract_file (char *dst, char *src, int method, int comp_size,
  			  int uncomp_size, NOTIFYPROC notify);
! extern BOOL unzip_archive (char *dirname, char *data, DWORD size,
! 			   NOTIFYPROC callback);
  extern char *map_new_file (DWORD flags, char *filename, char
  			   *pathname_part, int size,
--- 59,75 ----
  #pragma pack()
  
+ /* installation scheme */
+ 
+ typedef struct tagSCHEME {
+     char *name;
+     char *prefix;
+ } SCHEME;
+ 
  typedef int (*NOTIFYPROC)(int code, LPSTR text, ...);
  
  extern BOOL extract_file (char *dst, char *src, int method, int comp_size,
  			  int uncomp_size, NOTIFYPROC notify);
! extern BOOL unzip_archive (SCHEME *scheme, char *dirname, char *data,
! 			   DWORD size,  NOTIFYPROC notify);
  extern char *map_new_file (DWORD flags, char *filename, char
  			   *pathname_part, int size,
***************
*** 79,80 ****
--- 86,88 ----
  #define NUM_FILES 6
  #define FILE_OVERWRITTEN 7
+ 

Index: extract.c
===================================================================
RCS file: /cvsroot/python/distutils/misc/extract.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** extract.c	2001/02/19 09:19:07	1.5
--- extract.c	2001/09/05 12:55:53	1.6
***************
*** 10,14 ****
  
  /* Convert unix-path to dos-path */
! static void fixpath (char *path)
  {
      while (path && *path) {
--- 10,14 ----
  
  /* Convert unix-path to dos-path */
! static void normpath (char *path)
  {
      while (path && *path) {
***************
*** 186,190 ****
   */
  BOOL
! unzip_archive (char *dirname, char *data, DWORD size, NOTIFYPROC notify)
  {
      int n;
--- 186,191 ----
   */
  BOOL
! unzip_archive (SCHEME *scheme, char *dirname, char *data, DWORD size,
! 	       NOTIFYPROC notify)
  {
      int n;
***************
*** 208,211 ****
--- 209,213 ----
      /* Loop through the central directory, reading all entries */
      for (n = 0; n < pe->nTotalCDir; ++n) {
+ 	int i;
  	char *fname;
  	char *pcomp;
***************
*** 230,238 ****
  		     + pfhdr->extra_length];
  
  	strcpy (pathname, dirname);
! 	strcat (pathname, "\\");
  	new_part = &pathname[lstrlen (pathname)];
  	strncat (pathname, fname, pfhdr->fname_length);
! 	fixpath (pathname);
  	if (pathname[strlen(pathname)-1] != '\\') {
  	    /*
--- 232,276 ----
  		     + pfhdr->extra_length];
  
+ 	/* dirname is the Python home directory (prefix) */
  	strcpy (pathname, dirname);
! 	if (pathname[strlen(pathname)-1] != '\\')
! 	    strcat (pathname, "\\");
  	new_part = &pathname[lstrlen (pathname)];
+ 	/* we must now match the first part of the pathname
+ 	 * in the archive to a component in the installation
+ 	 * scheme (PURELIB, PLATLIB, HEADERS, SCRIPTS, or DATA)
+ 	 * and replace this part by the one in the scheme to use
+ 	 */
+ 	for (i = 0; *scheme[i].name; ++i) {
+ 	    if (0 == strnicmp(scheme[i].name, fname, strlen(scheme[i].name))) {
+ 		char *rest;
+ 		int len;
+ 		int namelen = strlen(scheme[i].name); /* length of the replaced part */
+ 
+ 		strcat(pathname, scheme[i].prefix);
+ 
+ 		rest = fname + namelen;
+ 		len = pfhdr->fname_length - namelen;
+ 
+ 		if ((pathname[strlen(pathname)-1] != '\\')
+ 		    && (pathname[strlen(pathname)-1] != '/'))
+ 		    strcat(pathname, "\\");
+ 		/* Now that pathname ends with a separator,
+ 		 * we must make sure rest does not start with
+ 		 * an additional one.
+ 		 */
+ 		if ((rest[0] == '\\') || (rest[0] == '/')) {
+ 		    ++rest;
+ 		    --len;
+ 		}
+ 
+ 		strncat(pathname, rest, len);
+ 		goto Done;
+ 	    }
+ 	}
+ 	/* no prefix to replace found, go unchanged */
  	strncat (pathname, fname, pfhdr->fname_length);
!       Done:
! 	normpath (pathname);
  	if (pathname[strlen(pathname)-1] != '\\') {
  	    /*

Index: install.c
===================================================================
RCS file: /cvsroot/python/distutils/misc/install.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** install.c	2001/04/09 18:03:11	1.11
--- install.c	2001/09/05 12:55:53	1.12
***************
*** 865,868 ****
--- 865,887 ----
  }
  
+ /* Note: If scheme.prefix is nonempty, it must end with a '\'! */
+ SCHEME old_scheme[] = {
+     { "PURELIB", "" },
+     { "PLATLIB", "" },
+     { "HEADERS", "" }, /* 'Include/dist_name' part already in archive */
+     { "SCRIPTS", "Scripts\\" },
+     { "DATA", "" },
+     { NULL, NULL },
+ };
+ 
+ SCHEME new_scheme[] = {
+     { "PURELIB", "Lib\\site-packages\\" },
+     { "PLATLIB", "Lib\\site-packages\\" },
+     { "HEADERS", "" }, /* 'Include/dist_name' part already in archive */
+     { "SCRIPTS", "Scripts\\" },
+     { "DATA", "" },
+     { NULL, NULL },
+ };
+ 
  BOOL CALLBACK
  InstallFilesDlgProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
***************
*** 870,873 ****
--- 889,893 ----
      LPNMHDR lpnm;
      char Buffer[4096];
+     SCHEME *scheme;
  
      switch (msg) {
***************
*** 922,930 ****
  	    OpenLogfile(install_dir);
  
  
  	    /* Extract all files from the archive */
  	    SetDlgItemText (hwnd, IDC_TITLE, "Installing files...");
! 	    success = unzip_archive (install_dir, arc_data,
! 				    arc_size, notify);
  	    /* Compile the py-files */
  	    if (pyc_compile) {
--- 942,975 ----
  	    OpenLogfile(install_dir);
  
+ /*
+  * The scheme we have to use depends on the Python version...
+ if sys.version < "2.2":
+     WINDOWS_SCHEME = {
+         'purelib': '$base',
+         'platlib': '$base',
+         'headers': '$base/Include/$dist_name',
+         'scripts': '$base/Scripts',
+         'data'   : '$base',
+     }
+ else:
+     WINDOWS_SCHEME = {
+         'purelib': '$base/Lib/site-packages',
+         'platlib': '$base/Lib/site-packages',
+         'headers': '$base/Include/$dist_name',
+         'scripts': '$base/Scripts',
+         'data'   : '$base',
+     }
+ */
+ 	    scheme = old_scheme;
+ 	    if (py_major > 2)
+ 		scheme = new_scheme;
+ 	    else if((py_major == 2) && (py_minor >= 2))
+ 		scheme = new_scheme;
  
  	    /* Extract all files from the archive */
  	    SetDlgItemText (hwnd, IDC_TITLE, "Installing files...");
! 	    success = unzip_archive (scheme,
! 				     install_dir, arc_data,
! 				     arc_size, notify);
  	    /* Compile the py-files */
  	    if (pyc_compile) {

Index: wininst.exe
===================================================================
RCS file: /cvsroot/python/distutils/misc/wininst.exe,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
Binary files /tmp/cvsPhHaDh and /tmp/cvs07uEOo differ