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


Python commands.init函数代码示例

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


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

示例1: test_file_only_copied

    def test_file_only_copied(self):
        """Change by copying a file with no content editing"""
        ui = mock_ui()
        hgcommands.init(ui, self.repo)

        hgrepo = repository(ui, self.repo)
        (
            open(hgrepo.pathto("file.dtd"), "w").write(
                """
             <!ENTITY key1 "Hello">
             <!ENTITY key2 "Cruel">
             """
            )
        )
        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui, hgrepo, user="Jane Doe <[email protected]>", message="initial commit")
        rev0 = hgrepo[0].hex()
        hgcommands.copy(ui, hgrepo, hgrepo.pathto("file.dtd"), hgrepo.pathto("newnamefile.dtd"))
        hgcommands.commit(ui, hgrepo, user="Jane Doe <[email protected]>", message="Second commit")
        rev1 = hgrepo[1].hex()

        Repository.objects.create(name=self.repo_name, url="http://localhost:8001/%s/" % self.repo_name)

        url = reverse("pushes.views.diff")
        response = self.client.get(url, {"repo": self.repo_name, "from": rev0, "to": rev1})
        eq_(response.status_code, 200)
        html_diff = response.content.split("Changed files:")[1]
        ok_("copied from file.dtd" in re.sub("<.*?>", "", html_diff))
        ok_(re.findall(">\s*newnamefile\.dtd\s*<", html_diff))
        ok_(not re.findall(">\s*Hello\s*<", html_diff))
        ok_(not re.findall(">\s*Cruel\s*<", html_diff))
开发者ID:gerv,项目名称:elmo,代码行数:31,代码来源:tests.py

示例2: test_remove_file

    def test_remove_file(self):
        """Change by removing a file, with parser"""
        ui = mock_ui()

        hgcommands.init(ui, self.repo)
        hgrepo = repository(ui, self.repo)
        (
            open(hgrepo.pathto("file.dtd"), "w").write(
                """
             <!ENTITY key1 "Hello">
             <!ENTITY key2 "Cruel">
             """
            )
        )

        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui, hgrepo, user="Jane Doe <[email protected]>", message="initial commit")
        rev0 = hgrepo[0].hex()
        hgcommands.remove(ui, hgrepo, "path:file.dtd")
        hgcommands.commit(ui, hgrepo, user="Jane Doe <[email protected]>", message="Second commit")
        rev1 = hgrepo[1].hex()

        Repository.objects.create(name=self.repo_name, url="http://localhost:8001/%s/" % self.repo_name)

        url = reverse("pushes.views.diff")
        response = self.client.get(url, {"repo": self.repo_name, "from": rev0, "to": rev1})
        eq_(response.status_code, 200)
        html_diff = response.content.split("Changed files:")[1]
        ok_(re.findall(">\s*file\.dtd\s*<", html_diff))
        # 2 entities with 2 rows each
        eq_(html_diff.count('<tr class="line-removed">'), 4)
        ok_(re.findall(">\s*key1\s*<", html_diff))
        ok_(re.findall(">\s*Hello\s*<", html_diff))
        ok_(re.findall(">\s*key2\s*<", html_diff))
        ok_(re.findall(">\s*Cruel\s*<", html_diff))
开发者ID:gerv,项目名称:elmo,代码行数:35,代码来源:tests.py

示例3: test_remove_file_no_parser

    def test_remove_file_no_parser(self):
        """Change by removing a file, without parser"""
        ui = mock_ui()

        hgcommands.init(ui, self.repo)
        hgrepo = repository(ui, self.repo)
        (open(hgrepo.pathto("file.txt"), "w").write("line 1\nline 2\n"))

        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui, hgrepo, user="Jane Doe <[email protected]>", message="initial commit")
        rev0 = hgrepo[0].hex()
        hgcommands.remove(ui, hgrepo, "path:file.txt")
        hgcommands.commit(ui, hgrepo, user="Jane Doe <[email protected]>", message="Second commit")
        rev1 = hgrepo[1].hex()

        repo_url = "http://localhost:8001/%s/" % self.repo_name
        Repository.objects.create(name=self.repo_name, url=repo_url)

        url = reverse("pushes.views.diff")
        response = self.client.get(url, {"repo": self.repo_name, "from": rev0, "to": rev1})
        eq_(response.status_code, 200)
        html_diff = response.content.split("Changed files:")[1]
        ok_(re.findall(">\s*file\.txt\s*<", html_diff))
        # 1 removed file
        eq_(html_diff.count('<div class="diff file-removed">'), 1)
        # also, expect a link to the old revision of the file
        change_ref = 'href="%sfile/%s/file.txt"' % (repo_url, rev0)
        ok_(change_ref in html_diff)
        ok_(not re.findall(">\s*line 1\s*<", html_diff))
        ok_(not re.findall(">\s*line 2\s*<", html_diff))
