当前位置: 首页>>代码示例>>Python>>正文


Python util.create_file函数代码示例

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


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


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