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

Python manager.main函数代码示例

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

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



在下文中一共展示了main函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_err_no_such_coll

    def test_err_no_such_coll(self):
        """ Test error adding warc to non-existant collection
        """
        warc1 = self._get_sample_warc("example.warc.gz")

        with raises(IOError):
            main(["add", "bar", warc1])
开发者ID:eriknstr,项目名称:pywb,代码行数:7,代码来源:test_auto_colls.py


示例2: test_custom_config

    def test_custom_config(self):
        """ Test custom created config.yaml which overrides auto settings
        Template is relative to collection-specific dir
        Add custom metadata and test its presence in custom search page
        """
        config_path = os.path.join(self.root_dir, 'collections', 'test', 'config.yaml')
        with open(config_path, 'w+b') as fh:
            fh.write('search_html: ./templates/custom_search.html\n')
            fh.write('index_paths: ./cdx2/\n')

        custom_search = os.path.join(self.root_dir, 'collections', 'test',
                                     'templates', 'custom_search.html')

        # add metadata
        main(['metadata', 'test', '--set', 'some=value'])

        with open(custom_search, 'w+b') as fh:
            fh.write('config.yaml overriden search page: ')
            fh.write('{{ wbrequest.user_metadata | tojson }}\n')

        os.rename(os.path.join(self.root_dir, 'collections', 'test', INDEX_DIR),
                  os.path.join(self.root_dir, 'collections', 'test', 'cdx2'))

        self._create_app()
        resp = self.testapp.get('/test/')
        assert resp.status_int == 200
        assert resp.content_type == 'text/html'
        assert 'config.yaml overriden search page: {"some": "value"}' in resp.body

        resp = self.testapp.get('/test/20140103030321/http://example.com?example=1')
        assert resp.status_int == 200
开发者ID:machawk1,项目名称:pywb,代码行数:31,代码来源:test_auto_colls.py


示例3: test_more_custom_templates

    def test_more_custom_templates(self):
        """
        Test custom templates and metadata
        Template is relative to collection-specific dir
        Add custom metadata and test its presence in custom search page
        """
        custom_search = os.path.join(self.root_dir, COLLECTIONS, 'test',
                                      'templates', 'search.html')

        # add metadata
        main(['metadata', 'test', '--set', 'some=value'])

        with open(custom_search, 'w+b') as fh:
            fh.write(b'overriden search page: ')
            fh.write(b'{{ metadata | tojson }}\n')

        # force clear of jinja env cache to reload
        self.app.rewriterapp.jinja_env.jinja_env.cache = {}

        resp = self.testapp.get('/test/')
        resp.charset = 'utf-8'
        assert resp.status_int == 200
        assert resp.content_type == 'text/html'
        assert 'overriden search page: ' in resp.text
        assert '"some":"value"' in resp.text
开发者ID:ikreymer,项目名称:pywb,代码行数:25,代码来源:test_auto_colls.py


示例4: test_custom_config

    def test_custom_config(self):
        """ Test custom created config.yaml which overrides auto settings
        Template is relative to collection-specific dir
        Add custom metadata and test its presence in custom search page
        """
        config_path = os.path.join(self.root_dir, "collections", "test", "config.yaml")
        with open(config_path, "w+b") as fh:
            fh.write(b"search_html: ./templates/custom_search.html\n")
            fh.write(b"index_paths: ./cdx2/\n")

        custom_search = os.path.join(self.root_dir, "collections", "test", "templates", "custom_search.html")

        # add metadata
        main(["metadata", "test", "--set", "some=value"])

        with open(custom_search, "w+b") as fh:
            fh.write(b"config.yaml overriden search page: ")
            fh.write(b"{{ wbrequest.user_metadata | tojson }}\n")

        os.rename(
            os.path.join(self.root_dir, "collections", "test", INDEX_DIR),
            os.path.join(self.root_dir, "collections", "test", "cdx2"),
        )

        self._create_app()
        resp = self.testapp.get("/test/")
        resp.charset = "utf-8"
        assert resp.status_int == 200
        assert resp.content_type == "text/html"
        assert 'config.yaml overriden search page: {"some": "value"}' in resp.text

        resp = self.testapp.get("/test/20140103030321/http://example.com?example=1")
        assert resp.status_int == 200