开发者ID:gerv,项目名称:elmo,代码行数:30,代码来源:tests.py

示例4: test_handlePushes_space_files

    def test_handlePushes_space_files(self):
        repo = Repository.objects.create(name="mozilla-central", url="file:///" + self.repo)
        self.assertEqual(handlePushes(repo.pk, []), None)

        ui = mock_ui()

        hgcommands.init(ui, self.repo)
        hgrepo = repository(ui, self.repo)
        (
            open(hgrepo.pathto("file.dtd "), "w").write(  # deliberate trailing space
                """
             <!ENTITY key1 "Hello">
             <!ENTITY key2 "Cruel">
             """
            )
        )

        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui, hgrepo, user="Jane Doe <[email protected]>", message="initial commit")
        rev0 = hgrepo[0].hex()

        timestamp = int(time.time())
        pushjs0 = PushJS(100, {"date": timestamp, "changesets": [rev0], "user": "jdoe"})
        handlePushes(repo.pk, [pushjs0])

        file_, = File.objects.all()
        self.assertEqual(file_.path, "file.dtd ")
开发者ID:gerv,项目名称:elmo,代码行数:27,代码来源:tests.py

示例5: test_file_edited_broken_encoding

    def test_file_edited_broken_encoding(self):
        """Change by editing a good with a broken edit"""
        ui = mock_ui()
        hgcommands.init(ui, self.repo)
        hgrepo = repository(ui, self.repo)

        (open(hgrepo.pathto("file.dtd"), "w").write(u'<!ENTITY key1 "Hello">\n'))

        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui, hgrepo, user="Jane Doe <[email protected]>", message="initial commit")
        rev0 = hgrepo[0].hex()

        # do this to trigger an exception on Mozilla.Parser.readContents
        _content = u'<!ENTITY key1 "Hell\xe3">\n'
        (codecs.open(hgrepo.pathto("file.dtd"), "w", "latin1").write(_content))

        hgcommands.commit(ui, hgrepo, user="Jane Doe <[email protected]>", message="Second commit")
        rev1 = hgrepo[1].hex()

        repo_url = "http://localhost:8001/" + self.repo_name + "/"
        Repository.objects.create(name=self.repo_name, url=repo_url)

        url = reverse("pushes.views.diff")
        response = self.client.get(url, {"repo": self.repo_name, "from": rev0, "to": rev1})
        eq_(response.status_code, 200)
        html_diff = response.content.split("Changed files:")[1]
        ok_("Cannot parse file" in html_diff)
        # also, expect a link to this file
        change_url = repo_url + "file/%s/file.dtd" % rev1
        ok_('href="%s"' % change_url in html_diff)
开发者ID:gerv,项目名称:elmo,代码行数:30,代码来源:tests.py

示例6: _upgrade

def _upgrade(ui, repo):
    ext_dir = os.path.dirname(os.path.abspath(__file__))
    ui.debug(_('kiln: checking for extensions upgrade for %s\n') % ext_dir)

    try:
        r = localrepo.localrepository(hgui.ui(), ext_dir)
    except RepoError:
        commands.init(hgui.ui(), dest=ext_dir)
        r = localrepo.localrepository(hgui.ui(), ext_dir)

    r.ui.setconfig('kiln', 'autoupdate', False)
    r.ui.pushbuffer()
    try:
        source = 'https://developers.kilnhg.com/Repo/Kiln/Group/Kiln-Extensions'
        if commands.incoming(r.ui, r, bundle=None, force=False, source=source) != 0:
            # no incoming changesets, or an error. Don't try to upgrade.
            ui.debug('kiln: no extensions upgrade available\n')
            return
        ui.write(_('updating Kiln Extensions at %s... ') % ext_dir)
        # pull and update return falsy values on success
        if commands.pull(r.ui, r, source=source) or commands.update(r.ui, r, clean=True):
            url = urljoin(repo.url()[:repo.url().lower().index('/repo')], 'Tools')
            ui.write(_('unable to update\nvisit %s to download the newest extensions\n') % url)
        else:
            ui.write(_('complete\n'))
    except Exception, e:
        ui.debug(_('kiln: error updating extensions: %s\n') % e)
        ui.debug(_('kiln: traceback: %s\n') % traceback.format_exc())
