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

Python util.create_file函数代码示例

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

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



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

示例1: setUp

    def setUp(self):
        tmpdir = os.path.realpath(tempfile.gettempdir())
        self.env = EnvironmentStub(enable=['trac.*', AuthzPolicy], path=tmpdir)
        self.env.config.set('trac', 'permission_policies',
                            'AuthzPolicy, DefaultPermissionPolicy')
        self.env.config.set('ticket', 'restrict_owner', True)

        self.perm_sys = PermissionSystem(self.env)
        self.env.insert_known_users([
            ('user1', '', ''), ('user2', '', ''),
            ('user3', '', ''), ('user4', '', '')
        ])
        self.perm_sys.grant_permission('user1', 'TICKET_MODIFY')
        self.perm_sys.grant_permission('user2', 'TICKET_VIEW')
        self.perm_sys.grant_permission('user3', 'TICKET_MODIFY')
        self.perm_sys.grant_permission('user4', 'TICKET_MODIFY')
        self.authz_file = os.path.join(tmpdir, 'trac-authz-policy')
        create_file(self.authz_file)
        self.env.config.set('authz_policy', 'authz_file', self.authz_file)
        self.ctlr = TicketSystem(self.env).action_controllers[0]
        self.req1 = Mock(authname='user1', args={},
                         perm=PermissionCache(self.env, 'user1'))
        self.ticket = Ticket(self.env)
        self.ticket['status'] = 'new'
        self.ticket.insert()
开发者ID:pkdevbox,项目名称:trac,代码行数:25,代码来源:default_workflow.py


示例2: test_inherit_multiple

    def test_inherit_multiple(self):
        class Foo(object):
            option_b = Option("b", "option2", "default")

        base = os.path.dirname(self.filename)
        relsite1 = os.path.join("sub1", "trac-site1.ini")
        site1 = os.path.join(base, relsite1)
        relsite2 = os.path.join("sub2", "trac-site2.ini")
        site2 = os.path.join(base, relsite2)
        os.mkdir(os.path.dirname(site1))
        create_file(site1, "[a]\noption1 = x\n" "[c]\noption = 1\npath1 = site1\n")
        try:
            os.mkdir(os.path.dirname(site2))
            create_file(site2, "[b]\noption2 = y\n" "[c]\noption = 2\npath2 = site2\n")
            try:
                self._write(["[inherit]", "file = %s, %s" % (relsite1, relsite2)])
                config = self._read()
                self.assertEqual("x", config.get("a", "option1"))
                self.assertEqual("y", config.get("b", "option2"))
                self.assertEqual("1", config.get("c", "option"))
                self.assertEqual(os.path.join(base, "site1"), config.getpath("c", "path1"))
                self.assertEqual(os.path.join(base, "site2"), config.getpath("c", "path2"))
                self.assertEqual("", config.getpath("c", "path3"))
                self.assertEqual(os.path.join(base, "site4"), config.getpath("c", "path4", "site4"))
            finally:
                os.remove(site2)
                os.rmdir(os.path.dirname(site2))
        finally:
            os.remove(site1)
            os.rmdir(os.path.dirname(site1))
开发者ID:zjj,项目名称:trac_hack,代码行数:30,代码来源:config.py


示例3: test_get_historian

    def test_get_historian(self):
        paths = [u'normal-path.txt',
                 u'tickét.tx\\t',
                 u'\a\b\t\n\v\f\r\x1b"\\.tx\\t']

        for path in paths:
            path_utf8 = path.encode('utf-8')
            create_file(os.path.join(self.repos_path, path_utf8))
            self._git('add', path_utf8)
        self._git_commit('-m', 'ticket:11180 and ticket:11198',
                         date=datetime(2013, 4, 30, 17, 48, 57))

        def validate(path, quotepath):
            self._git('config', 'core.quotepath', quotepath)
            storage = self._storage()
            rev = storage.head()
            with storage.get_historian('HEAD', path) as historian:
                hrev = storage.last_change('HEAD', path, historian)
                self.assertEquals(rev, hrev)

        validate(paths[0], 'true')
        validate(paths[0], 'false')
        validate(paths[1], 'true')
        validate(paths[1], 'false')
        validate(paths[2], 'true')
        validate(paths[2], 'false')
