コード例 #1
0
    def checkcode(self, team, path, code=0, date=None):

        project, file_path = self.get_project_path(path)
        path, file_name = os.path.split(path)

        # Check out the code
        wt = WorkingTree(int(team), project)
        # Directory we're working in
        td = wt.tmpdir

        if code != 0:  #overwrite the version from the repo
            print td + os.path.sep + file_path
            tmpfile = open(td + os.path.sep + file_path, 'w')
            tmpfile.write(str(code))
            tmpfile.close()

        print 'temp_dir: ' + td + "\nfile_path: " + file_path

        # Check out the dummified SR library too
        shutil.copy(config.get("checker.file"), td)

        # Run pychecker
        p = subprocess.Popen(
            ["pylint", "-e", "-f", "parseable", "--reports=n", file_path],
            cwd=td,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE)
        output = p.communicate()

        rval = p.wait()
        wt.destroy()

        if rval == 0:
            return dict(errors=0)
        else:
            chk_warnings = []
            chk_errors = []

            #pychecker outputs two parts: one warnings, one the processing resuls
            warn_part = output[0].split('\n')
            proc_part = output[1].split('\n')

            for line in warn_part:  #simply grab the lines of interest - we can do more in JS
                if not line in ['', '\n', 'Warnings...']:
                    chk_warnings.append(line)

            for line in proc_part:
                if not line in [
                        '', '\n',
                        'Processing ' + os.path.splitext(file_path)[0] + '...'
                ]:
                    chk_errors.append(line)

            return dict(messages=chk_warnings,
                        err=chk_errors,
                        path=path,
                        file=file_name,
                        errors=1)
コード例 #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 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)
コード例 #4
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)
        wt.commit('Move ' + src_path + ' to ' + dest_path)

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

        return dict(new_revision="0",
                    status="0",
                    message='Sucessfully moved file ' + src + ' to ' + dest)
コード例 #5
0
    def diff(self, team, file, rev, code=None):
        """
        This function returns the patch applied by a particular revision to a file.
        """
        if file[:9] == 'New File ':
            return dict(path=file, history=[])

        project, file = self.get_project_path(file)
        b = open_branch(int(team), project)

        if code == None:
            #the patch from a commit
            rev_id = b.revision_history()[int(rev) - 1]
            rev = b.repository.get_revision(rev_id)

            from cStringIO import StringIO
            from bzrlib import diff

            if len(rev.parent_ids) == 0:
                ancestor_id = bzrlib.revision.NULL_REVISION
            else:
                ancestor_id = rev.parent_ids[0]
            tree_1 = b.repository.revision_tree(ancestor_id)
            tree_2 = b.repository.revision_tree(rev_id)
            s = StringIO()
            diff.show_diff_trees(tree_1, tree_2, s, old_label='', new_label='')
            filediff = s.getvalue()

        else:
            #the current difference
            path, file_name = os.path.split(file)
            ancestor_id = b.last_revision()

            # Check out the code
            wt = WorkingTree(int(team), project)
            # Directory we're working in
            td = wt.tmpdir

            print td + os.path.sep + file
            tmpfile = open(td + os.path.sep + file, 'w')
            tmpfile.write(str(code))
            tmpfile.close()

            print 'temp_dir: ' + td + "\nfile: " + file

            # Run pychecker
            p = subprocess.Popen(['bzr', 'diff'],
                                 cwd=td,
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE)
            output = p.communicate()

            rval = p.wait()
            wt.destroy()

            if rval == 0:
                return dict()
            else:
                filediff = output[0]

        return dict(diff=filediff, oldrev=b.revision_id_to_revno(ancestor_id))
コード例 #6
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)