本文整理汇总了Python中utils.get_file_contents函数的典型用法代码示例。如果您正苦于以下问题:Python get_file_contents函数的具体用法?Python get_file_contents怎么用?Python get_file_contents使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_file_contents函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_default_widgets
def load_default_widgets(cls):
"""Loads the default widgets.
Assumes that everything is valid (directories exist, widget config files
are formatted correctly, etc.).
"""
widget_ids = os.listdir(feconf.INTERACTIVE_WIDGETS_DIR)
for widget_id in widget_ids:
widget_dir = os.path.join(feconf.INTERACTIVE_WIDGETS_DIR, widget_id)
widget_conf_filename = '%s.config.yaml' % widget_id
with open(os.path.join(widget_dir, widget_conf_filename)) as f:
conf = utils.dict_from_yaml(f.read().decode('utf-8'))
conf['id'] = '%s-%s' % (feconf.INTERACTIVE_PREFIX, widget_id)
conf['params'] = [Parameter(**param) for param in conf['params']]
conf['handlers'] = [AnswerHandler(**ah) for ah in conf['handlers']]
conf['template'] = utils.get_file_contents(
os.path.join(widget_dir, '%s.html' % widget_id))
conf['static_template'] = ''
static_path = os.path.join(widget_dir, '%s.static.html' % widget_id)
if os.path.exists(static_path):
conf['static_template'] = utils.get_file_contents(static_path)
widget = cls(**conf)
widget.put()
示例2: get_full_html
def get_full_html(cls):
"""Returns the HTML bodies for all visualizations."""
js_directives = utils.get_file_contents(os.path.join(
feconf.VISUALIZATIONS_DIR, 'visualizations.js'))
html_templates = utils.get_file_contents(os.path.join(
feconf.VISUALIZATIONS_DIR, 'visualizations.html'))
return '<script>%s</script>\n%s' % (js_directives, html_templates)
示例3: test_default_rte_components_are_valid
def test_default_rte_components_are_valid(self):
"""Test that the default RTE components are valid."""
for component_id in feconf.ALLOWED_RTE_EXTENSIONS:
# Check that the component id is valid.
self.assertTrue(self._is_camel_cased(component_id))
# Check that the component directory exists.
component_dir = os.path.join(
feconf.RTE_EXTENSIONS_DIR, component_id)
self.assertTrue(os.path.isdir(component_dir))
# In this directory there should be a config .py file, an
# html file, a JS file, a .png file and a protractor.js file.
dir_contents = self._listdir_omit_ignored(component_dir)
self.assertLessEqual(len(dir_contents), 5)
py_file = os.path.join(component_dir, '%s.py' % component_id)
html_file = os.path.join(component_dir, '%s.html' % component_id)
js_file = os.path.join(component_dir, '%s.js' % component_id)
png_file = os.path.join(component_dir, '%s.png' % component_id)
protractor_file = os.path.join(component_dir, 'protractor.js')
self.assertTrue(os.path.isfile(py_file))
self.assertTrue(os.path.isfile(html_file))
self.assertTrue(os.path.isfile(js_file))
self.assertTrue(os.path.isfile(png_file))
self.assertTrue(os.path.isfile(protractor_file))
js_file_content = utils.get_file_contents(js_file)
html_file_content = utils.get_file_contents(html_file)
self.assertIn(
'oppiaNoninteractive%s' % component_id, js_file_content)
self.assertIn(
'<script type="text/ng-template" '
'id="richTextComponent/%s"' % component_id,
html_file_content)
self.assertNotIn('<script>', js_file_content)
self.assertNotIn('</script>', js_file_content)
component = rte_component_registry.Registry.get_rte_component(
component_id)
# Check that the specified component id is the same as the class
# name.
self.assertTrue(component_id, component.__class__.__name__)
# Check that the configuration file contains the correct
# top-level keys, and that these keys have the correct types.
for item, item_type in _COMPONENT_CONFIG_SCHEMA:
self.assertTrue(isinstance(
getattr(component, item), item_type))
# The string attributes should be non-empty.
if item_type == basestring:
self.assertTrue(getattr(component, item))
self._validate_customization_arg_specs(
component._customization_arg_specs) # pylint: disable=protected-access
示例4: html_body
def html_body(self):
"""The HTML code containing directives and templates for the
gadget. This contains everything needed to display the gadget
once the necessary attributes are supplied.
"""
js_directives = utils.get_file_contents(os.path.join(
feconf.GADGETS_DIR, self.type, '%s.js' % self.type))
html_templates = utils.get_file_contents(os.path.join(
feconf.GADGETS_DIR, self.type, '%s.html' % self.type))
return '<script>%s</script>\n%s' % (js_directives, html_templates)
示例5: test_wrapper_name_rule
def test_wrapper_name_rule(self):
rule = tar_file_string.ChecksWrapperDirName('myproject-0.1')
file_name = 'wrong-wrapper-name.tar.gz'
encoded_content = base64.b64encode(utils.get_file_contents(
os.path.join(TEST_DATA_DIR, file_name), raw_bytes=True, mode='rb'))
self.assertTrue(rule.eval(encoded_content))
file_name = 'good.tar.gz'
encoded_content = base64.b64encode(utils.get_file_contents(
os.path.join(TEST_DATA_DIR, file_name), raw_bytes=True, mode='rb'))
self.assertFalse(rule.eval(encoded_content))
示例6: analyse_paths
def analyse_paths(host):
directory = utils.test_host_directory(host)
filters = utils.get_url_path_filters(host)
if os.path.isfile(directory+"paths_filtered"):
print "paths_filtered exists"
paths = utils.get_file_contents(host, "paths_filtered")
else:
print "paths_filtered doesn't exists"
paths = utils.get_file_contents(host, "paths")
paths.sort()
return render_template('analyse_paths.html', paths=paths, host=host, num_all_paths=len(paths), filters=filters)
示例7: html_body
def html_body(self):
"""The HTML code containing directives and templates for the component.
This contains everything needed to display the component once the
necessary attributes are supplied. For rich-text components, this
consists of a single directive/template pair.
"""
js_directives = utils.get_file_contents(os.path.join(
feconf.RTE_EXTENSIONS_DIR, self.id, '%s.js' % self.id))
html_templates = utils.get_file_contents(os.path.join(
feconf.RTE_EXTENSIONS_DIR, self.id, '%s.html' % self.id))
return '<script>%s</script>\n%s' % (js_directives, html_templates)
示例8: test_wrapper_presence_rule
def test_wrapper_presence_rule(self):
rule = tar_file_string.ChecksWrapperDirPresence()
file_name = 'no-wrapper-dir.tar.gz'
encoded_content = base64.b64encode(utils.get_file_contents(
os.path.join(TEST_DATA_DIR, file_name), raw_bytes=True, mode='rb'))
self.assertTrue(rule.eval(encoded_content))
file_name = 'good.tar.gz'
encoded_content = base64.b64encode(utils.get_file_contents(
os.path.join(TEST_DATA_DIR, file_name), raw_bytes=True, mode='rb'))
self.assertFalse(rule.eval(encoded_content))
示例9: test_apple_double_file_rule
def test_apple_double_file_rule(self):
rule = tar_file_string.HasAppleDoubleFile()
file_name = 'apple-double.tar.gz'
encoded_content = base64.b64encode(utils.get_file_contents(
os.path.join(TEST_DATA_DIR, file_name), raw_bytes=True, mode='rb'))
self.assertTrue(rule.eval(encoded_content))
file_name = 'good.tar.gz'
encoded_content = base64.b64encode(utils.get_file_contents(
os.path.join(TEST_DATA_DIR, file_name), raw_bytes=True, mode='rb'))
self.assertFalse(rule.eval(encoded_content))
示例10: test_thumbnail_icons_exist_for_each_category
def test_thumbnail_icons_exist_for_each_category(self):
all_categories = feconf.CATEGORIES_TO_COLORS.keys()
# Test that an icon exists for each default category.
for category in all_categories:
utils.get_file_contents(os.path.join(
'static', 'images', 'gallery', 'thumbnails',
'%s.svg' % category.replace(' ', '')))
# Test that the default icon exists.
utils.get_file_contents(os.path.join(
'static', 'images', 'gallery', 'thumbnails',
'%s.svg' % feconf.DEFAULT_THUMBNAIL_ICON))
示例11: html_body
def html_body(self):
"""The HTML code containing directives and templates for the
interaction. This contains everything needed to display the interaction
once the necessary attributes are supplied.
Each interaction has two directive/template pairs, one for the
interaction itself and the other for displaying the learner's response
in a read-only view after it has been submitted.
"""
js_directives = utils.get_file_contents(os.path.join(
feconf.INTERACTIONS_DIR, self.id, '%s.js' % self.id))
html_templates = utils.get_file_contents(os.path.join(
feconf.INTERACTIONS_DIR, self.id, '%s.html' % self.id))
return '<script>%s</script>\n%s' % (js_directives, html_templates)
示例12: test_unexpected_content_rule
def test_unexpected_content_rule(self):
TEST_DATA_DIR = 'extensions/rules/testdata'
rule = tar_file_string.HasUnexpectedContent(
['hello.c', 'Makefile'])
file_name = 'incorrect-contents.tar.gz'
encoded_content = base64.b64encode(utils.get_file_contents(
os.path.join(TEST_DATA_DIR, file_name), raw_bytes=True))
self.assertTrue(rule.eval(encoded_content))
file_name = 'good.tar.gz'
encoded_content = base64.b64encode(utils.get_file_contents(
os.path.join(TEST_DATA_DIR, file_name), raw_bytes=True))
self.assertFalse(rule.eval(encoded_content))
示例13: test_missing_expected_file_rule
def test_missing_expected_file_rule(self):
rule = tar_file_string.MissingExpectedFile(
["myproject-0.1", "myproject-0.1/hello.c",
"myproject-0.1/Makefile"]
)
file_name = 'missing-expected-file.tar.gz'
encoded_content = base64.b64encode(utils.get_file_contents(
os.path.join(TEST_DATA_DIR, file_name), raw_bytes=True, mode='rb'))
self.assertTrue(rule.eval(encoded_content))
file_name = 'good.tar.gz'
encoded_content = base64.b64encode(utils.get_file_contents(
os.path.join(TEST_DATA_DIR, file_name), raw_bytes=True, mode='rb'))
self.assertFalse(rule.eval(encoded_content))
示例14: load_demo
def load_demo(exploration_id):
"""Loads a demo exploration."""
if not (0 <= int(exploration_id) < len(feconf.DEMO_EXPLORATIONS)):
raise Exception('Invalid demo exploration id %s' % exploration_id)
exploration = feconf.DEMO_EXPLORATIONS[int(exploration_id)]
if len(exploration) == 3:
(exp_filename, title, category) = exploration
image_filename = None
elif len(exploration) == 4:
(exp_filename, title, category, image_filename) = exploration
else:
raise Exception('Invalid demo exploration: %s' % exploration)
image_id = None
if image_filename:
image_filepath = os.path.join(
feconf.SAMPLE_IMAGES_DIR, image_filename)
image_id = image_models.Image.create(utils.get_file_contents(
image_filepath, raw_bytes=True))
yaml_content = utils.get_sample_exploration_yaml(exp_filename)
exploration_id = create_from_yaml(
yaml_content, ADMIN_COMMITTER_ID, title, category,
exploration_id=exploration_id, image_id=image_id)
exploration = get_exploration_by_id(exploration_id)
exploration.is_public = True
save_exploration(ADMIN_COMMITTER_ID, exploration)
logging.info('Exploration with id %s was loaded.' % exploration_id)
示例15: test_unexpected_file_rule
def test_unexpected_file_rule(self):
TEST_DATA_DIR = 'extensions/rules/testdata'
rule = tar_file_string.HasUnexpectedFile(
["myproject-0.1", "myproject-0.1/hello.c", "myproject-0.1/Makefile"]
)
file_name = 'unexpected-file.tar.gz'
encoded_content = base64.b64encode(utils.get_file_contents(
os.path.join(TEST_DATA_DIR, file_name), raw_bytes=True))
self.assertTrue(rule.eval(encoded_content))
file_name = 'good.tar.gz'
encoded_content = base64.b64encode(utils.get_file_contents(
os.path.join(TEST_DATA_DIR, file_name), raw_bytes=True))
self.assertFalse(rule.eval(encoded_content))