开发者ID:eriknstr,项目名称:pywb,代码行数:33,代码来源:test_auto_colls.py


示例5: test_err_missing_dirs

    def test_err_missing_dirs(self):
        """ Test various errors with missing warcs dir,
        missing cdx dir, non dir cdx file, and missing collections root
        """
        colls = os.path.join(self.root_dir, COLLECTIONS)

        # No Statics -- ignorable
        shutil.rmtree(os.path.join(colls, 'foo', 'static'))

        # No WARCS
        warcs_path = os.path.join(colls, 'foo', ARCHIVE_DIR)
        shutil.rmtree(warcs_path)

        with raises(IOError):
            main(['add', 'foo', 'somewarc'])

        # No CDX
        cdx_path = os.path.join(colls, 'foo', INDEX_DIR)
        shutil.rmtree(cdx_path)

        # CDX a file not a dir
        with open(cdx_path, 'w+b') as fh:
            fh.write(b'foo\n')

        shutil.rmtree(colls)

        # No Collections to list
        with raises(IOError):
            main(['list'])

        # No Collections
        resp = self.testapp.get('/test/', status=404)
        assert resp.status_int == 404
开发者ID:ikreymer,项目名称:pywb,代码行数:33,代码来源:test_auto_colls.py


示例6: test_err_invalid_name

    def test_err_invalid_name(self):
        """ Invalid collection name
        """
        with raises(ValueError):
            main(["init", "../abc%"])

        with raises(ValueError):
            main(["init", "45^23"])
开发者ID:eriknstr,项目名称:pywb,代码行数:8,代码来源:test_auto_colls.py


示例7: test_another_coll

    def test_another_coll(self):
        """ Test adding warc to a new coll, check replay
        """
        warc1 = self._get_sample_warc('example.warc.gz')

        main(['init', 'foo'])

        main(['add', 'foo', warc1])
开发者ID:ikreymer,项目名称:pywb,代码行数:8,代码来源:test_auto_colls.py


示例8: test_add_warcs

    def test_add_warcs(self):
        """ Test adding warc to new coll, check replay
        """
        warc1 = self._get_sample_warc("example.warc.gz")

        main(["add", "test", warc1])

        self._create_app()
        resp = self.testapp.get("/test/20140103030321/http://example.com?example=1")
        assert resp.status_int == 200
开发者ID:eriknstr,项目名称:pywb,代码行数:10,代码来源:test_auto_colls.py


示例9: test_add_title_metadata_index_page

    def test_add_title_metadata_index_page(self):
        """ Test adding title metadata to a collection, test
        retrieval on default index page
        """
        main(['metadata', 'foo', '--set', 'title=Collection Title'])

        self._create_app()
        resp = self.testapp.get('/')
        assert resp.status_int == 200
        assert resp.content_type == 'text/html'
        assert '(Collection Title)' in resp.body
开发者ID:machawk1,项目名称:pywb,代码行数:11,代码来源:test_auto_colls.py


示例10: test_add_title_metadata_index_page

    def test_add_title_metadata_index_page(self):
        """ Test adding title metadata to a collection, test
        retrieval on default index page
        """
        main(["metadata", "foo", "--set", "title=Collection Title"])

        self._create_app()
        resp = self.testapp.get("/")
        assert resp.status_int == 200
        assert resp.content_type == "text/html"
        resp.charset = "utf-8"
        assert "(Collection Title)" in resp.text
开发者ID:eriknstr,项目名称:pywb,代码行数:12,代码来源:test_auto_colls.py


示例11: test_create_first_coll

    def test_create_first_coll(self):
        """ Test first collection creation, with all required dirs
        """
        main(['init', 'test'])

        colls = os.path.join(self.root_dir, COLLECTIONS)
        assert os.path.isdir(colls)

        test = os.path.join(colls, 'test')
        assert os.path.isdir(test)

        self._check_dirs(test, [INDEX_DIR, ARCHIVE_DIR, 'static', 'templates'])
开发者ID:ikreymer,项目名称:pywb,代码行数:12,代码来源:test_auto_colls.py


