#!/usr/bin/python

from rasterize import fetch, rename, compose, partial, flip
import tempfile

database = 'static/database/documents.sqlite3'
(host, username, password) = ('localhost', 'volkmar', 'MDa3ZyNhULYyA')
archive = "rasterized"

#r = fetch(database, host, username, password,
#  'documents', archive=rename, pattern='512', limit=1)

r = [('LOGISTIQUE_0_023328.pdf', 3, None)]
print map(lambda x: (x[0], x[1]), r)


def test_get_source():
    from rasterize import get_document_by_name
    global database

    file = 'LOGISTIQUE_0_023328.pdf'
    r = get_document_by_name(database, file)
    print r
    f = open(file, 'wb+')
    f.write(r[3])
    f.close()


def test_archive():
    import ftplib

    global host, username, password

    ftp = ftplib.FTP(host, username, password)
    ftp.cwd('documents')
    mv = compose(partial(flip(partial(rename, ftp)), archive), lambda x: x[0])

    map(mv, r)

print test_get_source()
