Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to chmod files within a python setup.py?

I created a python package installation with a setup.py, and i want it to copy a data file in the folder (created for the occasion) ~/.did. The problem is that i have to call setup.py with sudo rights, as it writes in /usr/local/... So when my data file is copied in ~/.did, only the root user has write access to the file.

I decided then to add a call to os.chmod() after the setup() function, but i'd like to know if anyone had a more clean way to do so.

Here is my setup.py file :

#!/usr/bin/env python

from distutils.core import setup
import os

home=os.path.expanduser('~')

setup(name='did',
      version='1.0',
      description='Daily Image Downloader',
      author='Luc Mazon',
      author_email='[email protected]',
      url='',
      license='GNU GPL v3',
      scripts=['did'],
      packages=['didlib'],
      data_files=[
                  ('/usr/share/man/man1', ['doc/did.1.gz']),
                  (home+'/.did', ['did.xml'])
                 ]
     )

os.chmod(home+'/.did/did.xml', 0666)

As did.xml is not a python file, i also created a MANIFEST.in file with the following line in it :

include did.xml

The global structure of my package is the following :

did-1.0
 | didlib
 |  | __init__.py
 |  | variouspyfiles.py
 | doc
 |  |-did.1.gz
 | MANIFEST.in
 | did.xml
 | did
 | setup.py
like image 678
kluck Avatar asked Nov 28 '25 00:11

kluck


1 Answers

I think it would be better, and more customary, to not write to the installer's home directory any config files at all. What about other users? Better would be to have your code check, on initialization, if that file exists for the user running it and only add a new one if it does not.

like image 95
Keith Avatar answered Nov 29 '25 14:11

Keith