本文整理汇总了Python中trac.config.Configuration.sections方法的典型用法代码示例。如果您正苦于以下问题:Python Configuration.sections方法的具体用法?Python Configuration.sections怎么用?Python Configuration.sections使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trac.config.Configuration
的用法示例。
在下文中一共展示了Configuration.sections方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: diff
# 需要导入模块: from trac.config import Configuration [as 别名]
# 或者: from trac.config.Configuration import sections [as 别名]
def diff(file1, file2, ignored_sections=None, ignore_absent=False):
"""
:param file1: Filename
:param file2: Filename
:param list ignored_sections: List of ignored sections
:param bool ignore_absent: Disables absent key reporting
"""
if ignored_sections is None:
ignored_sections = []
if not os.path.exists(file1):
raise ValueError("file %s does not exists" % file1)
if not os.path.exists(file2):
raise ValueError("file %s does not exists" % file2)
conf1 = Configuration(file1)
conf2 = Configuration(file2)
fn1 = os.path.split(file1)[1]
fn2 = os.path.split(file2)[1]
conf1_sections = set(conf1.sections()) - set(ignored_sections)
conf2_sections = set(conf2.sections()) - set(ignored_sections)
for section in conf1.sections():
if section not in conf2_sections:
print "SECTION: %s not in %s" % (section, fn2)
default = object()
for section in conf1_sections:
for key, value1 in conf1.options(section):
if not conf2.has_option(section, key):
if not ignore_absent:
print "[%s] %s = %s is ABSENT from %s (but exists in %s)" % (section, key, value1, fn2, fn1)
else:
value2 = conf2.get(section, key, default)
if value2 != value1 and value2 is not default:
print "[%s] %s = %s -> %s (%s -> %s)" % (section, key, value1, value2, fn1, fn2)
示例2: do_initenv
# 需要导入模块: from trac.config import Configuration [as 别名]
# 或者: from trac.config.Configuration import sections [as 别名]
def do_initenv(self, line):
def initenv_error(msg):
printerr(_("Initenv for '%(env)s' failed.", env=self.envname),
"\n%s" % msg)
if self.env_check():
initenv_error(_("Does an environment already exist?"))
return 2
if os.path.exists(self.envname) and os.listdir(self.envname):
initenv_error(_("Directory exists and is not empty."))
return 2
if not os.path.exists(os.path.dirname(self.envname)):
initenv_error(_("Base directory '%(env)s' does not exist. Please "
"create it manually and retry.",
env=os.path.dirname(self.envname)))
return 2
arg = self.arg_tokenize(line)
inherit_paths = []
config_file_path = None
i = 0
while i < len(arg):
item = arg[i]
if item.startswith('--inherit='):
inherit_paths.append(arg.pop(i)[10:])
elif item.startswith('--config='):
config_file_path = arg.pop(i)[9:]
else:
i += 1
config = None
if config_file_path:
if not os.path.exists(config_file_path):
initenv_error(_("The file specified in the --config argument "
"does not exist: %(path)s.",
path=config_file_path))
return 2
try:
config = Configuration(config_file_path)
except TracError as e:
initenv_error(e)
return 2
arg = arg or [''] # Reset to usual empty in case we popped the only one
project_name = None
db_str = None
repository_type = None
repository_dir = None
if len(arg) == 1 and not arg[0]:
project_name, db_str = self.get_initenv_args()
elif len(arg) == 2:
project_name, db_str = arg
elif len(arg) == 4:
project_name, db_str, repository_type, repository_dir = arg
else:
initenv_error('Wrong number of arguments: %d' % len(arg))
return 2
try:
printout(_("Creating and Initializing Project"))
options = []
if config:
for section in config.sections(defaults=False):
options.extend((section, option, value)
for option, value
in config.options(section))
options.extend([
('project', 'name', project_name),
('trac', 'database', db_str),
])
def add_nav_order_options(section, default):
for i, name in enumerate(default, 1):
options.append((section, name + '.order', float(i)))
add_nav_order_options('mainnav', default_mainnav_order)
add_nav_order_options('metanav', default_metanav_order)
if repository_dir:
options.extend([
('repositories', '.type', repository_type),
('repositories', '.dir', repository_dir),
])
if inherit_paths:
options.append(('inherit', 'file',
",\n ".join(inherit_paths)))
try:
self.__env = Environment(self.envname, create=True,
options=options)
except Exception as e:
initenv_error(_('Failed to create environment.'))
printerr(e)
traceback.print_exc()
sys.exit(1)
# Add a few default wiki pages
printout(_(" Installing default wiki pages"))
pages_dir = pkg_resources.resource_filename('trac.wiki',
'default-pages')
WikiAdmin(self.__env).load_pages(pages_dir)
if repository_dir:
try:
repos = RepositoryManager(self.__env).get_repository('')
#.........这里部分代码省略.........