Commits

Florent Cayré committed 551fb0a

refactor hook code to ease reuse by other cubes

  • Participants
  • Parent commits 5bef2b4

Comments (0)

Files changed (2)

         if not exists:
             commands.add(ui, repo, access_conf_path)
 
-    def __call__(self):
-        repo_path = osp.join(self._cw.user.login, self.entity.name)
-        repo_url = self.hg_repo_url(repo_path, encoding=None)
-        # add vcsfile cube Repository instance
-        repo_dir_path = self.hg_repo_dir(repo_path)
-        self._cw.create_entity('Repository', title=self.entity.name,
-                               type=u'mercurial', source_url=repo_url,
-                               path=repo_dir_path, encoding=u'utf-8',
-                               import_revision_content=self.default_import_revision_content,
-                               reverse_vcsrepo=self.entity.eid)
+    def mercurial_server_setup(self, repo_url):
         # add access.conf entry if needed
         commit_msg = u'added access.conf entry for %s' % self._cw.user.login
         self.exec_in_hgadmin_clone(self.write_access_conf, commit_msg)
         finally:
             shutil.rmtree(new_repo_dir_path)
 
+    def __call__(self):
+        repo_path = osp.join(self._cw.user.login, self.entity.name)
+        repo_url = self.hg_repo_url(repo_path, encoding=None)
+        # add vcsfile cube Repository instance
+        repo_dir_path = self.hg_repo_dir(repo_path)
+        self.repo = self._cw.create_entity(
+            'Repository', title=self.entity.name,
+            type=u'mercurial', source_url=repo_url,
+            path=repo_dir_path, encoding=u'utf-8',
+            import_revision_content=self.default_import_revision_content,
+            reverse_vcsrepo=self.entity.eid)
+        self.mercurial_server_setup(repo_url)
 
 class MercurialServerRepoRenameHook(MercurialServerHookMixin, Hook):
     """rename mercurial server repository when the entity's name changes"""

test/unittest_mercurial_server.py

         self.commit()
         msr.set_attributes(name=u'mytest2')
         self.commit()
-        self.failUnless(osp.isdir(osp.join(self.base_path, 'repos', 'admin', 'mytest2')),
+        self.assertTrue(osp.isdir(osp.join(self.base_path, 'repos', 'admin', 'mytest2')),
                         'renamed repo not found!')