Exemple #1
0
def remote_ping(request, message):
    import sputnik

    sputnik.addMessageToChannel(request, "/booki/", {})

    _now = time.time()

    try:
        locks = sputnik.rkeys("booki:*:locks:*") 
    except:
        return

    for key in locks:
        
        lastAccess = sputnik.get(key)

        if type(lastAccess) in [type(' '), type(u' ')]:
            try:
                lastAccess = decimal.Decimal(lastAccess)
            except:
                continue

        if lastAccess and decimal.Decimal("%f" % _now) - lastAccess > 30:
            sputnik.rdelete(key)

            m = re.match("booki:(\d+):locks:(\d+):(\w+)", key)
            
            if m:
                sputnik.addMessageToChannel(request, "/booki/book/%s/" % m.group(1), {"command": "chapter_status", 
                                                                                      "chapterID": m.group(2), 
                                                                                      "status": "normal", 
                                                                                      "username": m.group(3)},
                                            myself = True)
Exemple #2
0
def remote_chapter_save(request, message, bookid, version):
    # TODO
    # put this outside in common module
    # or maybe even betterm put it in the Model

    book = models.Book.objects.get(id=bookid)
    book_version = getVersion(book, version)
    chapter = models.Chapter.objects.get(id=int(message["chapterID"]))

    if message.get("minor", False) != True:
        history = logChapterHistory(chapter = chapter,
                                    content = message["content"],
                                    user = request.user,
                                    comment = message.get("comment", ""),
                                    revision = chapter.revision+1)

        logBookHistory(book = chapter.book,
                       version = book_version,
                       chapter = chapter,
                       chapter_history = history,
                       user = request.user,
                       args = {"comment": message.get("comment", ""),
                               "author": message.get("author", ""),
                               "authorcomment": message.get("authorcomment", "")},
                       kind = 'chapter_save')

        chapter.revision += 1

    chapter.content = message["content"];

    try:
        chapter.save()

        sputnik.addMessageToChannel(request, "/chat/%s/" % bookid, {"command": "message_info",
                                                                    "from": request.user.username,
                                                                    "message": 'User %s has saved chapter "%s".' % (request.user.username, chapter.title)}, myself=True)
    except:
        transaction.rollback()
    else:
        transaction.commit()

    if not message['continue']:
        sputnik.addMessageToChannel(request, "/booki/book/%s/%s/" % (bookid, version),
                                    {"command": "chapter_status",
                                     "chapterID": message["chapterID"],
                                     "status": "normal",
                                     "username": request.user.username})

        sputnik.rdelete("booki:%s:locks:%s:%s" % (bookid, message["chapterID"], request.user.username))

    # fire the signal
    import booki.editor.signals
    booki.editor.signals.chapter_modified.send(sender = book_version, chapter = chapter, user = request.user)

    return {}
Exemple #3
0
def remote_chapter_status(request, message, bookid, version):

    if message["status"] == "normal":
        sputnik.rdelete("booki:%s:locks:%s:%s" % (bookid, message["chapterID"], request.user.username))

    sputnik.addMessageToChannel(request, "/booki/book/%s/%s/" % (bookid, version),
                                {"command": "chapter_status",
                                 "chapterID": message["chapterID"],
                                 "status": message["status"],
                                 "username": request.user.username})

    return {}
Exemple #4
0
def remote_ping(request, message):
    """
    Sends ping to the server. Just so we know client is still alive. It also removes old locks. This is not the place to do it at all,
    but once we have normal scheduled calls, will put it there.
    :Args:
      - request (:class:`django.http.HttpRequest`): Client Request object
      - message (dict): Message object
    """

    import sputnik

    sputnik.addMessageToChannel(request, "/booktype/", {})

    # kill old chapters which are no longer under edit
    keys = sputnik.rkeys("booktype:*:*:editlocks:*")

    for key in keys:
        last_ping = sputnik.get(key)

        try:
            last_ping = decimal.Decimal(last_ping)
        except Exception as e:
            logger.exception(e)

        if last_ping and decimal.Decimal(
                "%f" %
                time.time()) - last_ping > Chapter.EDIT_PING_SECONDS_MAX_DELTA:
            sputnik.rdelete(key)
            m = re.match("booktype:(\d+):(\d+).(\d+):editlocks:(\d+):(\w+)",
                         key)

            if m:
                bookid, version, chapter_id, username = (m.group(1),
                                                         "{0}.{1}".format(
                                                             m.group(2),
                                                             m.group(3)),
                                                         m.group(4),
                                                         m.group(5))

                sputnik.addMessageToChannel(request,
                                            "/booktype/book/%s/%s/" %
                                            (bookid, version), {
                                                "command": "chapter_state",
                                                "chapterID": chapter_id,
                                                "state": "normal",
                                                "username": username
                                            },
                                            myself=True)
Exemple #5
0
def remote_book_notification(request, message, bookid, version):
    res = {}

    import time

    # rcon.delete(key)
    # set the initial timer for editor

    if request.user.username and request.user.username != '':
        sputnik.set("booki:%s:locks:%s:%s" % (bookid, message["chapterID"], request.user.username), time.time())

        if '%s' % sputnik.get("booki:%s:killlocks:%s:%s" % (bookid, message["chapterID"], request.user.username)) == '1':
            sputnik.rdelete("booki:%s:killlocks:%s:%s" % (bookid, message["chapterID"], request.user.username))
            res = {"kill": "please"}

    return res
