[kforge-dev] windows problem creating database

Rufus Pollock rufus.pollock at okfn.org
Mon Aug 14 20:27:12 UTC 2006


Nikolas Bowe wrote:
> Hi again.
>  
>  
> Sorry if this isnt threaded properly; Im on a different machine.
>  
> Id *like* to run this on linux.
> But my work doesnt have anyone else who is comfortable in it.
> So Im actually converting our current source control from a linux 
> machine that I maintain to windows.
> And while I was at it I thought kforge looked like a simple interface to 
> managing the projects.
>  
>  
> Creating the db by hand works
>   C:\django\kforge>createdb -h localhost -U kforge kforge
>   Password:
>   CREATE DATABASE
>  
> but initing it prints an error.
>   C:\django\kforge>python \Python24\Scripts\kforge-admin db init
>   Command failed. Details: 'Permission' object has no attribute 
> 'protectionObject'
>
> some records go in but it is very sparse. i attached the dump from pg_dump
> really not sure on this one. any ideas?

Error msg isn't as informative as it might be is it (we should probably 
improve command error messages to contain line number and original 
exception or at least write that to the log file)! I assume you are 
using kforge-0.11 in which case the db initialiase code is:

<http://project.knowledgeforge.net/kforge/svn/tags/kforge-0.11/src/kforge/command/initialise.py>

Looking at your db dump it seems it seems that the last thing that work 
was createStates suggesting the problem is in createRoles. Why not try 
putting some debug code in there and seeing what happens to narrow the 
problem down.

>  
>   C:\django\kforge>python \Python24\Scripts\kforge-admin www build
> works fine (no output)
> but in the generated httpd.conf it has this line a lot
>             SetEnv PYTHONPATH
> is that meant to point to python path or is it correct as it is?

It is correct as is as long as you've installed kforge site-wide. 
Leaving it blank is just the equivalent of having an empty python path 
and I don't think it causes any problem.

> On windows python doesnt set the PYTHONPATH environment variable. rather 
> (annoyingly) it keeps it in the registry.
> On my setup it is "C:\Python24\Lib;C:\Python24\DLLs;C:\Python24\Lib\lib-tk"
> I just added it to my system environment variables manually. then 
> rebuilt the httpd.conf. looks ok.
> could probably do with a mention in the INSTALL file.

Thanks for the windows info. As I said if you install site-wide this 
isn't an issue but if you are using PYTHONPATH (or equivalent) then 
obviousl it is.

> Apparently under mac os x this variable is also not set by default. so a 
> mention is probably a good idea. I dont have OS X though so I cant 
> confirm this.

I'm on mac osx and there's no problem.

>  
> Regarding the \ escape problem
> It can happen on other platforms even though they use different 
> seperators because they use the \ to escape strange characters.
> For example:
> I have a folder called "my/files". If a person wants the slash to be 
> treated as part of the folder name then they escape it with \
> "/usr/share/my\/files"
> most languages (im not sure on python.) will output this as 
> "/usr/share/my/files", thus treating "files" as a subdir of "my".
> sure its an unlikely name. but it can happen :)

Good point. Obviously solution is just to patch the 'hacky' code that 
does variable substitution when generating the config files (if only 
python ConfigParser supporting reading and rewriting config files in a 
respectful way ...)

>  
> It turns out that the commands module is unix specific.
> http://docs.python.org/lib/unix.html
> I searched the .py files for these modules and commands is the only one 
> used.

Hmmm. Thanks for letting us know.

> the following files all use commands.getstatusoutput (i only check .py 
> files. there may be more)
> Find all "commands.getstatusoutput", Find Results 1, All Open Documents
> C:\django\kforge-0.11\src\kforge\apache\apacheconfig.py(53):            
> errorStatus, output = commands.getstatusoutput(cmd)
> C:\django\kforge-0.11\src\kforge\test\kforge-admin_script_test.py(19):        
> status, output = commands.getstatusoutput(cmd)
> C:\django\kforge-0.11\src\kforge\test\install_test.py(31):        
> status, output = commands.getstatusoutput(cmd)
> C:\django\kforge-0.11\src\kforge\utils\db.py(40):        status, output 
> = commands.getstatusoutput(cmd)
> C:\django\kforge-0.11\build\lib\kforge\apache\apacheconfig.py(53):            
> errorStatus, output = commands.getstatusoutput(cmd)
> C:\django\kforge-0.11\build\lib\kforge\test\kforge-admin_script_test.py(19):        
> status, output = commands.getstatusoutput(cmd)
> C:\django\kforge-0.11\build\lib\kforge\test\install_test.py(31):        
> status, output = commands.getstatusoutput(cmd)
> C:\django\kforge-0.11\build\lib\kforge\utils\db.py(40):        status, 
> output = commands.getstatusoutput(cmd)
> C:\django\kforge-0.11\src\kforge\plugin\trac\command.py(66):        
> status, output = commands.getstatusoutput(cmd)
> C:\django\kforge-0.11\build\lib\kforge\plugin\trac\command.py(66):        
> status, output = commands.getstatusoutput(cmd)
> Total found: 10    Matching files: 367    Total files searched: 428
>  
> rather than alter all those files I added a short snippet to detect the 
> problem and redirect the function.
> but eventually Id recommend kforge using its own getstatusoutput.
> as an interim approach I did the following

> in my C:\Python24\Lib\site-packages\kforge\__init__.py
> (before a kforge install it would be here in source 
> tree kforge-0.11/src/kforge/core/ioc)
> I added the following to the end
>  
> # patch(hack) to make commands.getstatusoutput work on winxp
> def mygetstatusoutput(cmd):
>     """Return (status, output) of executing cmd in a shell."""
>     import os
>     pipe = os.popen(cmd + ' 2>&1', 'r')
>     text = pipe.read()
>     sts = pipe.close()
>     if sts is None: sts = 0
>     if text[-1:] == '\n': text = text[:-1]
>     return sts, text
> import os
> if (os.name == 'nt'):
>     import commands
>     commands.getstatusoutput = mygetstatusoutput
> then it (almost) works:
>   C:\django\kforge>python \Python24\Scripts\kforge-admin db rebuild
>   Command dropdb requires 'kforge' user authentication:
>   Password:
>   Command createdb requires 'kforge' user authentication:
>   Password:
>   Command failed. Details: 'Permission' object has no attribute 
> 'protectionObject'

Nice 'hack' patch. It is sort of annoying that python doesn't do 
something 'similar' for commands.getstatusoutput already. You're welcome 
to open a ticket for this:

http://project.knowledgeforge.net/kforge/trac/newticket

>  
> Also it would be really nice if all the python scripts used .py as their 
> extension if possible. (eg kforge-admin)
> is there any reason against this?

> it would mean that windows machines (that have .py associated with 
> python) could execute kforge-admin without all th junk that I have to go 
> through at the moment

That was to follow unixy conventions whereby scripts don't have 
extension and you use #!/usr/bin/python (or whatever). I understand that 
this will cause problems on windows but I'd suggest working around by 
just doing python <script-name> (as you are doing)

> Is a valid way to get apache to reload its config files to restart apache?
> ie reload_apache = "C:\Program Files\Apache Group\Apache2\bin\apache" -k 
> restart

I think so but I haven't used apache on windows for a *long* time

> The INSTALL file doesnt mention running kforge-admin db init, it only 
> mentions create.
> Create doesnt init the db even though rebuild does
> but im not using the cvs version so its probably fixed in that.

You've caught a documentation bug.

Regards,

Rufus




More information about the kforge-dev mailing list