Exemplo n.º 1
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)
Exemplo n.º 2
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)
Exemplo n.º 3
0
    def getblogfeed(self):
        """Returns the current rss feed url associated with a user. If
		the user has not previously registered a url, it will return a
		blank string.
		"""
        #get the current user
        cur_user = str(srusers.get_curuser())
        if cur_user == None:
            return dict(feedurl="", valid=0, error=1)

        # grab the sql record for the user, if it exists and extract the url
        try:
            r = model.UserBlogFeeds.selectBy(user=cur_user)
            try:
                row = r.getOne()
            except:
                # the record doesn't exist, return blank
                return dict(feedurl="", valid=0, checked=0, error=0)
        except:
            # the record doesn't exist, return blank
            return dict(feedurl="", valid=0, checked=0, error=0)
        # success, return url
        return dict(feedurl=row.url,
                    valid=int(row.valid),
                    checked=int(row.checked),
                    error=0)
Exemplo n.º 4
0
    def setblogfeed(self, feedurl):
        """Returns the new rss feed url associated with a user. If
		the user has not previously registered a url, it will assign a
		new row in the table, else it will update their existing entry.	
		"""
        #get the current user
        cur_user = srusers.get_curuser()

        # grab the sql record, edit the url, commit it
        try:
            r = model.UserBlogFeeds.selectBy(user=cur_user)
            try:
                row = r.getOne()
                if feedurl != row.url:
                    row.valid = False  # will need to be re-validated
                    row.url = feedurl
                    row.set()
                else:
                    pass  #nothing to update
            except:
                # user doen't have an entry yet, so create one
                if r.count() == 0:
                    new_row = model.UserBlogFeeds(user=cur_user,
                                                  url=feedurl,
                                                  valid=False)
                    new_row.set()
                    return dict(feedurl=new_row.url,
                                valid=int(new_row.valid),
                                error=0)
        except:
            return dict(feedurl="", valid=0, error=1)
        else:
            return dict(feedurl=row.url, valid=int(row.valid), error=0)
Exemplo n.º 5
0
    def commit(self, message=""):
        """
        Commit changed tree.
        Returns a tuple of revno, revid
        """
        last_revno, last_revid = self.b.last_revision_info()

        if not self.revid == last_revid:
            raise bzrlib.errors.OutOfDateTree(
                self.PrevTree)  # cannot commit, tree not up to date
        if not len(self.conflicts) == 0:
            return None  # cannot commit, conflicts remain

        # get commiter username
        ide_user = str(srusers.get_curuser())

        self.b = bzrlib.branch.Branch.open(self.b.base)
        self.b.lock_write()

        try:
            if hasattr(self.PrevTree, "commit"):
                # As of bzr 1.18 PreviewTrees have built-in commit method.
                #self.PrevTree.set_parent_ids([ self.revid ]) # needed here?
                revid_new = self.PrevTree.commit(message)  # TODO: add author
            else:
                if last_revid == bzrlib.revision.NULL_REVISION:
                    parent_ids = []  # no existing commits on this branch
                else:
                    parent_ids = [self.revid]
                revprops = {"branch-nick": self.b.nick}  # is this necessary?
                builder = self.b.get_commit_builder(parent_ids,
                                                    revprops=revprops,
                                                    committer=ide_user)

                changes = list(
                    builder.record_iter_changes(self.PrevTree, self.revid,
                                                self.TransPrev.iter_changes()))
                builder.finish_inventory()
                revid_new = builder.commit(message)
                revno_new = last_revno + 1
                self.b.set_last_revision_info(revno_new, revid_new)
        finally:
            # always unlock branch
            # NOTE: an exception during unlock() here can mask other exceptions during try,
            # so try:unlock to absorb this and allow original exception through.
            # TODO: more elegant solution
            try:
                self.b.unlock()
            except:
                pass

        self.revid = revid_new
        # should we delete TransPrev as it is no longer up to date?
        return revno_new, revid_new
Exemplo n.º 6
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)
Exemplo n.º 7
0
    def savefile(self, team, path, content, rev):
        src_rev = int(rev)
        src_team = int(team)
        user = str(srusers.get_curuser())

        exists_test = model.AND(model.AutoSave.q.file_path == path,
                        model.AutoSave.q.team_id == src_team,
                        model.AutoSave.q.uname == user)

        files = model.AutoSave.select(exists_test)

        if files.count() > 0 :  #if it exists we're doing an update, else we need a new file
            save = files[0]
            save.set(file_path = path, revision = src_rev, team_id = src_team, uname = user, content = content)
        else:
            save = model.AutoSave(file_path = path, revision = src_rev, team_id = src_team, uname = user, content = content)

        return { 'date' : save.date, 'code' : save.content }
Exemplo n.º 8
0
 def info(self):
     info = dict(Version=self.version, User=str(srusers.get_curuser()))
     return dict(info=info)