Пример #1
0
def initial_create(tid, git_path, lfs, user):
    try:
        db_task = Task.objects.get(pk = tid)
        path_pattern = r"\[(.+)\]"
        path_search = re.search(path_pattern, git_path)
        path = None

        if path_search is not None:
            path = path_search.group(1)
            git_path = git_path[0:git_path.find(path) - 1].strip()
            path = os.path.join('/', path.strip())
        else:
            anno_file = re.sub(r'[\\/*?:"<>|\s]', '_', db_task.name)[:100]
            path = '/annotation/{}.zip'.format(anno_file)

        path = path[1:]
        _split = os.path.splitext(path)
        if len(_split) < 2 or _split[1] not in [".xml", ".zip"]:
            raise Exception("Only .xml and .zip formats are supported")

        db_git = GitData()
        db_git.url = git_path
        db_git.path = path
        db_git.task = db_task
        db_git.lfs = lfs

        try:
            _git = Git(db_git, db_task, db_task.owner)
            _git.init_repos()
            db_git.save()
        except git.exc.GitCommandError as ex:
            _have_no_access_exception(ex)
    except Exception as ex:
        slogger.task[tid].exception('exception occurred during git initial_create', exc_info = True)
        raise ex
Пример #2
0
    def test_init_repos(self):
        for git_rep_already_init in [True, False]:
            task = self._create_task(init_repos=git_rep_already_init)
            db_task = Task.objects.get(pk=task["id"])
            db_git = GitData()
            db_git.url = GIT_URL

            cvat_git = TestGit(db_git, db_task, self.user)
            cvat_git.init_repos()
            self.assertTrue(osp.isdir(osp.join(cvat_git.get_working_dir(), '.git')))
Пример #3
0
    def test_clone(self):
        task = self._create_task(init_repos=False)
        db_task = Task.objects.get(pk=task["id"])
        db_git = GitData()
        db_git.url = GIT_URL

        cvat_git = TestGit(db_git, db_task, self.user)
        cvat_git.clone()
        repo = cvat_git.get_rep()
        self.assertTrue(osp.isdir(osp.join(cvat_git.get_working_dir(), '.git')))
        self.assertTrue(len(repo.heads))
Пример #4
0
    def test_push(self):
        task = self._create_task(init_repos=True)
        db_task = Task.objects.get(pk=task["id"])
        db_git = GitData()
        db_git.url = GIT_URL
        db_git.path = "annotation.zip"
        db_git.sync_date = timezone.now()

        cvat_git = TestGit(db_git, db_task, self.user)
        cvat_git.set_rep()
        cvat_git.create_master_branch()
        self.add_file(cvat_git.get_cwd(), "file.txt")
        cvat_git.push(self.user, "", "", db_task, db_task.updated_date)
        self.assertFalse(cvat_git.get_rep().is_dirty())
Пример #5
0
    def test_git_create_master_branch(self):
        task = self._create_task(init_repos=True)
        db_task = Task.objects.get(pk=task["id"])
        db_git = GitData()
        db_git.url = GIT_URL

        cvat_git = TestGit(db_git, db_task, self.user)
        cvat_git.set_rep()
        cvat_git.create_master_branch()
        cwd = cvat_git.get_cwd()
        self.assertTrue(osp.isfile(osp.join(cwd, "README.md")))

        repo = cvat_git.get_rep()
        self.assertFalse(repo.is_dirty())
        self.assertTrue(len(repo.heads) == 1)
        self.assertTrue(repo.heads[0].name == "master")
Пример #6
0
 def setUp(self):
     self.client = APIClient()
     db_git = GitData()
     db_git.url = GIT_URL