如何在python setup.py中使用chmod文件? [英] How to chmod files within a python setup.py?

查看:96
本文介绍了如何在python setup.py中使用chmod文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用setup.py创建了一个python软件包安装,我希望它复制文件夹中的数据文件(为此创建)〜/.did.问题是我必须以sudo权限调用setup.py,因为它写在/usr/local/中.因此,当将我的数据文件复制到〜/.did中时,只有root用户具有对该文件的写访问权.

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.

然后,我决定在setup()函数之后添加对os.chmod()的调用,但是我想知道是否有人可以使用这种方法.

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.

这是我的setup.py文件:

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='my@mail.com',
      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)

由于did.xml不是python文件,所以我还创建了一个MANIFEST.in文件,其中包含以下行:

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

推荐答案

我认为将所有配置文件都写到安装程序的主目录会更好,更习惯.那其他用户呢?最好是在初始化时检查您的代码是否存在,供运行它的用户使用,如果不存在则仅添加一个新文件.

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.

这篇关于如何在python setup.py中使用chmod文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