You are not logged in.

#1 2006-07-13 19:44:06

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

knowing where it goes -- distutils

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

#2 2006-07-13 20:42:31

cactus
Taco Eater
From: t͈̫̹ͨa͖͕͎̱͈ͨ͆ć̥̖̝o̫̫̼s͈̭̱̞͍̃!̰
Registered: 2004-05-25
Posts: 4,622
Website

Re: knowing where it goes -- distutils

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.

http://trac.edgewall.org/browser/trunk/setup.py


"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

#3 2006-07-15 16:20:47

stonecrest
Member
From: Boulder
Registered: 2005-01-22
Posts: 1,190

Re: knowing where it goes -- distutils

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

#4 2006-07-15 17:22:45

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: knowing where it goes -- distutils

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

#5 2006-07-15 18:27:23

cactus
Taco Eater
From: t͈̫̹ͨa͖͕͎̱͈ͨ͆ć̥̖̝o̫̫̼s͈̭̱̞͍̃!̰
Registered: 2004-05-25
Posts: 4,622
Website

Re: knowing where it goes -- distutils

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

#6 2006-07-15 21:33:40

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: knowing where it goes -- distutils

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 smile

Dusty

Offline

#7 2006-07-15 23:47:03

cactus
Taco Eater
From: t͈̫̹ͨa͖͕͎̱͈ͨ͆ć̥̖̝o̫̫̼s͈̭̱̞͍̃!̰
Registered: 2004-05-25
Posts: 4,622
Website

Re: knowing where it goes -- distutils

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

#8 2006-07-16 02:21:52

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: knowing where it goes -- distutils

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...

Dusty

Offline

#9 2006-07-16 03:33:48

smartcat99s
Member
Registered: 2006-03-17
Posts: 44

Re: knowing where it goes -- distutils

Dusty wrote:
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

#10 2006-07-16 16:49:54

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Offline

#11 2006-07-16 21:53:26

T-Dawg
Forum Fellow
From: Charlotte, NC
Registered: 2005-01-29
Posts: 2,736

Re: knowing where it goes -- distutils

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..

according to wikipedia, 2.5 then links to here:
http://www.python.org/dev/peps/pep-0308/

Offline

Board footer

Powered by FluxBB