[python-win32] Creating an installer for a COM server.

Robin Becker robin@reportlab.com
Mon, 28 Oct 2002 17:57:59 +0000


ReportLab is shipping and exe demo that controls exactly the bits that you are concerned about.


So far as I can tell we are using the following registry keys

Root: HKCU; Subkey: "Software\ReportLab\Demo"; Flags: uninsdeletekey
Root: HKCU; Subkey: "Software\ReportLab\Demo"; ValueType: string; ValueName: "InstallPath"; ValueData: "{app}"
Root: HKCU; Subkey: "Software\ReportLab\Demo"; ValueType: string; ValueName: "Version"; ValueData: "1.16"
Root: HKLM; Subkey: "Software\ReportLab\Demo"; Flags: uninsdeletekey
Root: HKLM; Subkey: "Software\ReportLab\Demo"; ValueType: string; ValueName: "InstallPath"; ValueData: "{app}"
Root: HKLM; Subkey: "Software\ReportLab\Demo"; ValueType: string; ValueName: "Version"; ValueData: "1.16"


and we have a modified python.c that controls the startup fairly rigorously.

It looks at the registry installpath and then the  python.exe location to establish a HOMEPATH
then it searches for  and dynamically loads the pythonx.x dll it finds underneath
HOMEPATH\DLLs.

During the startup to eliminate leakage we're doing things like

        pypath = (char*)malloc(strlen(homepath)+13);
        strcpy(pypath,"PYTHONHOME=");
        strcpy(pypath+11,homepath);
        i = strlen(pypath)-1;
        if(pypath[i]=='\\' || pypath[i]=='/') pypath[i]=0;
        VS1("Set %s\n",pypath);
        _putenv( pypath );
        free(pypath);
        VS("Setting Python vars\n");
        orgNoSiteFlag = *Py_NoSiteFlag;
        *Py_NoSiteFlag = 1;
        Py_SetProgramName(argv[0]);
        VS("Initializing Python\n");    
        Py_Initialize();
        Py_GetPath();
        _putenv( "PYTHONPATH=");        
        VS("Importing module sys\n");
        PyRun_SimpleStringFlags("import sys;sys.path=filter(lambda x: not x or x.find(sys.exec_prefix)==0, sys.path)",
&cf);
        VS("Installing import hooks\n");
        pypath = malloc(strlen(_rl_startup)+strlen(homepath)+100);
        sprintf(pypath,_rl_startup,homepath);
        if(PyRun_SimpleStringFlags(pypath, &cf)){
                FATALERROR("Cannot start up importing.\n");
                return -1;
                }
        free(pypath);
        if(!orgNoSiteFlag){
                VS("Importing module site\n");
                *Py_NoSiteFlag = 0;
                PyRun_SimpleStringFlags("import site;" _RL_RESTORE_PYZ, &cf);
                }

        if (*Py_VerboseFlag ||
            (command == NULL && filename == NULL && stdin_is_interactive))
                fprintf(stderr, "Python %s on %s\n%s\n",
                        Py_GetVersion(), Py_GetPlatform(), COPYRIGHT);



I know we have used this framework OK with a simple Excel+COM framework 
(ie not all of Pythonwin was in the demo) so I think the above is sufficient
to make stuff work with COM.

Anyhow Gordon's latest stuff makes pretty good COM servers so is there a special
reason to not use his approach?
-- 
Robin Becker