<commit_before>import sputnik

from django.db import transaction

from booki.utils.log import logBookHistory, logChapterHistory

from booki.editor import models
from booki.editor.views import getVersion

try:
    from booki.settings import OBJAVI_URL
except ImportError:
    OBJAVI_URL = "http://objavi.flossmanuals.net/objavi.cgi"

try:
    from booki.settings import THIS_BOOKI_SERVER
except:
    THIS_BOOKI_SERVER = os.environ.get('HTTP_HOST', 'booki.flossmanuals.net')


# this couple of functions should go to models.BookVersion

def getTOCForBook(version):
    def _getInfo(chap):
        if chap.chapter:
            return (chap.chapter.id, chap.chapter.title, chap.chapter.url_title, chap.typeof, chap.chapter.status.id)
        else:
            return ('s%s' % chap.id, chap.name, chap.name, chap.typeof)

    return [_getInfo(chap) for chap in list(version.getTOC())]


def getHoldChapters(book_version):
    return [(ch.id, ch.title, ch.url_title, 1, ch.status.id) for ch in book_version.getHoldChapters()]


def getAttachments(book_version):
    import os.path
    import Image

    def _getDimension(att):
        if att.attachment.name.endswith(".jpg"):
            try:
                im = Image.open(att.attachment.name)
                return im.size
            except:
                return (0, 0)
        return None
            

    attachments = [{"id":        att.id, 
                    "dimension": _getDimension(att), 
                    "status":    att.status.id, 
                    "name":      os.path.split(att.attachment.name)[1], 
                    "size":      att.attachment.size} 
                   for att in book_version.getAttachments() if att.attachment]

    return attachments
<commit_msg>accidentally rewrote a function for no particular reason<commit_after>import sputnik

from django.db import transaction

from booki.utils.log import logBookHistory, logChapterHistory

from booki.editor import models
from booki.editor.views import getVersion

try:
    from booki.settings import OBJAVI_URL
except ImportError:
    OBJAVI_URL = "http://objavi.flossmanuals.net/objavi.cgi"

try:
    from booki.settings import THIS_BOOKI_SERVER
except:
    THIS_BOOKI_SERVER = os.environ.get('HTTP_HOST', 'booki.flossmanuals.net')


# this couple of functions should go to models.BookVersion
def getTOCForBook(version):
    results = []
    for chap in version.getTOC():
        # is it a section or chapter?
        if chap.chapter:
            results.append((chap.chapter.id,
                            chap.chapter.title,
                            chap.chapter.url_title,
                            chap.typeof,
                            chap.chapter.status.id))
        else:
            results.append(('s%s' % chap.id, chap.name, chap.name, chap.typeof))
    return results



def getHoldChapters(book_version):
    return [(ch.id, ch.title, ch.url_title, 1, ch.status.id) for ch in book_version.getHoldChapters()]


def getAttachments(book_version):
    import os.path
    import Image

    def _getDimension(att):
        if att.attachment.name.endswith(".jpg"):
            try:
                im = Image.open(att.attachment.name)
                return im.size
            except:
                return (0, 0)
        return None
            

    attachments = [{"id":        att.id, 
                    "dimension": _getDimension(att), 
                    "status":    att.status.id, 
                    "name":      os.path.split(att.attachment.name)[1], 
                    "size":      att.attachment.size} 
                   for att in book_version.getAttachments() if att.attachment]

    return attachments

{'fraction_non_alphanumeric': 0.09703723837999456, 'fraction_numerical': 0.0021745039412883935, 'mean_word_length': 2.1319148936170214, 'pattern_counts': {'":': 10, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2201503', 'n_tokens_mistral': 1137, 'n_tokens_neox': 1067, 'n_words': 254}