Beispiel #1
0
def _create_char(userid, x1, y1, x2, y2, charid, config=None, remove=True):
    x1, y1, x2, y2 = d.get_int(x1), d.get_int(y1), d.get_int(x2), d.get_int(y2)
    filename = d.url_make(charid, "char/.thumb", root=True)
    if not m.os.path.exists(filename):
        filename = d.url_make(charid, "char/cover", root=True)
        if not filename:
            return
        remove = False

    im = image.read(filename)
    size = im.size.width, im.size.height

    d.execute(
        """
        UPDATE character
        SET settings = REGEXP_REPLACE(settings, '-.', '') || '-%s'
        WHERE charid = %i
    """, [image.image_setting(im), charid])
    dest = '%s%i.thumb%s' % (d.get_hash_path(
        charid, "char"), charid, images.image_extension(im))

    bounds = None
    if image.check_crop(size, x1, y1, x2, y2):
        bounds = geometry.Rectangle(x1, y1, x2, y2)
    thumb = images.make_thumbnail(im, bounds)
    thumb.write(dest, format=images.image_file_type(thumb))
    if remove:
        m.os.remove(filename)
Beispiel #2
0
def _create_char(userid, x1, y1, x2, y2, charid, config=None, remove=True):
    x1, y1, x2, y2 = d.get_int(x1), d.get_int(y1), d.get_int(x2), d.get_int(y2)
    filename = d.url_make(charid, "char/.thumb", root=True)
    if not m.os.path.exists(filename):
        filename = d.url_make(charid, "char/cover", root=True)
        if not filename:
            return
        remove = False

    im = image.read(filename)
    size = im.size.width, im.size.height

    d.execute("""
        UPDATE character
        SET settings = REGEXP_REPLACE(settings, '-.', '') || '-%s'
        WHERE charid = %i
    """, [image.image_setting(im), charid])
    dest = '%s%i.thumb%s' % (d.get_hash_path(charid, "char"), charid, images.image_extension(im))

    bounds = None
    if image.check_crop(size, x1, y1, x2, y2):
        bounds = geometry.Rectangle(x1, y1, x2, y2)
    thumb = images.make_thumbnail(im, bounds)
    thumb.write(dest, format=images.image_file_type(thumb))
    if remove:
        m.os.remove(filename)
Beispiel #3
0
def select_latest(userid, rating, otherid=None, config=None):
    if config is None:
        config = d.get_config(userid)

    statement = ["SELECT jo.journalid, jo.title, jo.unixtime FROM journal jo WHERE"]

    if userid:
        if d.is_sfw_mode():
            statement.append(" (jo.rating <= %i)" % (rating,))
        else:
            statement.append(" (jo.userid = %i OR jo.rating <= %i)" % (userid, rating))
        if not otherid:
            statement.append(m.MACRO_IGNOREUSER % (userid, "jo"))
        statement.append(m.MACRO_BLOCKTAG_JOURNAL % (userid, userid))
    else:
        statement.append(" jo.rating <= %i" % (rating,))

    if otherid:
        statement.append(
            " AND jo.userid = %i AND jo.settings !~ '[%sh]'" % (otherid, "" if frienduser.check(userid, otherid) else "f"))

    statement.append("ORDER BY jo.journalid DESC LIMIT 1")
    query = d.execute("".join(statement), options="single")

    if query:
        return {
            "journalid": query[0],
            "title": query[1],
            "unixtime": query[2],
            "content": files.read("%s%s%i.txt" % (m.MACRO_SYS_JOURNAL_PATH, d.get_hash_path(query[0]), query[0])),
            "comments": d.execute("SELECT COUNT(*) FROM journalcomment WHERE targetid = %i AND settings !~ 'h'",
                                  [query[0]], ["element"]),
        }
Beispiel #4
0
def make_resource(userid, target, feature, extension=None):
    """
    Returns the full path to the specified resource.
    """
    # Character
    if feature == "char/submit":
        return "%s%d.submit.%d%s" % (d.get_hash_path(target, "char"), target, userid, extension)
    if feature == "char/cover":
        return "%s%d.cover%s" % (d.get_hash_path(target, "char"), target, extension)
    if feature == "char/thumb":
        return "%s%d.thumb%s" % (d.get_hash_path(target, "char"), target, extension)
    if feature == "char/.thumb":
        return "%s%d.new.thumb" % (d.get_hash_path(target, "char"), target)
    # Journal
    if feature == "journal/submit":
        return "%s%d.txt" % (d.get_hash_path(target, "journal"), target)
    # Unknown
    raise ValueError
Beispiel #5
0
def select_latest(userid, rating, otherid=None, config=None):
    if config is None:
        config = d.get_config(userid)

    statement = [
        "SELECT jo.journalid, jo.title, jo.unixtime FROM journal jo WHERE"
    ]

    if userid:
        if d.is_sfw_mode():
            statement.append(" (jo.rating <= %i)" % (rating, ))
        else:
            statement.append(" (jo.userid = %i OR jo.rating <= %i)" %
                             (userid, rating))
        if not otherid:
            statement.append(m.MACRO_IGNOREUSER % (userid, "jo"))
        statement.append(m.MACRO_BLOCKTAG_JOURNAL % (userid, userid))
    else:
        statement.append(" jo.rating <= %i" % (rating, ))

    if otherid:
        statement.append(
            " AND jo.userid = %i AND jo.settings !~ '[%sh]'" %
            (otherid, "" if frienduser.check(userid, otherid) else "f"))

    statement.append("ORDER BY jo.journalid DESC LIMIT 1")
    query = d.execute("".join(statement), options="single")

    if query:
        return {
            "journalid":
            query[0],
            "title":
            query[1],
            "unixtime":
            query[2],
            "content":
            files.read("%s%s%i.txt" % (m.MACRO_SYS_JOURNAL_PATH,
                                       d.get_hash_path(query[0]), query[0])),
            "comments":
            d.execute(
                "SELECT COUNT(*) FROM journalcomment WHERE targetid = %i AND settings !~ 'h'",
                [query[0]], ["element"]),
        }
Beispiel #6
0
def make_path(target, root):
    path = d.get_hash_path(target, root)
    makedirs(path)