-
Notifications
You must be signed in to change notification settings - Fork 0
/
albumlist.py
executable file
·58 lines (45 loc) · 1.58 KB
/
albumlist.py
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
50
51
52
53
54
55
56
57
58
#!/usr/bin/python2.4
from modules import db
from modules import flags
from modules import items
from modules import utils
import getopt
import sys
FLAGS = flags.FLAGS
FLAGS.AddFlag('u', 'username', 'The username to use for the database')
FLAGS.AddFlag('p', 'password', 'The password to use for the database')
FLAGS.AddFlag('d', 'database', 'The database to use', 'gallery2')
FLAGS.AddFlag('h', 'hostname', 'The hostname to use', 'localhost')
FLAGS.AddFlag('t', 'table_prefix', 'The table prefix to use', 'g2_')
FLAGS.AddFlag('f', 'field_prefix', 'The field prefix to use', 'g_')
def main(argv):
appname = argv[0]
try:
argv = FLAGS.Parse(argv[1:])
except flags.FlagParseError, e:
utils.Usage(appname, e.usage(), e.message())
sys.exit(1)
gdb = db.Database(FLAGS.username, FLAGS.password, FLAGS.database,
FLAGS.hostname, FLAGS.table_prefix, FLAGS.field_prefix)
try:
albums = []
album_ids = gdb.ItemIdsForTable(items.AlbumItem.TABLE_NAME)
for id in album_ids:
albums.append(items.AlbumItem(gdb, id))
photos_by_album = {}
photo_ids = gdb.ItemIdsForTable(items.PhotoItem.TABLE_NAME)
for id in photo_ids:
photo = items.PhotoItem(gdb, id)
if photo.parent_id() not in photos_by_album:
photos_by_album[photo.parent_id()] = []
photos_by_album[photo.parent_id()].append(photo)
for album in albums:
print album
if album.id() not in photos_by_album:
continue
for photo in photos_by_album[album.id()]:
print '\t%s' % photo
finally:
gdb.close()
if __name__ == '__main__':
main(sys.argv)