summaryrefslogtreecommitdiff
path: root/examples/01-simple.py
blob: f039789170d11428a61e8eda940cc16c09705eb0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python

import sys
import os
import ethumb.client
import ecore

if len(sys.argv) < 2:
    raise SystemExit("missing file names.")

def pop_existent(client, files):
    while files:
        f = files.pop()
        client.file_set(f)
        print client
        if not client.exists():
            return f
        tf, tk = client.thumb_path
        print "%s already thumbnailed %s, %s" % (f, tf, tk)
    return None

def request_next(client, files):
    if pop_existent(client, files):
        id = client.generate(generated_cb, files, client)
        print "generating id=%d" % id
    else:
        print "nothing left to generate."
        ecore.main_loop_quit()

def generated_cb(id, file, key, tpath, tkey, success, files, client):
    if success:
        print "id=%d (%s, %s) successfully generated %s, %s" % \
            (id, file, key, tpath, tkey)
    else:
        print "id=%d (%s, %s) failed to generate" % (id, file, key)

    request_next(client, files)


def connected_cb(client, success, files):
    if not success:
        print "could not connect to server."
        ecore.main_loop_quit()
        return
    request_next(client, files)

c = ethumb.client.Client(connected_cb, sys.argv[1:])
ecore.main_loop_begin()
del c