You are not logged in.
Hey guys,
I only know the basics of distutils in python and I'm not sure how to solve this little problem. Basically, I want to install some configuration files to /usr/share/pallavi and then when the application is running, I will want to copy these 'skeleton' files into $HOME/.pallavi.
The thing is, I can imagine some users may want to install to someplace other than /usr/share. I'm not sure if or how distutils supports this, but assuming it does, it means I don't really want to hard-code the path (/usr/share/pallavi) into my application when I copy the files to $HOME. How can I find out where the user actually installed the files from within the application?
Or is this basically a throwback to all the C compilng I've been doing lately where you have to run ./configure to find out where stuff is installed. Is it safe to assume that if I want to install to /usr/share, then the files are stored there? I'm not even sure if I am working with a legitimate concern here. ;-)
Dusty
Offline
I have seen apps with a siteconfig.py in their base python lib dir. Trac does this.
Take a look at the trac setup.py, and see how they generate their siteconfig.
"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍
Offline
You could always just check for the file in common paths. For example, I have..
setup.py with distutils
data_files=[('share/pixmaps', ['mirage.png'])]
and in mirage.py
iconname = 'mirage.png'
if os.path.exists(iconname):
icon_path = iconname
elif os.path.exists('../share/pixmaps/' + iconname):
icon_path = '../share/pixmaps/' + iconname
elif os.path.exists('/usr/local/share/pixmaps/' + iconname):
icon_path = '/usr/local/share/pixmaps/' + iconname
elif os.path.exists('/usr/share/pixmaps/' + iconname):
icon_path = '/usr/share/pixmaps/' + iconname
Not the cleanest, I know, but it gets the job done.
I am a gated community.
Offline
I love how I learn something new with python every day. But sometimes it doesn't make sense... what is this code doing?:
path = self.prefix or self.home
I like the siteconfig.py idea, but I don't feel like going to the trouble of setting it up right now (sure its about five minutes max, but I don't even have that). I think I'll go with a hardcoded path for now, maybe checking in a couple of places like stone_crest suggests. I really want to push this release out even though its mostly broken. I haven't had the time to work on my project lately and its getting me down. ;-)
Dusty
Offline
That code is setting the path variable to self.prefix.
If self.prefix is not set, it sets it to self.home.
Think of it like a ternary operator..kinduv..
cactus psuedocode..
path = (isset(path.prefix)) ? self.prefix : self.home
at least..I *think* that is what it is doing. lol
"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍
Offline
That was my guess, so I tried it and its odd...
>>> x = 3
>>> y = 4
>>> z = x or y
>>> z
3
>>> z = m or x
Traceback (most recent call last):
File "<stdin>", line 1, in ?
NameError: name 'm' is not defined
>>>
So then I thought a bit and I decided that it is testing for None, not for whether the variable is set:
>>> x = 3
>>> y = None
>>> z = y or x
>>> z
3
So now we know
Dusty
Offline
yeah. it isn't *real* ternary operation, because certain values of y (in your example) cause the operation to fail that test for y. As in, when y = None or when y = False
If you set y to false, and wanted z to be false, the z = y or x would always set z to x, because the value of y is false.
I read somewhere that python is working on a real ternary syntax for 2.5 or 2.6, but I don't know for sure..or remember where I read it..
"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍
Offline
I read somewhere that python is working on a real ternary syntax for 2.5 or 2.6, but I don't know for sure..or remember where I read it..
I thought Guido hated ternary operators.... I'd sure like to see one though. I don't use one much, but it sure is nice to reduce a five line if statement to one line...
Dusty
Offline
cactus wrote:I read somewhere that python is working on a real ternary syntax for 2.5 or 2.6, but I don't know for sure..or remember where I read it..
I thought Guido hated ternary operators.... I'd sure like to see one though. I don't use one much, but it sure is nice to reduce a five line if statement to one line...
http://docs.python.org/dev/whatsnew/pep-308.html
x = (value if bool else otherValue)
Running Folding@Home for Team 11108 - My Stats
Offline
its pretty :-)
Offline
I read somewhere that python is working on a real ternary syntax for 2.5 or 2.6, but I don't know for sure..or remember where I read it..
according to wikipedia, 2.5 then links to here:
http://www.python.org/dev/peps/pep-0308/
Offline