开发者ID:exocad,项目名称:exotrac,代码行数:26,代码来源:PyGIT.py


示例4: test_existing

 def test_existing(self):
     util.create_file(self.path, 'Some content')
     self.assertEqual('Some content', util.read_file(self.path))
     with util.AtomicFile(self.path) as f:
         f.write('Some new content')
     self.assertEqual(True, f.closed)
     self.assertEqual('Some new content', util.read_file(self.path))
开发者ID:Stackato-Apps,项目名称:bloodhound,代码行数:7,代码来源:__init__.py


示例5: runTest

    def runTest(self):
        env = self._testenv.get_trac_environment()
        env.config.set('components', 'RaiseExceptionPlugin.*', 'enabled')
        env.config.save()
        create_file(os.path.join(env.path, 'plugins', 'RaiseExceptionPlugin.py'),
"""\
from trac.core import Component, implements
from trac.web.api import IRequestHandler

url = 'http://trac-hacks.org/wiki/HelloWorldMacro'

class RaiseExceptionPlugin(Component):
    implements(IRequestHandler)

    def match_request(self, req):
        if req.path_info == '/raise-exception':
            return True

    def process_request(self, req):
        raise Exception

""")

        try:
            tc.go(self._tester.url + '/raise-exception')
            tc.find(internal_error)
            tc.find('<form class="newticket" method="get" '
                    'action="http://trac-hacks.org/newticket">')
            tc.find('<input type="hidden" name="component" '
                    'value="HelloWorldMacro" />')
        finally:
            env.config.set('components', 'RaiseExceptionPlugin.*', 'disabled')
开发者ID:pkdevbox,项目名称:trac,代码行数:32,代码来源:testcases.py


示例6: test_sync

    def test_sync(self):
        self._git_init()
        for idx in xrange(3):
            filename = 'file%d.txt' % idx
            create_file(os.path.join(self.repos_path, filename))
            self._git('add', filename)
            self._git_commit('-a', '-m', filename,
                             date=datetime(2014, 2, 2, 17, 12, idx))
        self._add_repository('gitrepos')
        repos = self._repomgr.get_repository('gitrepos')
        revs = [entry[1] for entry in repos.repos.get_node('').get_history()]
        revs.reverse()
        revs2 = []
        def feedback(rev):
            revs2.append(rev)
        repos.sync(feedback=feedback)
        self.assertEqual(revs, revs2)
        self.assertEqual(4, len(revs2))

        revs2 = []
        def feedback_1(rev):
            revs2.append(rev)
            if len(revs2) == 2:
                raise StopSync
        def feedback_2(rev):
            revs2.append(rev)
        try:
            repos.sync(feedback=feedback_1, clean=True)
        except StopSync:
            self.assertEqual(revs[:2], revs2)
            repos.sync(feedback=feedback_2)  # restart sync
        self.assertEqual(revs, revs2)
开发者ID:exocad,项目名称:exotrac,代码行数:32,代码来源:git_fs.py


示例7: test_coarse_permissions

    def test_coarse_permissions(self):
        # Granted to all due to wildcard
        self.assertPathPerm(True, 'unknown')
        self.assertPathPerm(True, 'joe')
        self.assertRevPerm(True, 'unknown')
        self.assertRevPerm(True, 'joe')
        # Granted if at least one fine permission is granted
        self.policy._mtime = 0
        create_file(self.authz, """\
[/somepath]
joe = r
denied =
[module:/otherpath]
jane = r
$anonymous = r
[inactive:/not-in-this-instance]
unknown = r
""")
        self.assertPathPerm(None, 'unknown')
        self.assertRevPerm(None, 'unknown')
        self.assertPathPerm(None, 'denied')
        self.assertRevPerm(None, 'denied')
        self.assertPathPerm(True, 'joe')
        self.assertRevPerm(True, 'joe')
        self.assertPathPerm(True, 'jane')
        self.assertRevPerm(True, 'jane')
        self.assertPathPerm(True, 'anonymous')
        self.assertRevPerm(True, 'anonymous')
开发者ID:exocad,项目名称:exotrac,代码行数:28,代码来源:svn_authz.py