示例12: test_create_first_coll

    def test_create_first_coll(self):
        """ Test first collection creation, with all required dirs
        """
        main(["init", "test"])

        colls = os.path.join(self.root_dir, "collections")
        assert os.path.isdir(colls)

        test = os.path.join(colls, "test")
        assert os.path.isdir(test)

        self._check_dirs(test, [INDEX_DIR, ARCHIVE_DIR, "static", "templates"])
开发者ID:eriknstr,项目名称:pywb,代码行数:12,代码来源:test_auto_colls.py


示例13: test_auto_index

    def test_auto_index(self):
        main(['init', 'auto'])
        auto_dir = os.path.join(self.root_dir, COLLECTIONS, 'auto')
        archive_dir = os.path.join(auto_dir, ARCHIVE_DIR)

        archive_sub_dir = os.path.join(archive_dir, 'sub')
        os.makedirs(archive_sub_dir)

        def do_copy():
            try:
                time.sleep(1.0)
                shutil.copy(self._get_sample_warc('example.warc.gz'), archive_dir)
                shutil.copy(self._get_sample_warc('example-extra.warc'), archive_sub_dir)
                time.sleep(1.0)
            finally:
                indexer.interval = 0

        indexer = AutoIndexer(interval=0.25)
        indexer.start()

        ge = gevent.spawn(do_copy)
        ge.join()

        index_file = os.path.join(auto_dir, INDEX_DIR, AUTOINDEX_FILE)
        assert os.path.isfile(index_file)

        with open(index_file, 'r') as fh:
            index = fh.read()

        assert '"example.warc.gz' in index, index
        assert '"sub/example-extra.warc' in index, index

        mtime = os.path.getmtime(index_file)

        # Update
        indexer.interval = 0.25
        indexer.start()

        os.remove(index_file)

        #thread = threading.Thread(target=do_copy)
        #thread.daemon = True
        #thread.start()
        ge = gevent.spawn(do_copy)

        #wayback(['-p', '0', '-a', '--auto-interval', '0.25'])

        #thread.join()
        ge.join()

	# assert file was update
        assert os.path.getmtime(index_file) > mtime
开发者ID:ikreymer,项目名称:pywb,代码行数:52,代码来源:test_auto_colls.py


示例14: test_add_more_warcs

    def test_add_more_warcs(self):
        """ Test adding additional warcs, check replay of added content
        """
        warc1 = self._get_sample_warc('iana.warc.gz')
        warc2 = self._get_sample_warc('example-extra.warc')

        main(['add', 'test', warc1, warc2])

        # Spurrious file in collections
        with open(os.path.join(self.root_dir, COLLECTIONS, 'blah'), 'w+b') as fh:
            fh.write(b'foo\n')

        with raises(IOError):
            main(['add', 'test', 'non-existent-file.warc.gz'])
开发者ID:ikreymer,项目名称:pywb,代码行数:14,代码来源:test_auto_colls.py


示例15: test_add_modify_home_template

    def test_add_modify_home_template(self):
        # Add shared template
        main(['template', '--add', 'home_html'])

        filename = os.path.join(self.root_dir, 'templates', 'index.html')
        assert os.path.isfile(filename)

        with open(filename, 'r+b') as fh:
            buf = fh.read()
            buf = buf.replace(b'</html>', b'Custom Test Homepage</html>')
            fh.seek(0)
            fh.write(buf)

        resp = self.testapp.get('/')
        resp.charset = 'utf-8'
        assert resp.content_type == 'text/html'
        assert 'Custom Test Homepage</html>' in resp.text, resp.text
开发者ID:ikreymer,项目名称:pywb,代码行数:17,代码来源:test_auto_colls.py