开发者ID:szechyjs,项目名称:dotfiles,代码行数:28,代码来源:kiln.py

示例7: test_handlePushes_repeated

    def test_handlePushes_repeated(self):
        repo = Repository.objects.create(name="mozilla-central", url="file:///" + self.repo)
        self.assertEqual(handlePushes(repo.pk, []), None)

        ui = mock_ui()

        hgcommands.init(ui, self.repo)
        hgrepo = repository(ui, self.repo)
        (
            open(hgrepo.pathto("file.dtd"), "w").write(
                """
             <!ENTITY key1 "Hello">
             <!ENTITY key2 "Cruel">
             """
            )
        )

        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui, hgrepo, user="Jane Doe <[email protected]>", message="initial commit")
        rev0 = hgrepo[0].hex()

        timestamp = int(time.time())
        pushjs0 = PushJS(100, {"date": timestamp, "changesets": [rev0], "user": "jdoe"})
        # first time
        pushes_initial = Push.objects.all().count()
        result = handlePushes(repo.pk, [pushjs0])
        self.assertEqual(result, 1)
        pushes_after = Push.objects.all().count()
        self.assertEqual(pushes_initial, pushes_after - 1)

        # a second time should be harmless
        result = handlePushes(repo.pk, [pushjs0])
        self.assertEqual(result, 1)
        pushes_after_after = Push.objects.all().count()
        self.assertEqual(pushes_after, pushes_after_after)
开发者ID:gerv,项目名称:elmo,代码行数:35,代码来源:tests.py

示例8: test_handlePushes_space_files

    def test_handlePushes_space_files(self):
        repo = Repository.objects.create(
          name='mozilla-central',
          url='file:///' + self.repo
        )
        self.assertEqual(handlePushes(repo.pk, []), None)

        ui = mock_ui()

        hgcommands.init(ui, self.repo)
        hgrepo = repository(ui, self.repo)
        (open(hgrepo.pathto('file.dtd '), 'w')  # deliberate trailing space
             .write('''
             <!ENTITY key1 "Hello">
             <!ENTITY key2 "Cruel">
             '''))

        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui, hgrepo,
                  user="Jane Doe <[email protected]>",
                  message="initial commit")
        rev0 = hgrepo[0].hex()

        timestamp = int(time.time())
        pushjs0 = PushJS(100, {
          'date': timestamp,
          'changesets': [rev0],
          'user': 'jdoe',
        })
        handlePushes(repo.pk, [pushjs0])

        file_, = File.objects.all()
        self.assertEqual(file_.path, 'file.dtd ')
开发者ID:Archaeopteryx,项目名称:elmo,代码行数:33,代码来源:test_pushes.py

示例9: test_handlePushes_cause_repoerror

    def test_handlePushes_cause_repoerror(self):
        repo = Repository.objects.create(
          name='mozilla-central',
          url='file:///does/not/exist'
        )
        self.assertEqual(handlePushes(repo.pk, []), None)

        ui = mock_ui()

        hgcommands.init(ui, self.repo)
        hgrepo = repository(ui, self.repo)
        (open(hgrepo.pathto('file.dtd'), 'w')
             .write('''
             <!ENTITY key1 "Hello">
             <!ENTITY key2 "Cruel">
             '''))

        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui, hgrepo,
                  user="Jane Doe <[email protected]>",
                  message="initial commit")
        rev0 = hgrepo[0].hex()

        timestamp = int(time.time())
        pushjs0 = PushJS(100, {
          'date': timestamp,
          'changesets': [rev0],
          'user': 'jdoe',
        })
        self.assertRaises(RepoError, handlePushes,
                          repo.pk, [pushjs0])
开发者ID:Archaeopteryx,项目名称:elmo,代码行数:31,代码来源:test_pushes.py

