<commit_before>import datetime

import argparse
import os
import sqlite3
import sys
from socket import gethostname
from PIL import Image as PILImage, ImageFile as PILImageFile, ExifTags
from peewee import *

DBVERSION = 1
DATABASE = 'imagine.db' # default value
IMAGEEXTENSIONS = ['jpg', 'jpeg', 'png', 'cr2']

DEBUG = True
#DEBUG = False

# database = SqliteDatabase(DATABASE)
database = None


def prt(messageType, message):
    if DEBUG == False:
        return

    if messageType == 'i':
        print '[Info] {0}'.format(message)
    elif messageType == 'e':
        print '[Error] {0}'.format(message)
    elif messageType == 'd':
        print '[Debug] {0}'.format(message)


class BaseModel(Model):
    class Meta:
        database = database


class Collection(BaseModel):
    name = CharField()
    base_dir = CharField()

    added_at = DateTimeField(default=datetime.datetime.now())


class Directory(BaseModel):
    directory = CharField()
    collection = ForeignKeyField(Collection)

    added_at = DateTimeField(default=datetime.datetime.now())

    def get_filepath(self, filename):
        return '%s/%s'.format(self.directory, filename)


class Image(BaseModel):
    directory = ForeignKeyField(Directory, related_name='parent')
    filename = CharField()
    file_ext = CharField()
    filetype = CharField(null=True)
    filesize = IntegerField(default=-1)
    file_modified = DateTimeField(null=True)

    added_at = DateTimeField(default=datetime.datetime.now())
    description = TextField(default='')
    is_visible = BooleanField(default=True)

    width = IntegerField(default=-1)
    height = IntegerField(default=-1)

    image_hash = CharField(null=True)
    thumb_hash = CharField(null=True)

    class Meta:
        order_by = ('filename',)


    def get_filepath(self):
        dirname = Directory.select().where(
                Directory = self.directory
        )
        return '%s/%s'.format(dirname, self.filename)


class ExifItem(BaseModel):
    image = ForeignKeyField(Image)
    key = CharField()
    value_str = CharField(null=True)
    value_int = IntegerField(null=True)
    value_float = FloatField(null=True)

    def get_value(as_type='str'):
        # TODO: be able to return _int or _float<commit_msg>Printable model definitions<commit_after>import datetime

import argparse
import os
import sqlite3
import sys
from socket import gethostname
from PIL import Image as PILImage, ImageFile as PILImageFile, ExifTags
from peewee import *

DBVERSION = 1
DATABASE = 'imagine.db' # default value
IMAGEEXTENSIONS = ['jpg', 'jpeg', 'png', 'cr2']

DEBUG = True
#DEBUG = False

# database = SqliteDatabase(DATABASE)
database = None


def prt(messageType, message):
    if DEBUG == False:
        return

    if messageType == 'i':
        print '[Info] {0}'.format(message)
    elif messageType == 'e':
        print '[Error] {0}'.format(message)
    elif messageType == 'd':
        print '[Debug] {0}'.format(message)


class BaseModel(Model):
    class Meta:
        database = database


class Collection(BaseModel):
    name = CharField()
    base_dir = CharField()

    added_at = DateTimeField(default=datetime.datetime.now())

    def __unicode__(self):
        return '{0} ({1})'.format(self.name, self.base_dir)


class Directory(BaseModel):
    directory = CharField()
    collection = ForeignKeyField(Collection)

    added_at = DateTimeField(default=datetime.datetime.now())

    def get_filepath(self, filename):
        return '{0}/{1}'.format(self.directory, filename)

    def __unicode__(self):
        return self.directory


class Image(BaseModel):
    directory = ForeignKeyField(Directory, related_name='parent')
    filename = CharField()
    file_ext = CharField()
    filetype = CharField(null=True)
    filesize = IntegerField(default=-1)
    file_modified = DateTimeField(null=True)

    added_at = DateTimeField(default=datetime.datetime.now())
    description = TextField(default='')
    is_visible = BooleanField(default=True)

    width = IntegerField(default=-1)
    height = IntegerField(default=-1)

    image_hash = CharField(null=True)
    thumb_hash = CharField(null=True)

    class Meta:
        order_by = ('filename',)


    def get_filepath(self):
        dirname = Directory.select().where(
                Directory = self.directory
        )
        return '{0}/{1}'.format(dirname, self.filename)

    def __unicode__(self):
        return self.get_filepath(self)


class ExifItem(BaseModel):
    image = ForeignKeyField(Image)
    key = CharField()
    value_str = CharField(null=True)
    value_int = IntegerField(null=True)
    value_float = FloatField(null=True)

    def get_value(as_type='str'):
        # TODO: be able to return _int or _float
{'fraction_non_alphanumeric': 0.11589613679544016, 'fraction_numerical': 0.00506649778340722, 'mean_word_length': 3.5426653883029724, 'pattern_counts': {'":': 0, '<': 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': '589505', 'n_tokens_mistral': 1460, 'n_tokens_neox': 1405, 'n_words': 341}