示例8: _test_timerange

    def _test_timerange(self, cached_repository):
        self.env.config.set('git', 'cached_repository', cached_repository)

        self._git_init()
        filename = os.path.join(self.repos_path, '.gitignore')
        start = datetime(2000, 1, 1, 0, 0, 0, 0, utc)
        ts = datetime(2014, 2, 5, 15, 24, 6, 0, utc)
        for idx in xrange(3):
            create_file(filename, 'commit-%d.txt' % idx)
            self._git_commit('-a', '-m', 'commit %d' % idx, date=ts)
        self._add_repository()
        repos = self._repomgr.get_repository('gitrepos')
        repos.sync()

        revs = [repos.youngest_rev]
        while True:
            parents = repos.parent_revs(revs[-1])
            if not parents:
                break
            revs.extend(parents)
        self.assertEqual(4, len(revs))

        csets = list(repos.get_changesets(start, ts))
        self.assertEqual(1, len(csets))
        self.assertEqual(revs[-1], csets[0].rev)  # is oldest rev

        csets = list(repos.get_changesets(start, ts + timedelta(seconds=1)))
        self.assertEqual(revs, [cset.rev for cset in csets])
开发者ID:exocad,项目名称:exotrac,代码行数:28,代码来源:git_fs.py


示例9: setUp

 def setUp(self):
     self.parent_dir = tempfile.mkdtemp(prefix="trac-")
     self.tracignore = os.path.join(self.parent_dir, ".tracignore")
     for dname in self.dirs:
         os.mkdir(os.path.join(self.parent_dir, dname))
     for fname in self.files:
         create_file(os.path.join(self.parent_dir, fname))
     self.environ = {"trac.env_paths": [], "trac.env_parent_dir": self.parent_dir}
开发者ID:dafrito,项目名称:trac-mirror,代码行数:8,代码来源:main.py


示例10: test_parse_authz_malformed_raises

    def test_parse_authz_malformed_raises(self):
        """ConfigurationError should be raised if the file is malformed."""
        create_file(self.authz_file, """\
wiki:WikiStart]
änon = WIKI_VIEW
* =
""")
        authz_policy = AuthzPolicy(self.env)
        self.assertRaises(ConfigurationError, authz_policy.parse_authz)
开发者ID:pkdevbox,项目名称:trac,代码行数:9,代码来源:authz_policy.py


示例11: setUp

 def setUp(self):
     self.status = None
     self.headers = None
     self.response = StringIO()
     self.dir = tempfile.mkdtemp(prefix='trac-')
     self.filename = os.path.join(self.dir, 'test.txt')
     self.data = 'contents\n'
     create_file(self.filename, self.data, 'wb')
     self.req = None
开发者ID:pkdevbox,项目名称:trac,代码行数:9,代码来源:api.py


示例12: test_migrate_with_plugin_py_to_sqlite_env

 def test_migrate_with_plugin_py_to_sqlite_env(self):
     dburi = get_dburi()
     if dburi == 'sqlite::memory:':
         dburi = 'sqlite:db/trac.db'
     self._create_env(self.src_path, dburi)
     plugin_name = self._generate_module_name() + '.py'
     create_file(os.path.join(self.src_path, 'plugins', plugin_name),
                 _plugin_py)
     self._test_migrate_with_plugin_to_sqlite_env()
开发者ID:jun66j5,项目名称:tracmigrateplugin,代码行数:9,代码来源:admin.py


示例13: test_existing

 def test_existing(self):
     util.create_file(self.path, 'Some content')
     self.assertEqual('Some content', util.read_file(self.path))
     f = util.AtomicFile(self.path)
     try:
         f.write('Some new content')
     finally:
         f.close()
     self.assertEqual('Some new content', util.read_file(self.path))
开发者ID:wiraqutra,项目名称:photrackjp,代码行数:9,代码来源:__init__.py


示例14: test_existing_open_for_reading

 def test_existing_open_for_reading(self):
     util.create_file(self.path, 'Initial file content')
     self.assertEqual('Initial file content', util.read_file(self.path))
     with open(self.path) as rf:
         with util.AtomicFile(self.path) as f:
             f.write('Replaced content')
     self.assertEqual(True, rf.closed)
     self.assertEqual(True, f.closed)
     self.assertEqual('Replaced content', util.read_file(self.path))
