@@ -0,0 +1,1546 @@
+#!/usr/bin/env python%0A# -*- coding: utf-8 -*-%0A%0Aimport MySQLdb%0Aimport sys%0Aimport os%0Afrom mosql.common import insert%0A%0ADB_USER = ''%0ADB_PSWD = ''%0ADB_NAME = ''%0A%0Adef list_files_in(directory, verbose=True):%0A  path_list = %5B%5D%0A%09for dir_path, dir_names, file_names in os.walk(root_dir):%0A%09%09for f in file_names:%0A%09%09%09rel_path = os.path.relpath(dir_path, root_dir)%0A%09%09%09file_path = '/' + os.path.join(rel_path, f)%0A%09%09%09path_list.append(file_path)%0A%09%09%09if verbose:%0A%09%09%09%09print file_path%0A%09if verbose:%0A%09%09print%0A%09return path_list%0A%0Adef confirm(statement):%0A%09yes = set(%5B'yes', 'y', 'ok', 'sure'%5D)%0A%09no = set(%5B'no', 'n'%5D)%0A%09choice = raw_input(statement).strip().lower()%0A%09if choice in yes:%0A%09%09return True%0A%09elif choice in no:%0A%09%09return False%0A%09else:%0A%09%09raise ValueError%0A%0Adef import_to_db(db, path_list):%0A%09cur = db.cursor()%0A%09images_creating_sql = insert('tagging_images', %0A%09%09 %09%09%09%09%09%09 columns=('img_path'),%0A%09%09%09%09%09%09%09%09 values=%5B(path,) for path in path_list%5D)%0A%09cur.execute(images_creating_sql)%0A%09db.commit()%0A%0Aif __name__ == '__main__':%0A%0A%09root_dir = '.'%0A%09if len(sys.argv) %3E 1:%0A%09%09root_dir = sys.argv%5B1%5D%0A%09%09print%0A%09else:%0A%09%09print 'Root directory is undefined'%0A%09%09exit()%0A%0A%09paths = list_files_in(root_dir)%0A%09try:%0A%09%09if confirm(' %3E%3E Do you want to import into db? '):%0A%0A%09%09%09db = MySQLdb.connect(%0A%09%09%09%09%09%09host='localhost',%0A%09%09%09%09%09 %09user=DB_USER,%0A%09%09%09%09%09 %09passwd=DB_PSWD,%0A%09%09%09%09%09 %09db=DB_NAME)%0A%09%09%09print ' %3E%3E Start importing '%0A%09%09%09import_to_db(db, paths)%0A%09%09%09print ' %3E%3E Finished '%0A%09%09else:%0A%09%09%09print ' %3E%3E Fine. I will not import anything.'%0A%09except ValueError:%0A%09%09print ' %3E%3E I can%5C't understand what you said'%0A%09except:%0A%09%09raise%0A

Create path2db.py