PDA

View Full Version : os.gentenv function is not working on windows


linuxluemmel
2009-08-11, 15:31
hello

Have a little problem with this code ....

# Check if the user allready accepted the EULA

if (os_linux):
eula_path = os.getenv("HOME") + '/EULA_blue-pill-accepted'
eula = os.path.exists(eula_path)
print 'eula was accepted for linux'

if (os_windows):
eula_path = str(os.getenv("USERPROFILE")) + '\\EULA_blue-pill-accepted'
print eula_path
eula = os.path.exists(eula_path)
print 'eula was accepted for windows'



Under linux it is working
Under windows the functions should return the path to the user
but allways returns 'NONE'

Where is the point I miss ?

Regards
Hans

CrashX
2009-08-11, 21:11
Check to see that you have an environment variable "USERPROFILE" ?

linuxluemmel
2009-08-11, 22:06
Check to see that you have an environment variable "USERPROFILE" ?

If I do in a commandshell SET the variable USERPROFILE is listet, therefore the
command should return the path to the home directory of the user.

I did insert the print statement to see the value.

It allways returns NONE

regards
hans

rwparris2
2009-08-11, 23:41
Confirmed, this only happens in XBMC. Please file a report on Trac if you must... but I'm curious why you care about messing with the user's environment instead of staying inside of the XBMC file structure?

Unless you're doing something I'm not seeing, you should be checking special://userdata/script_data (or plugin_data).

PS - the 'HOME' variable is also legal in Windows, well... XP at least, so you can maybe drop the different OS functions.

FrostBox
2009-08-12, 00:47
hi,
I have a alternative solution for windows, not very good. but is work


import os

file_txt = os.path.join( os.getcwd(), "userprofile.txt" )

command = 'echo %userprofile%>"'+ file_txt + '"'

os.system( command )

if os.path.exsist( file_txt ):
print str( file( file_txt ).read() ).strip( "\n" )
else:
print "unknown"
frost

linuxluemmel
2009-08-12, 00:59
hi,
I have a alternative solution for windows, not very good. but is work


import os

file_txt = os.path.join( os.getcwd(), "userprofile.txt" )

command = 'echo %userprofile%>"'+ file_txt + '"'

os.system( command )

if os.path.exsist( file_txt ):
print str( file( file_txt ).read() ).strip( "\n" )
else:
print "unknown"
frost

Merci beaucoup mon vieux ;-=)

Je l'essaier demain soir ....

PS : Escuse my poor french and english ;-) LOL
Jean

Zeron
2009-08-12, 01:55
PS - the 'HOME' variable is also legal in Windows, well... XP at least, so you can maybe drop the different OS functions.

Not true on XP Pro SP3 - Just checked on a fresh install and there is HOMEDRIVE and HOMEPATH but HOME is not valid.

rwparris2
2009-08-12, 04:35
Not true on XP Pro SP3 - Just checked on a fresh install and there is HOMEDRIVE and HOMEPATH but HOME is not valid.
Yeah that's what I tested as well. It works IN python; windows itself doesn't know what HOME means but python understands.

linuxluemmel
2009-08-12, 09:34
OK I created a ticket inside trac

[XBMC] #7044: os.getenv not working as expected with python / win32


If I know the function is not working with windows I place the file inside the script-directory.

Regards
Hans