本文整理汇总了Python中awscli.topictags.TopicTagDB.load_json_index方法的典型用法代码示例。如果您正苦于以下问题:Python TopicTagDB.load_json_index方法的具体用法?Python TopicTagDB.load_json_index怎么用?Python TopicTagDB.load_json_index使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类awscli.topictags.TopicTagDB
的用法示例。
在下文中一共展示了TopicTagDB.load_json_index方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ProviderHelpCommand
# 需要导入模块: from awscli.topictags import TopicTagDB [as 别名]
# 或者: from awscli.topictags.TopicTagDB import load_json_index [as 别名]
class ProviderHelpCommand(HelpCommand):
"""Implements top level help command.
This is what is called when ``aws help`` is run.
"""
EventHandlerClass = ProviderDocumentEventHandler
def __init__(self, session, command_table, arg_table,
description, synopsis, usage):
HelpCommand.__init__(self, session, None,
command_table, arg_table)
self.description = description
self.synopsis = synopsis
self.help_usage = usage
self._subcommand_table = None
self._topic_tag_db = None
self._related_items = ['aws help topics']
@property
def event_class(self):
return 'aws'
@property
def name(self):
return 'aws'
@property
def subcommand_table(self):
if self._subcommand_table is None:
if self._topic_tag_db is None:
self._topic_tag_db = TopicTagDB()
self._topic_tag_db.load_json_index()
self._subcommand_table = self._create_subcommand_table()
return self._subcommand_table
def _create_subcommand_table(self):
subcommand_table = {}
# Add the ``aws help topics`` command to the ``topic_table``
topic_lister_command = TopicListerCommand(self.session)
subcommand_table['topics'] = topic_lister_command
topic_names = self._topic_tag_db.get_all_topic_names()
# Add all of the possible topics to the ``topic_table``
for topic_name in topic_names:
topic_help_command = TopicHelpCommand(self.session, topic_name)
subcommand_table[topic_name] = topic_help_command
return subcommand_table
示例2: TopicListerDocumentEventHandler
# 需要导入模块: from awscli.topictags import TopicTagDB [as 别名]
# 或者: from awscli.topictags.TopicTagDB import load_json_index [as 别名]
class TopicListerDocumentEventHandler(CLIDocumentEventHandler):
DESCRIPTION = (
'This is the AWS CLI Topic Guide. It gives access to a set '
'of topics that provide a deeper understanding of the CLI. To access '
'the list of topics from the command line, run ``aws help topics``. '
'To access a specific topic from the command line, run '
'``aws help [topicname]``, where ``topicname`` is the name of the '
'topic as it appears in the output from ``aws help topics``.')
def __init__(self, help_command):
self.help_command = help_command
self.register(help_command.session, help_command.event_class)
self.help_command.doc.translation_map = self.build_translation_map()
self._topic_tag_db = TopicTagDB()
self._topic_tag_db.load_json_index()
def doc_breadcrumbs(self, help_command, **kwargs):
doc = help_command.doc
if doc.target != 'man':
doc.write('[ ')
doc.style.sphinx_reference_label(label='cli:aws', text='aws')
doc.write(' ]')
def doc_title(self, help_command, **kwargs):
doc = help_command.doc
doc.style.new_paragraph()
doc.style.link_target_definition(
refname='cli:aws help %s' % self.help_command.name,
link='')
doc.style.h1('AWS CLI Topic Guide')
def doc_description(self, help_command, **kwargs):
doc = help_command.doc
doc.style.h2('Description')
doc.include_doc_string(self.DESCRIPTION)
doc.style.new_paragraph()
def doc_synopsis_start(self, help_command, **kwargs):
pass
def doc_synopsis_end(self, help_command, **kwargs):
pass
def doc_options_start(self, help_command, **kwargs):
pass
def doc_options_end(self, help_command, **kwargs):
pass
def doc_subitems_start(self, help_command, **kwargs):
doc = help_command.doc
doc.style.h2('Available Topics')
categories = self._topic_tag_db.query('category')
topic_names = self._topic_tag_db.get_all_topic_names()
# Sort the categories
category_names = sorted(categories.keys())
for category_name in category_names:
doc.style.h3(category_name)
doc.style.new_paragraph()
# Write out the topic and a description for each topic under
# each category.
for topic_name in sorted(categories[category_name]):
description = self._topic_tag_db.get_tag_single_value(
topic_name, 'description')
doc.write('* ')
doc.style.sphinx_reference_label(
label='cli:aws help %s' % topic_name,
text=topic_name
)
doc.write(': %s\n' % description)
# Add a hidden toctree to make sure everything is connected in
# the document.
doc.style.hidden_toctree()
for topic_name in topic_names:
doc.style.hidden_tocitem(topic_name)
示例3: TestTopicTagDBGeneral
# 需要导入模块: from awscli.topictags import TopicTagDB [as 别名]
# 或者: from awscli.topictags.TopicTagDB import load_json_index [as 别名]
#.........这里部分代码省略.........
tag_dict = {
topic_name: {
'related topic': ['foo']
}
}
self.topic_tag_db = TopicTagDB(tag_dict)
value = self.topic_tag_db.get_tag_value('no-exist', 'related topic')
self.assertEqual(value, None)
def test_get_tag_no_exist_tag(self):
topic_name = 'topic-name-1'
tag_dict = {
topic_name: {
'related topic': ['foo']
}
}
self.topic_tag_db = TopicTagDB(tag_dict)
value = self.topic_tag_db.get_tag_value(topic_name, ':foo:')
self.assertEqual(value, None)
def test_get_tag_no_exist_use_default(self):
topic_name = 'topic-name-1'
tag_dict = {
topic_name: {
'related topic': ['foo']
}
}
self.topic_tag_db = TopicTagDB(tag_dict)
value = self.topic_tag_db.get_tag_value('no-exist', ':foo:', [])
self.assertEqual(value, [])
def test_get_tag_single_value(self):
topic_name = 'topic-name-1'
tag_dict = {
topic_name: {
'title': ['foo']
}
}
self.topic_tag_db = TopicTagDB(tag_dict)
value = self.topic_tag_db.get_tag_single_value('topic-name-1', 'title')
self.assertEqual(value, 'foo')
def test_get_tag_single_value_exception(self):
topic_name = 'topic-name-1'
tag_dict = {
topic_name: {
'title': ['foo', 'bar']
}
}
self.topic_tag_db = TopicTagDB(tag_dict)
with self.assertRaises(ValueError):
self.topic_tag_db.get_tag_single_value('topic-name-1', 'title')
def test_get_tag_single_value_no_exists(self):
topic_name = 'topic-name-1'
tag_dict = {
topic_name: {
'title': ['foo']
}
}
self.topic_tag_db = TopicTagDB(tag_dict)
value = self.topic_tag_db.get_tag_single_value(
'topic-name-1', ':title:')
self.assertEqual(value, None)
def test_load_and_save_json_index(self):
tag_dict = {
'topic-name-1': {
'title': ['My First Topic Title'],
'description': ['This describes my first topic'],
'category': ['General Topics', 'S3'],
'related command': ['aws s3'],
'related topic': ['topic-name-2']
},
'topic-name-2': {
'title': ['My Second Topic Title'],
'description': ['This describes my second topic'],
'category': ['General Topics'],
'related topic': ['topic-name-1']
}
}
json_index = self.file_creator.create_file('index.json', '')
# Create a JSON index to be loaded.
tag_json = json.dumps(tag_dict, indent=4, sort_keys=True)
with open(json_index, 'w') as f:
f.write(tag_json)
# Load the JSON index.
self.topic_tag_db = TopicTagDB(index_file=json_index)
self.topic_tag_db.load_json_index()
# Write the loaded json to disk and ensure it is as expected.
saved_json_index = self.file_creator.create_file('index2.json', '')
self.topic_tag_db.index_file = saved_json_index
self.topic_tag_db.save_to_json_index()
with open(saved_json_index, 'r') as f:
self.assertEqual(f.read(), tag_json)