假设我们有一个名为foo的程序。
如果使用绝对路径:
setup(...,
data_files=[...,
('/etc', ['foo.cfg'])]
)然后foo$ python setup.py --prefix=/usr/local和我们将拥有/etc/foo.cfg。但根据FHS的说法,我们应该使用/usr/local/etc/foo.cfg。
如果我们使用相对路径呢?
setup(...,
data_files=[...,
('etc', ['foo.cfg'])]
)然后,如果我们使用默认的安装路径,即安装到/usr,我们将拥有/usr/etc/foo.cfg。又不走运了。
那么如何才能做到这一点呢?
为了避免使问题更加复杂,我们假设这个程序foo不能在非unix环境下运行。
发布于 2013-07-01 20:07:26
子类化distutils.command.install.install并不是绝对必要的。相反,可以将data_files传递给setup,如'Installing Additional Files'上的distutils文档所示。
例如:
setup(
...
data_files = [
(conf_path, ['foo.cfg'])
]
)其中conf_path是根据您自己的需求计算的。例如,通过测试sys.prefix (而不是self.prefix)来构建它,就像上面的@weakish所做的那样。
发布于 2010-07-27 01:17:31
似乎没有简单的方法。问题是配置文件是特殊的数据文件,需要特殊处理。
因此,编写我们自己的类:
class myinstall(distutils.command.install.install):
if self.prefix == '/usr':
self.conf_prefix = '/etc'
else:
self.conf_prefix = self.prefix + '/etc'
install.finalize_options(self)
def install_conf(self):
self.mkpath((self.root or '') + self.conf_prefix)
for file in self.distribution.conf_files:
dest = (self.root or '') + self.conf_prefix + '/' +
os.path.basename(file)
self.copy_file(file, dest)
# blah blah blah然后:
setup(# blah blah blah
conf_files = ['foo.cfg']
cmdclass = {'install': myinstall,
# blah blah blah
}
)https://stackoverflow.com/questions/3325606
复制相似问题