openstack nova 源码分析1
这是nova源码的setup脚本,有些我加了 注释,当然很多我也不是很明白希望大家一起探讨。[*]import gettext
[*]import glob
[*]import os
[*]import subprocess
[*]import sys
[*]
[*]from setuptools import find_packages
[*]from setuptools.command.sdist import sdist
[*]
[*]# In order to run the i18n commands for compiling and
[*]# installing message catalogs, we use DistUtilsExtra.
[*]# Don't make this a hard requirement, but warn that
[*]# i18n commands won't be available if DistUtilsExtra is
[*]# not installed...
[*]try:
[*] from DistUtilsExtra.auto import setup
[*]except ImportError:
[*] from setuptools import setup
[*] print "Warning: DistUtilsExtra required to use i18n builders. "
[*] print "To build nova with support for message catalogs, you need "
[*] print "https://launchpad.net/python-distutils-extra >= 2.18"
[*]
[*]gettext.install('nova', unicode=1)
[*]
[*]from nova.utils import parse_mailmap, str_dict_replace
[*]from nova import version
[*]
[*]if os.path.isdir('.bzr'): #判断路径
[*] with open("nova/vcsversion.py", 'w') as version_file: #with as用法,用version_file来代替,可读写打开文件,
[*] vcs_cmd = subprocess.Popen(["bzr", "version-info", "--python"],
[*] stdout=subprocess.PIPE)
[*] #创建一个指针实例(打开进程文件指针)
[*] vcsversion = vcs_cmd.communicate()#其中有2个参数见下面注释
[*] """
[*] def communicate(self, input=None):
[*]
[*] 来自subProcess的Popen的解释
[*] Interact with process: Send data to stdin.Read data from
[*] stdout and stderr, until end-of-file is reached.Wait for
[*] process to terminate.The optional input argument should be a
[*] string to be sent to the child process, or None, if no data
[*] should be sent to the child.
[*]
[*] communicate() returns a tuple (stdout, stderr)."""
[*] version_file.write(vcsversion)#即时向其中写入
[*]
[*]'''''注意这个version_file
[*](This file is automatically generated by generate_version_info
[*]It uses the current working tree to determine the revision.
[*]So don't edit it. :)
[*])
[*]''''
[*]
[*]
[*]class local_sdist(sdist):
[*] """Customized sdist hook - builds the ChangeLog file from VC first"""
[*] #构建changlogFile
[*] def run(self):
[*] if os.path.isdir('.bzr'):
[*] # We're in a bzr branch
[*] env = os.environ.copy()
[*] env['BZR_PLUGIN_PATH'] = os.path.abspath('./bzrplugins')
[*] #创建一个指针实例(打开进程文件指针)
[*] log_cmd = subprocess.Popen(["bzr", "log", "--novalog"],
[*] stdout=subprocess.PIPE, env=env)
[*] #打开上面给的给的目录你会发现有个novalog文件里面有一个Init.py
[*] #而这个.py证明这是一个模块
[*] changelog = log_cmd.communicate()
[*] #下面这4行代码,求高人指点啊
[*] mailmap = parse_mailmap()
[*]
[*] with open("ChangeLog", "w") as changelog_file:
[*] changelog_file.write(str_dict_replace(changelog, mailmap))
[*] sdist.run(self)
[*]nova_cmdclass = {'sdist': local_sdist}
[*]
[*]
[*]try:
[*] from sphinx.setup_command import BuildDoc
[*]
[*] class local_BuildDoc(BuildDoc):
[*] def run(self):
[*] for builder in ['html', 'man']:
[*] self.builder = builder
[*] self.finalize_options()
[*] BuildDoc.run(self)
[*] nova_cmdclass['build_sphinx'] = local_BuildDoc
[*]
[*]except:
[*] pass
[*]
[*]
[*]try:
[*] #我猜想应该是抽取目录吧
[*]
[*] from babel.messages import frontend as babel
[*] nova_cmdclass['compile_catalog'] = babel.compile_catalog
[*] nova_cmdclass['extract_messages'] = babel.extract_messages
[*] nova_cmdclass['init_catalog'] = babel.init_catalog
[*] nova_cmdclass['update_catalog'] = babel.update_catalog
[*]except:
[*] pass
[*]
[*]#是指找到数据文件?求高人指点
[*]def find_data_files(destdir, srcdir):
[*] package_data = []
[*] files = []
[*] for d in glob.glob('%s/*' % (srcdir, )):
[*] if os.path.isdir(d):
[*] package_data += find_data_files(
[*] os.path.join(destdir, os.path.basename(d)), d)
[*] else:
[*] files +=
[*] package_data += [(destdir, files)]
[*] return package_data
[*]#这个可能就是程序打包的部分里面的知识了,scripts是指指定目录下的脚本
[*]setup(name='nova',
[*] version=version.canonical_version_string(),
[*] description='cloud computing fabric controller',
[*] author='OpenStack',
[*] author_email='nova@lists.launchpad.net',
[*] url='http://www.openstack.org/',
[*] cmdclass=nova_cmdclass,
[*] packages=find_packages(exclude=['bin', 'smoketests']),
[*] include_package_data=True,
[*] test_suite='nose.collector',
[*] data_files=find_data_files('share/nova', 'tools'),
[*] scripts=['bin/nova-ajax-console-proxy',
[*] 'bin/nova-api',
[*] 'bin/nova-compute',
[*] 'bin/nova-console',
[*] 'bin/nova-dhcpbridge',
[*] 'bin/nova-direct-api',
[*] 'bin/nova-logspool',
[*] 'bin/nova-manage',
[*] 'bin/nova-network',
[*] 'bin/nova-objectstore',
[*] 'bin/nova-scheduler',
[*] 'bin/nova-spoolsentry',
[*] 'bin/stack',
[*] 'bin/nova-volume',
[*] 'bin/nova-vncproxy',
[*] 'tools/nova-debug'],
[*] py_modules=[])
页:
[1]