• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python utils.get_file_contents函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中utils.get_file_contents函数的典型用法代码示例。如果您正苦于以下问题:Python get_file_contents函数的具体用法?Python get_file_contents怎么用?Python get_file_contents使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_file_contents函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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()
开发者ID:sunu,项目名称:oppia-test-4,代码行数:26,代码来源:models.py


示例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)
开发者ID:DSeanLaw,项目名称:oppia,代码行数:7,代码来源:visualization_registry.py


示例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
开发者ID:wasper1,项目名称:oppia,代码行数:58,代码来源:rte_component_registry_test.py


示例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)
开发者ID:maitbayev,项目名称:oppia,代码行数:10,代码来源:base.py


示例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))
开发者ID:miyucy,项目名称:oppia,代码行数:12,代码来源:tar_file_string_test.py


示例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)
开发者ID:Samuirai,项目名称:nazo,代码行数:12,代码来源:nazo_server.py


示例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)
开发者ID:VictoriaRoux,项目名称:oppia,代码行数:12,代码来源:base.py


示例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))
开发者ID:miyucy,项目名称:oppia,代码行数:12,代码来源:tar_file_string_test.py


示例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))
开发者ID:miyucy,项目名称:oppia,代码行数:12,代码来源:tar_file_string_test.py


示例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))
开发者ID:CuriousLearner,项目名称:oppia,代码行数:13,代码来源:galleries_test.py


示例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)
开发者ID:rainehoover,项目名称:oppia,代码行数:14,代码来源:base.py


示例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))
开发者ID:willingc,项目名称:oh-missions-oppia-beta,代码行数:15,代码来源:tar_file_string_test.py


示例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))
开发者ID:miyucy,项目名称:oppia,代码行数:15,代码来源:tar_file_string_test.py


示例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)
开发者ID:willingc,项目名称:oh-missions-oppia-beta,代码行数:32,代码来源:exp_services.py


示例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))
开发者ID:willingc,项目名称:oh-missions-oppia-beta,代码行数:16,代码来源:tar_file_string_test.py


示例16: load_demos

def load_demos():
    """Initializes the demo explorations."""
    for index, exploration in enumerate(feconf.DEMO_EXPLORATIONS):
        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.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, None, title, category, exploration_id=str(index),
            image_id=image_id)

        exploration = Exploration.get(exploration_id)
        exploration.is_public = True
        exploration.put()
开发者ID:sunu,项目名称:oppia-test-4,代码行数:26,代码来源:services.py


示例17: load_demo_explorations

    def load_demo_explorations(cls):
        """Initializes the demo explorations."""
        for index, exploration in enumerate(feconf.DEMO_EXPLORATIONS):
            assert len(exploration) in [3, 4], "Invalid format for demo exploration: %s" % exploration

            yaml_filename = "%s.yaml" % exploration[0]
            yaml_file = utils.get_file_contents(os.path.join(feconf.SAMPLE_EXPLORATIONS_DIR, yaml_filename))

            title = exploration[1]
            category = exploration[2]
            image_filename = exploration[3] if len(exploration) == 4 else None

            image_id = None
            if image_filename:
                with open(os.path.join(feconf.SAMPLE_IMAGES_DIR, image_filename)) as f:
                    raw_image = f.read()
                image_id = Image.create(raw_image)

            exploration = cls.create_from_yaml(
                yaml_file=yaml_file,
                user=None,
                title=title,
                category=category,
                exploration_id=str(index),
                image_id=image_id,
            )
            exploration.is_public = True
            exploration.put()
开发者ID:sunu,项目名称:oppia-test-2,代码行数:28,代码来源:models.py


示例18: _stats_log_template

 def _stats_log_template(self):
     """The template for reader responses in the stats log."""
     try:
         return utils.get_file_contents(os.path.join(
             feconf.INTERACTIONS_DIR, self.id, 'stats_response.html'))
     except IOError:
         return '{{answer}}'
开发者ID:rainehoover,项目名称:oppia,代码行数:7,代码来源:base.py


示例19: get_js_template

 def get_js_template(cls):
     # NB: These generators should use only Angular templating. The
     # variables they have access to are generatorId, initArgs,
     # customizationArgs and objType.
     return utils.get_file_contents(os.path.join(
         os.getcwd(), feconf.VALUE_GENERATORS_DIR, 'templates',
         '%s.js' % cls.__name__))
开发者ID:aldeka,项目名称:oppia,代码行数:7,代码来源:value_generators_domain.py


示例20: get_editor_html_template

 def get_editor_html_template(cls):
     if cls.edit_html_filename is None:
         raise Exception(
             'There is no editor template defined for objects of type %s' %
             cls.__name__)
     return utils.get_file_contents(os.path.join(
         os.getcwd(), feconf.OBJECT_TEMPLATES_DIR,
         '%s.html' % cls.edit_html_filename))
开发者ID:maitbayev,项目名称:oppia,代码行数:8,代码来源:objects.py



注:本文中的utils.get_file_contents函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.get_filedisk函数代码示例发布时间:2022-05-26
下一篇:
Python utils.get_file_content函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap