#!/usr/bin/python # # getpics by Tami (Masaaki) Takamiya me@tamichan.com # # 2007.12.25 Version 0.1 # 2008.01.05 Version 0.2 - delete result even if the file ext does't match # 2008.01.08 Version 0.3 - performance improvement # 2008.01.11 Version 0.4 - cannot find default datastore in some cases (why?) import sys import os import shutil from datetime import datetime from sugar.datastore import datastore PROPERTIES = ['uid', 'title', 'mtime', 'timestamp', 'keep', 'buddies', 'icon-color', 'mime_type', 'progress', 'activity', 'mountpoint', 'activity_id'] file_ext = ".jpg" mount_id = None mount_ids = [] mounts = datastore.mounts() for m in mounts: id = m['id'] mount_ids += [ id ] if m['title'] == '/home/olpc/.sugar/default/datastore': mount_id = id if mount_id != None: mount_ids = [ mount_id ] try: (results,count) = datastore.find(dict( mountpoints=mount_ids, mime_type=["image/jpeg"]), properties=PROPERTIES) print "count = " + str(count) for f in results: src = f.get_file_path() if src.endswith(file_ext): dict = f.get_metadata().get_dictionary() dt = datetime.fromtimestamp(dict["timestamp"]) dest = dt.strftime("%Y%m%d-%H%M%S" + file_ext) if os.path.exists(dest): print dest, 'exists.' else: shutil.copyfile(src, dest) print dest, 'was extracted.' object_id = f.object_id # # add following line if you want to remove pictures from datastore # datastore.delete(object_id) f.destroy() except Exception, e: print 'Error: %s' % (e)