Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jan 20th, 2012  |  syntax: Python  |  size: 0.98 KB  |  views: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/usr/bin/env python
  2. import csv
  3. import sys
  4. import MySQLdb
  5. conn = MySQLdb.connect(host= "localhost",
  6.                   user="crushlb",
  7.                   passwd="password",
  8.                   db="crushlb")
  9.  
  10. cursor = conn.cursor()  
  11. user_args = []
  12. perm_args = []
  13.  
  14. perms = '(read)(write)(view)(delete)(resume)(share)(slideshow)(rename)(makedir)(deletedir)'
  15.  
  16. open(sys.argv[1], 'rt') with f:
  17.     for id, row in enumerate(csv.reader(f), start = 24):
  18.         username, password, path = row
  19.         user_args.append((id, username, password, 'MainUsers'))
  20.         perm_args.append((id, path, perms))
  21.  
  22. insert_users = '''
  23.    INSERT IGNORE INTO `USERS`
  24.    (`userid`, `username`, `password`, `server_group`)
  25.    VALUES (%s, %s, %s, %s)
  26.    '''
  27.  
  28. insert_vfs_permissions = '''
  29.    INSERT IGNORE INTO `VFS_PERMISSIONS`
  30.    (`userid`, `path`, `privs`)
  31.    VALUES (%s, %s, %s),
  32.    '''
  33.  
  34. cursor.executemany(insert_users,user_args)
  35. cursor.executemany(insert_vfs_permissions,perm_args)