Exemple #6
0
def remote_ping(request, message):
    """
    Sends ping to the server. Just so we know client is still alive. It also removes old locks. This is not the place to do it at all, 
    but once we have normal scheduled calls, will put it there.

    @type request: C{django.http.HttpRequest}
    @param request: Client Request object
    @type message: C{dict}
    @param message: Message object
    """

    import sputnik

    sputnik.addMessageToChannel(request, "/booki/", {})

    _now = time.time()

    try:
        locks = sputnik.rkeys("booki:*:locks:*")
    except:
        return

    for key in locks:

        lastAccess = sputnik.get(key)

        if type(lastAccess) in [type(' '), type(u' ')]:
            try:
                lastAccess = decimal.Decimal(lastAccess)
            except:
                continue

        if lastAccess and decimal.Decimal("%f" % _now) - lastAccess > 30:
            sputnik.rdelete(key)

            m = re.match("booki:(\d+):locks:(\d+):(\w+)", key)

            if m:
                sputnik.addMessageToChannel(request,
                                            "/booki/book/%s/" % m.group(1), {
                                                "command": "chapter_status",
                                                "chapterID": m.group(2),
                                                "status": "normal",
                                                "username": m.group(3)
                                            },
                                            myself=True)
Exemple #7
0
def remote_ping(request, message):
    """
    Sends ping to the server. Just so we know client is still alive. It also removes old locks. This is not the place to do it at all, 
    but once we have normal scheduled calls, will put it there.

    @type request: C{django.http.HttpRequest}
    @param request: Client Request object
    @type message: C{dict}
    @param message: Message object
    """

    import sputnik

    sputnik.addMessageToChannel(request, "/booki/", {})

    _now = time.time()

    try:
        locks = sputnik.rkeys("booki:*:locks:*") 
    except:
        return

    for key in locks:
        
        lastAccess = sputnik.get(key)

        if type(lastAccess) in [type(' '), type(u' ')]:
            try:
                lastAccess = decimal.Decimal(lastAccess)
            except:
                continue

        if lastAccess and decimal.Decimal("%f" % _now) - lastAccess > 30:
            sputnik.rdelete(key)

            m = re.match("booki:(\d+):locks:(\d+):(\w+)", key)
            
            if m:
                sputnik.addMessageToChannel(request, "/booki/book/%s/" % m.group(1), {"command": "chapter_status", 
                                                                                      "chapterID": m.group(2), 
                                                                                      "status": "normal", 
                                                                                      "username": m.group(3)},
                                            myself = True)
Exemple #8
0
def removeClient(request, clientName):
    """
    Remove client from Sputnik.

    @type request: C{django.http.HttpRequest}
    @param request: Django Request.
    @type clientName: C{string}
    @param clientName: Unique Client ID.

    @todo: Should remove all tracks of user existence on the system.
    """

    import sputnik

    for chnl in sputnik.smembers("ses:%s:channels" % clientName):
        removeClientFromChannel(request, chnl, clientName)
        srem("ses:%s:channels" % clientName, chnl)

    sputnik.rdelete("ses:%s:username" % clientName)
    sputnik.rdelete("ses:%s:last_access" % clientName)
Exemple #9
0
def removeClient(request, clientName):
    """
    Remove client from Sputnik.

    @type request: C{django.http.HttpRequest}
    @param request: Django Request.
    @type clientName: C{string}
    @param clientName: Unique Client ID.

    @todo: Should remove all tracks of user existence on the system.
    """

    import sputnik

    for chnl in sputnik.smembers("ses:%s:channels" % clientName):
        removeClientFromChannel(request, chnl, clientName)
        srem("ses:%s:channels" % clientName, chnl)

    sputnik.rdelete("ses:%s:username" % clientName)
    sputnik.rdelete("ses:%s:last_access" % clientName)
Exemple #10
0
def remote_ping(request, message):
    """
    Sends ping to the server. Just so we know client is still alive. It also removes old locks. This is not the place to do it at all,
    but once we have normal scheduled calls, will put it there.
    :Args:
      - request (:class:`django.http.HttpRequest`): Client Request object
      - message (dict): Message object
    """

    import sputnik

    sputnik.addMessageToChannel(request, "/booktype/", {})

    # kill old chapters which are no longer under edit
    keys = sputnik.rkeys("booktype:*:*:editlocks:*")

    for key in keys:
        last_ping = sputnik.get(key)

        try:
            last_ping = decimal.Decimal(last_ping)
        except Exception as e:
            logger.exception(e)

        if last_ping and decimal.Decimal("%f" % time.time()) - last_ping > Chapter.EDIT_PING_SECONDS_MAX_DELTA:
            sputnik.rdelete(key)
            m = re.match("booktype:(\d+):(\d+).(\d+):editlocks:(\d+):(\w+)", key)

            if m:
                bookid, version, chapter_id, username = (m.group(1), "{0}.{1}".format(m.group(2), m.group(3)),
                                                         m.group(4), m.group(5))

                sputnik.addMessageToChannel(request, "/booktype/book/%s/%s/" % (bookid, version),
                                            {"command": "chapter_state",
                                             "chapterID": chapter_id,
                                             "state": "normal",
                                             "username": username},
                                            myself=True)