开发者ID:Stackato-Apps,项目名称:bloodhound,代码行数:9,代码来源:__init__.py


示例15: setUp

 def setUp(self):
     self.env = EnvironmentStub()
     self.repos_path = tempfile.mkdtemp(prefix='trac-gitrepos')
     self.git_bin = locate('git')
     # create git repository and master branch
     self._git('init', self.repos_path)
     create_file(os.path.join(self.repos_path, '.gitignore'))
     self._git('add', '.gitignore')
     self._git('commit', '-a', '-m', 'test')
开发者ID:Stackato-Apps,项目名称:bloodhound,代码行数:9,代码来源:PyGIT.py


示例16: test_parse_authz_no_settings

    def test_parse_authz_no_settings(self):
        """Allow the file to have no settings."""
        create_file(self.authz_file, """\
# [wiki:WikiStart]
# änon = WIKI_VIEW
# * =
""")
        authz_policy = AuthzPolicy(self.env)
        authz_policy.parse_authz()
        self.assertEqual([], authz_policy.authz.sections())
开发者ID:pkdevbox,项目名称:trac,代码行数:10,代码来源:authz_policy.py


示例17: setUp

 def setUp(self):
     self.parent_dir = tempfile.mkdtemp(prefix='trac-')
     self.tracignore = os.path.join(self.parent_dir, '.tracignore')
     for dname in self.dirs:
         os.mkdir(os.path.join(self.parent_dir, dname))
     for fname in self.files:
         create_file(os.path.join(self.parent_dir, fname))
     self.environ = {
        'trac.env_paths': [],
        'trac.env_parent_dir': self.parent_dir,
     }
开发者ID:moreati,项目名称:trac-gitsvn,代码行数:11,代码来源:main.py


示例18: test_unicode_filename

 def test_unicode_filename(self):
     create_file(os.path.join(self.repos_path, 'tickét.txt'))
     self._git('add', 'tickét.txt')
     self._git('commit', '-m', 'unicode-filename')
     storage = self._storage()
     filenames = sorted(fname for mode, type, sha, size, fname
                              in storage.ls_tree('HEAD'))
     self.assertEquals(unicode, type(filenames[0]))
     self.assertEquals(unicode, type(filenames[1]))
     self.assertEquals(u'.gitignore', filenames[0])
     self.assertEquals(u'tickét.txt', filenames[1])
开发者ID:Stackato-Apps,项目名称:bloodhound,代码行数:11,代码来源:PyGIT.py


示例19: test_shared_htdocs_dir_file_is_found

 def test_shared_htdocs_dir_file_is_found(self):
     from trac.web.api import RequestDone
     def send_file(path, mimetype):
         raise RequestDone
     req = Request(path_info='/chrome/shared/trac_logo.png',
                   send_file=send_file)
     shared_htdocs_dir = os.path.join(self.env.path, 'chrome', 'shared')
     os.makedirs(shared_htdocs_dir)
     create_file(os.path.join(shared_htdocs_dir, 'trac_logo.png'))
     self.env.config.set('inherit', 'htdocs_dir', shared_htdocs_dir)
     self.assertTrue(self.chrome.match_request(req))
     self.assertRaises(RequestDone, self.chrome.process_request, req)
开发者ID:exocad,项目名称:exotrac,代码行数:12,代码来源:chrome.py


示例20: test_turn_off_persistent_cache

    def test_turn_off_persistent_cache(self):
        # persistent_cache is enabled
        parent_rev = self._factory(False).getInstance().youngest_rev()

        create_file(os.path.join(self.repos_path, 'newfile.txt'))
        self._git('add', 'newfile.txt')
        self._git_commit('-m', 'test_turn_off_persistent_cache',
                         date=datetime(2014, 1, 29, 13, 13, 25))

        # persistent_cache is disabled
        rev = self._factory(True).getInstance().youngest_rev()
        self.assertNotEqual(rev, parent_rev)
开发者ID:exocad,项目名称:exotrac,代码行数:12,代码来源:PyGIT.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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