示例10: setUp

    def setUp(self):
        self.repo_path = mkdtemp()
        self.ui = ui.ui()
        self.ui.setconfig('ui', 'username', 'foo <[email protected]>')
        self.ui.setconfig('ui', 'quiet', True)
        commands.init(self.ui, self.repo_path)
        self.repo = hg.repository(self.ui, self.repo_path)
        file_dir = os.path.join(self.repo_path, 'content')
        if not os.path.isdir(file_dir):
            os.makedirs(file_dir)
        for i in range(3):
            file_path = os.path.join(file_dir, 'page-%i.rst' % i)
            with codecs.open(file_path, 'w', encoding='utf-8') as fp:
                fp.write(SAMPLE_PAGE)
            commands.add(self.ui, self.repo, file_path)
        file_path = os.path.join(file_dir, 'about.rst')
        with codecs.open(file_path, 'w', encoding='utf-8') as fp:
            fp.write(SAMPLE_PAGE + """
.. aliases: 301:/my-old-post-location/,/another-old-location/""")
        commands.add(self.ui, self.repo, file_path)
        file_dir = os.path.join(self.repo_path, 'content', 'post')
        if not os.path.isdir(file_dir):
            os.makedirs(file_dir)
        for i in range(3):
            file_path = os.path.join(file_dir, 'post-%i.rst' % i)
            with codecs.open(file_path, 'w', encoding='utf-8') as fp:
                fp.write(SAMPLE_POST)
            commands.add(self.ui, self.repo, file_path)
        file_path = os.path.join(file_dir, 'foo.rst')
        with codecs.open(file_path, 'w', encoding='utf-8') as fp:
            # using the page template, because we want to set tags manually
            fp.write(SAMPLE_PAGE + """
.. tags: foo, bar, lol""")
        commands.add(self.ui, self.repo, file_path)
        commands.commit(self.ui, self.repo, message='foo', user='foo')
开发者ID:GoGoBunny,项目名称:blohg,代码行数:35,代码来源:models.py

示例11: test_error_handling

    def test_error_handling(self):
        """Test various bad request parameters to the diff_app
        and assure that it responds with the right error codes."""
        ui = mock_ui()
        hgcommands.init(ui, self.repo)

        url = reverse("pushes.views.diff")
        response = self.client.get(url, {})
        eq_(response.status_code, 400)
        response = self.client.get(url, {"repo": "junk"})
        eq_(response.status_code, 404)

        hgrepo = repository(ui, self.repo)
        (
            open(hgrepo.pathto("file.dtd"), "w").write(
                """
             <!ENTITY key1 "Hello">
             <!ENTITY key2 "Cruel">
             """
            )
        )
        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui, hgrepo, user="Jane Doe <[email protected]>", message="initial commit")
        rev0 = hgrepo[0].hex()

        Repository.objects.create(name=self.repo_name, url="http://localhost:8001/%s/" % self.repo_name)

        # missing 'from' and 'to'
        response = self.client.get(url, {"repo": self.repo_name})
        eq_(response.status_code, 400)

        # missing 'to'
        response = self.client.get(url, {"repo": self.repo_name, "from": rev0})
        eq_(response.status_code, 400)
开发者ID:gerv,项目名称:elmo,代码行数:34,代码来源:tests.py

示例12: init

 def init(cls, path):
     if os.path.isdir(path):
         shutil.rmtree(path)
     os.mkdir(path)
     ui = cls._ui()
     hgcommands.init(ui, path)
     return repository(ui, path)
开发者ID:flodolo,项目名称:elmo,代码行数:7,代码来源:repo_fixtures.py

