Пример #1
0
 def __init__(self):
     self.text = None
     self.authors = Authors()
     self.cursors = Cursors()
     self.color = None
     self.user_id = None
     self.changeset = None
Пример #2
0
def run_api(args):
    log.debug("launched as API client")

    if not args.apikey:
        log.error("Missing API Key!")
        sys.exit(1)

    mypad = APIClient(args.apikey, "http://%s:%s/api" % (args.host,
                                                                   args.port))

    text = Text(Attributes(mypad, args.pad), Authors(), Cursors())
    idx = 0
    while True:
        try:
            cnt = int(mypad.getRevisionsCount(args.pad)["revisions"])
            if cnt+1 != idx:
                print chr(27) + "[2J" # clear screen
                print ""
Пример #3
0
def author(authorName):
    authorObj = Authors.getInstance()
    return authorObj.author(authorName)
Пример #4
0
def authors():
    headers = request.headers
    authorObj = Authors.getInstance()
    return authorObj.authorsPagedNEW(1,headers)  
Пример #5
0
def listAuthors():
    authorObj = Authors.getInstance()
    return authorObj.listAuthors()
Пример #6
0
from flask_cors import CORS

from Characters import Characters
from Authors import Authors
from Issues import Issues
from response_functions import responseFactory, sqlToDict
from database import database
from Search import searchFor

app = Flask(__name__)
CORS(app)


db = database.getInstance()
Characters(db)
Authors(db)
Issues(db)


@app.route('/listIssues')
def listIssues():
    issueObj = Issues.getInstance()
    return issueObj.listIssues()



@app.route('/listAuthors')
def listAuthors():
    authorObj = Authors.getInstance()
    return authorObj.listAuthors()
Пример #7
0
class EtherpadDispatch(object):
    def __init__(self):
        self.text = None
        self.authors = Authors()
        self.cursors = Cursors()
        self.color = None
        self.user_id = None
        self.changeset = None

    def on_client_vars(self, data):
        log.debug("on_clientvars: %s" % data)
        vars = data["collab_client_vars"]

        text  = vars["initialAttributedText"]["text"]
        csd   = dict(old_len=len(text),
                     new_len=len(text),
                     ops=vars["initialAttributedText"]["attribs"],
                     char_bank="")
        apool = vars["apool"]

        for i, params in apool['numToAttrib'].iteritems():
            if params[0] == 'author' and params[1] == data['userId']:
                user_id = i
                break
        else:
            apool['numToAttrib'][str(int(i)+1)] = ['author', data["userId"]]
            user_id = str(int(i)+1)
        self.authors.set_user_id(user_id, data['userId'], color=data['userColor'])

        self.text = Text(text=text, cursors=self.cursors, attribs=Attributes(pool=apool), authors=self.authors)
        csd = pack(csd)
        self.text.update(csd)

        self.text.set_revision(int(vars["rev"]))
        for author, d in vars["historicalAuthorData"].iteritems():
            name = d['name'] if 'name' in d.keys() else author
            self.authors.add(author, name=name, color=d['colorId'], padIDs=d['padIDs'])
        self.authors.set_color_palette(data["colorPalette"])

    def on_new_changes(self, data):
        log.debug("on_new_changes: %s" % data)
        newRev = int(data["newRev"])
        changeset = data["changeset"]
        if 'apool' in data.keys():
            self.text._attributes._pool = data['apool']
        if newRev > self.text.get_revision():
            log.debug("apply changeset %s at rev %s" % (changeset, newRev))
            self.text.update(changeset)
            self.text.set_revision(newRev)
        else:
            log.error("ERROR: new revision prior to current revision")

    def on_accept_commit(self, data):
        log.debug('on_accept_commit(%s)' % data)
        rev = int(data["newRev"])
        changeset = self.changeset['changeset']
        if 'apool' in self.changeset.keys():
            self.text._attributes._pool = self.changeset['apool']
        if rev > self.text.get_revision():
            log.debug("apply changeset %s at rev %s" % (changeset, rev))
            self.text.update(changeset)
            self.text.set_revision(rev)
        else:
            log.error("base revision different from current")


    def on_user_newinfo(self, data):
        log.debug("on_user_newinfo: %s" % data)
        userid = data["userInfo"]["userId"]
        name = userid
        if "name" in data["userInfo"]:
            name = data["userInfo"]["name"]
        colorid = data["userInfo"]["colorId"]
        self.authors.add(userid, name=name, color=colorid)
        log.debug("new author: %s (id:%s, color:%s)" % (name, userid, colorid))

    def on_user_leave(self, data):
        log.debug("on_user_leave: %s" % data)

    def on_custom(self, data):
        if data["payload"]["action"] == "cursorPosition":
            log.debug("on_custom:cursorPosition: %s" % data)
            locationX = data["payload"]["locationX"]
            locationY = data["payload"]["locationY"]
            authorId = data["payload"]["authorId"]
            authorName = data["payload"]["authorName"]
            self.cursors.update(authorId, locationX, locationY)
            log.debug("change cursor position of (%s, %s) to (%s, %s)" % (authorId,
                                                                        authorName,
                                                                        locationX,
                                                                        locationY))
        elif data["payload"]["action"] == "requestRTC":
            message = {
                "type" : 'RTC',
                "action" : 'declineRTC',
                "padId" : data["payload"]["padId"],
                "targetAuthorId" : data["payload"]["targetAuthorId"],
                "myAuthorId" : data["payload"]["authorId"]
            }
            def on_response(self, *args):
                log.debug("requestRTC:Response(%s)" % args)
            self.socketIO.emit('message', dict(component='pad',
                                            type="CUSTOM",
                                            padId=self.socketIO.params['padid'],
                                            data=dict(payload=message),
                                            protocolVersion=2), on_response)