another distutils question
Eric S. Johansson
esj at harvee.org
Fri Sep 29 22:57:22 EDT 2006
Keith Perkins wrote:
>
> On a similar note , I have another question about distutils and data files.
> I have a little program that uses a txt file to store data, and it works
> fine running it in it's own folder, if I install through distutils, using
> sudo to get it to write to the site-packages folder (which root owns), it
> installs the data file so that it is owned by root, and not by me, so
> that the data file can't be written to (although the script can read it).
> Do I need to run a post install script, or add something to setup.py file
> to chown the file or am I doing something wrong? There doesn't seem to be
> anything on this in the docs.
1: as pointed out, site-packages is for code only :-)
2: you will need a post processing script.
here is an example of distutils abuse that may help a little bit. I
needed to collect files from a file hierarchy and one other place in the
source directory then stuff them in the right place in the production
directory. Since the pattern was unpredictable, I built a method to
accumulate data file references.
the solution is a bit more hard coded than I like but it gets the job
done for now. as I need to improve it, I'll fix it.
def expand_hierarchy(starting_point, data_files):
dir_files = os.walk(starting_point)
for (path, name, files) in dir_files:
x = os.path.basename(path)
if x != 'CVS':
clean_files = [ os.path.join(path,item) \
for item in files \
if (clean_test(item)) ]
data_files.append((cr_paths%path,clean_files))
return data_files
setup(...
data_files=expand_hierarchy("web-ui",
[(cr_paths%'etc',
['ancillary/baseline_configuration']),
],
)
to solve the file perms problem you run something after setup. how you
associate perms/ownership with a file is up to you. It might work to
use data_files to enumerate files you apply the common perms/owernship.
then special case what you need to.
hope this gives you some useful ideas.
--- eric
More information about the Python-list
mailing list