示例13: test_handlePushes_twice

    def test_handlePushes_twice(self):
        repo = Repository.objects.create(
          name='mozilla-central',
          url='file://' + self.repo
        )

        ui = mock_ui()
        hgcommands.init(ui, self.repo)
        hgrepo = repository(ui, self.repo)
        (open(hgrepo.pathto('file.dtd'), 'w')
             .write('''
             <!ENTITY key1 "Hello">
             <!ENTITY key2 "Cruel">
             '''))

        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui, hgrepo,
                  user="Jane Doe <[email protected]>",
                  message="initial commit")
        rev0 = hgrepo[0].hex()

        timestamp = int(time.time())
        pushjs0 = PushJS(100, {
          'date': timestamp,
          'changesets': [rev0],
          'user': 'jdoe',
        })
        result = handlePushes(repo.pk, [pushjs0])

        (open(hgrepo.pathto('file.dtd'), 'w')
             .write('''
             <!ENTITY key1 "Hello">
             <!ENTITY key2 "Cruel">
             <!ENTITY key3 "World">
             '''))
        hgcommands.commit(ui, hgrepo,
                  user="Jane Doe <[email protected]>",
                  message="Second commit")
        rev1 = hgrepo[1].hex()

        # a second time
        timestamp = int(time.time())
        pushjs0 = PushJS(101, {
          'date': timestamp,
          'changesets': [rev1],
          'user': 'jdoe',
        })

        # re-fetch
        repo = Repository.objects.get(pk=repo.pk)
        self.assertEqual(repo.changesets.all().count(), 2)

        result = handlePushes(repo.pk, [pushjs0])
        self.assertEqual(result, 1)

        # re-fetch
        repo = Repository.objects.get(pk=repo.pk)
        self.assertEqual(repo.changesets.all().count(), 3)
开发者ID:Archaeopteryx,项目名称:elmo,代码行数:58,代码来源:test_pushes.py

示例14: test_diff_base_against_clone

    def test_diff_base_against_clone(self):
        """Test that the right error is raised on trying to do a diff across
        a different divergant clone"""
        ui = mock_ui()
        orig = os.path.join(settings.REPOSITORY_BASE, "orig")
        clone = os.path.join(settings.REPOSITORY_BASE, "clone")
        hgcommands.init(ui, orig)
        hgorig = repository(ui, orig)
        (
            open(hgorig.pathto("file.dtd"), "w").write(
                """
          <!ENTITY old "content we will delete">
          <!ENTITY mod "this has stuff to keep and delete">
        """
            )
        )
        hgcommands.addremove(ui, hgorig)
        hgcommands.commit(ui, hgorig, user="Jane Doe <[email protected]", message="initial commit")
        assert len(hgorig) == 1  # 1 commit

        # set up a second repo called 'clone'
        hgcommands.clone(ui, orig, clone)
        hgclone = repository(ui, clone)

        # new commit on base
        (
            open(hgorig.pathto("file.dtd"), "w").write(
                """
         <!ENTITY mod "this has stuff to keep and add">
         <!ENTITY new "this has stuff that is new">
         """
            )
        )
        hgcommands.commit(ui, hgorig, user="Jane Doe <[email protected]", message="second commit on base")
        assert len(hgorig) == 2  # 2 commits
        rev_from = hgorig[1].hex()

        # different commit on clone
        (
            open(hgclone.pathto("file.dtd"), "w").write(
                """
         <!ENTITY mod "this has stuff to keep and change">
         <!ENTITY new_in_clone "this has stuff that is different from base">
         """
            )
        )
        hgcommands.commit(ui, hgclone, user="John Doe <[email protected]", message="a different commit on clone")
        rev_to = hgclone[1].hex()

        Repository.objects.create(name="orig", url="http://localhost:8001/orig/")
        Repository.objects.create(name="clone", url="http://localhost:8001/clone/")

        url = reverse("pushes.views.diff")
        # right now, we can't diff between repos, this might change!
        self.assertRaises(RepoError, self.client.get, url, {"repo": "clone", "from": rev_from[:12], "to": rev_to[:12]})
开发者ID:gerv,项目名称:elmo,代码行数:55,代码来源:tests.py

示例15: setUp

 def setUp(self):
     self.repo_path = mkdtemp()
     self.ui = ui.ui()
     self.ui.setconfig('ui', 'quiet', True)
     commands.init(self.ui, self.repo_path)
     self.file_name = 'foo.rst'
     self.file_path = os.path.join(self.repo_path, self.file_name)
     with codecs.open(self.file_path, 'w', encoding='utf-8') as fp:
         fp.write('test\n')
     self.repo = hg.repository(self.ui, self.repo_path)
     self.changectx = self.repo[None]
     commands.commit(self.ui, self.repo, message='foo',
                     user='foo <[email protected]>', addremove=True)
开发者ID:GoGoBunny,项目名称:blohg,代码行数:13,代码来源:filectx.py


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