コード例 #1
0
    def delete(self, team, project, files, kind='SVN'):
        """
        Delete files from the repository, and prune empty directories.
        inputs: files - comma seperated list of paths
                kind - one of 'SVN' or 'AUTOSAVES'
        returns (json): Message - a message to show the user
        """

        if files != "":
            files = files.split(",")
            wt = WorkingTree(int(team), project)

            message = "Files deleted successfully: " + project + " >\n" + "\n".join(
                files)

            for f in files:
                self.autosave.delete(team, '/' + project + '/' + f)

            if kind == 'AUTOSAVES':
                return dict(Message="AutoSaves deleted successfully: \n" +
                            "\n".join(files))

            wt.remove(files)

            # find out current user
            ide_user = str(srusers.get_curuser())

            revproperties = {"authors": ide_user}
            wt.commit('Remove files: ' + ', '.join(files),
                      revprops=revproperties)
            wt.destroy()

            return dict(Message=message)
コード例 #2
0
    def revert(self, team, files, torev, message):

        file_list = files.split(',')
        if len(file_list) == 0:
            return dict(Message='Revert failed - no files specified', status=1)

        project, file = self.get_project_path(file_list[0])
        rev_spec = bzrlib.revisionspec.RevisionSpec.from_string(torev)
        file_list = [self.get_project_path(f)[1] for f in file_list]

        wt = WorkingTree(team, project)
        rev_tree = rev_spec.as_tree(wt.branch)

        wt.revert(file_list, rev_tree)

        # find out current user
        ide_user = str(srusers.get_curuser())

        revproperties = {"authors": ide_user}

        wt.commit(message, revprops=revproperties)
        newrev, id = wt.branch.last_revision_info()
        wt.destroy()

        return dict(new_revision=newrev,
                    code="",
                    success="Success !!!",
                    status=0)

        #from undelete
        return dict(fail=fail, success=','.join(success), status=status)
コード例 #3
0
    def move(self, team, src, dest, msg=""):
        #   the source and destination arguments may be directories or files
        #   directories rendered empty as a result of the move are automatically 'pruned'
        #   returns status = 0 on success

        src_proj, src_path = self.get_project_path(src)
        dest_proj, dest_path = self.get_project_path(dest)
        if src_proj != dest_proj:
            return dict(new_revision="0",
                        status="1",
                        message="Source and destination projects must match")

        wt = WorkingTree(int(team), src_proj)

        if not wt.has_filename(src_path):
            return dict(new_revision="0",
                        status="1",
                        message="Source file/folder doesn't exist: " + src)

        if not wt.has_filename(os.path.dirname(dest_path)):
            return dict(new_revision="0",
                        status="1",
                        message="Destination folder doesn't exist: " +
                        os.path.dirname(dest))

        if wt.has_filename(dest_path):
            return dict(new_revision="0",
                        status="1",
                        message="Destination already exists: " + dest)

        wt.rename_one(src_path, dest_path)

        # find out current user
        ide_user = str(srusers.get_curuser())

        revproperties = {"authors": ide_user}

        wt.commit('Move ' + src_path + ' to ' + dest_path,
                  revprops=revproperties)
        wt.destroy()

        self.autosave.move(team, src, dest)

        return dict(new_revision="0",
                    status="0",
                    message='Sucessfully moved file ' + src + ' to ' + dest)
コード例 #4
0
    def update_merge(self, team, project, filepath, rev, message, code):
        """Attempt to merge some file data with latest revision.
        1. Checkout the branch into a temporary directory
        2. Dump in the new file data
        3. Update file in working copy
        Then either:
        4. Return merge-flagged text if manual merge required
        or
        4. Commit file
        then always:
        5. Delete the temp directory
        """
        print "savefile: going down checkout2tmpdir route."

        #1. Get working tree of branch in temp dir
        wt = WorkingTree(int(team), project)
        reload = "false"

        #TODO: Check for path naugtiness trac#208
        path = os.path.dirname(filepath)
        basename = os.path.basename(filepath)
        fullpath = wt.tmpdir + "/" + filepath

        #2. Dump in the new file data
        target = open(fullpath, "wt")
        target.write(code)
        target.close()

        # try to update
        try:
            conflicts = wt.update()
        except:
            wt.destroy()
            return dict(code=code,
                        success="false",
                        file=filepath,
                        reloadfiles=reload)

#        print "conflicts: " + str(conflicts)
        if conflicts == 0:
            try:
                newrevid = wt.commit(message)
                success = "True"
            except:
                wt.destroy()
                return dict(code=code,
                            success="false",
                            file=filepath,
                            reloadfiles=reload)
        else:
            #Throw the new contents of the file back to the client for
            #tidying, then they can resubmit
            success = "Merge"
            #Grab the merged text.
            mergedfile = open(join(wt.tmpdir, basename), "rt")
            code = mergedfile.read()
            mergedfile.close()

        # find revision number from id
        newrevno = wt.branch.revision_id_to_revno(newrevid)

        #4. Destroy working tree checkout, remove the autosaves
        wt.destroy()
        self.autosave.delete(team, filepath)

        return dict(new_revision=str(newrevno),
                    code=code,
                    success=success,
                    file=filepath,
                    reloadfiles=reload)