示例16: test_add_custom_nested_warcs

    def test_add_custom_nested_warcs(self):
        """ Test recursive indexing of custom created WARC hierarchy,
        warcs/A/..., warcs/B/sub/...
        Ensure CDX is relative to root archive dir, test replay
        """

        main(['init', 'nested'])

        nested_root = os.path.join(self.root_dir, 'collections', 'nested', ARCHIVE_DIR)
        nested_a = os.path.join(nested_root, 'A')
        nested_b = os.path.join(nested_root, 'B', 'sub')

        os.makedirs(nested_a)
        os.makedirs(nested_b)

        warc1 = self._get_sample_warc('iana.warc.gz')
        warc2 = self._get_sample_warc('example.warc.gz')

        shutil.copy2(warc1, nested_a)
        shutil.copy2(warc2, nested_b)

        main(['index',
              'nested',
              os.path.join(nested_a, 'iana.warc.gz'),
              os.path.join(nested_b, 'example.warc.gz')
             ])

        nested_cdx = os.path.join(self.root_dir, 'collections', 'nested', INDEX_DIR, INDEX_FILE)
        with open(nested_cdx) as fh:
            nested_cdx_index = fh.read()

        assert '1043' in nested_cdx_index
        assert '333' in nested_cdx_index
        assert 'B/sub/example.warc.gz' in nested_cdx_index

        assert '2258' in nested_cdx_index
        assert '334' in nested_cdx_index
        assert 'A/iana.warc.gz' in nested_cdx_index

        self._create_app()
        resp = self.testapp.get('/nested/20140126200624/http://www.iana.org/')
        assert resp.status_int == 200

        resp = self.testapp.get('/nested/20140103030321/http://example.com?example=1')
        assert resp.status_int == 200
开发者ID:machawk1,项目名称:pywb,代码行数:45,代码来源:test_auto_colls.py


示例17: test_list_colls

    def test_list_colls(self):
        """ Test collection listing, printed to stdout
        """
        orig_stdout = sys.stdout
        buff = StringIO()
        sys.stdout = buff

        try:
            main(['list'])
        finally:
            sys.stdout = orig_stdout

        output = sorted(buff.getvalue().splitlines())
        assert len(output) == 4
        assert 'Collections:' in output
        assert '- foo' in output
        assert '- nested' in output
        assert '- test' in output
开发者ID:ikreymer,项目名称:pywb,代码行数:18,代码来源:test_auto_colls.py


示例18: test_add_modify_home_template

    def test_add_modify_home_template(self):
        # Add shared template
        main(["template", "--add", "home_html"])

        filename = os.path.join(self.root_dir, "templates", "index.html")
        assert os.path.isfile(filename)

        with open(filename, "r+b") as fh:
            buf = fh.read()
            buf = buf.replace(b"</html>", b"Custom Test Homepage</html>")
            fh.seek(0)
            fh.write(buf)

        self._create_app()
        resp = self.testapp.get("/")
        resp.charset = "utf-8"
        assert resp.content_type == "text/html"
        assert "Custom Test Homepage</html>" in resp.text, resp.text
开发者ID:eriknstr,项目名称:pywb,代码行数:18,代码来源:test_auto_colls.py


示例19: test_add_more_warcs

    def test_add_more_warcs(self):
        """ Test adding additional warcs, check replay of added content
        """
        warc1 = self._get_sample_warc("iana.warc.gz")
        warc2 = self._get_sample_warc("example-extra.warc")

        main(["add", "test", warc1, warc2])

        # Spurrious file in collections
        with open(os.path.join(self.root_dir, "collections", "blah"), "w+b") as fh:
            fh.write(b"foo\n")

        with raises(IOError):
            main(["add", "test", "non-existent-file.warc.gz"])

        # check new cdx
        self._create_app()
        resp = self.testapp.get("/test/20140126200624/http://www.iana.org/")
        assert resp.status_int == 200
开发者ID:eriknstr,项目名称:pywb,代码行数:19,代码来源:test_auto_colls.py


示例20: test_add_more_warcs

    def test_add_more_warcs(self):
        """ Test adding additional warcs, check replay of added content
        """
        warc1 = self._get_sample_warc('iana.warc.gz')
        warc2 = self._get_sample_warc('example-extra.warc')

        main(['add', 'test', warc1, warc2])

        # Spurrious file in collections
        with open(os.path.join(self.root_dir, 'collections', 'blah'), 'w+b') as fh:
            fh.write('foo\n')

        with raises(IOError):
            main(['add', 'test', 'non-existent-file.warc.gz'])

        # check new cdx
        self._create_app()
        resp = self.testapp.get('/test/20140126200624/http://www.iana.org/')
        assert resp.status_int == 200
开发者ID:machawk1,项目名称:pywb,代码行数:19,代码来源:test_auto_colls.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python _pywcs._Wcsprm函数代码示例发布时间:2022-05-26
下一篇:
Python wsgi_wrappers.init_app函数代码示例发布时间: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