2008-03-07 15:51:41 -06:00
#!/usr/bin/python
import pgdb
from turbogears . view import engines
import turbogears . view
import turbogears . util as tg_util
from turbogears import view , database , errorhandling , config
from itertools import izip
from inspect import isclass
from turbogears import update_config , start_server
import cherrypy
cherrypy . lowercase_api = True
from os . path import *
import sys
import time
2008-03-07 17:27:09 -06:00
import crypt
import random
2008-03-07 15:51:41 -06:00
if len ( sys . argv ) > 1 :
update_config ( configfile = sys . argv [ 1 ] ,
modulename = " fas.config " )
elif exists ( join ( dirname ( __file__ ) , " setup.py " ) ) :
update_config ( configfile = " dev.cfg " , modulename = " fas.config " )
else :
update_config ( configfile = " prod.cfg " , modulename = " fas.config " )
from sqlalchemy import *
from sqlalchemy . exceptions import *
from fas . model import *
2008-03-07 17:27:09 -06:00
def generate_salt ( length = 8 ) :
chars = ' ./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz '
salt = ' '
for i in xrange ( length ) :
salt + = random . choice ( chars )
return salt
2008-03-07 15:51:41 -06:00
db = pgdb . connect ( dsn = ' localhost ' , user = ' fedora ' , password = ' test ' , database = ' fedorausers ' )
c = db . cursor ( )
2008-03-07 17:27:09 -06:00
2008-03-07 15:51:41 -06:00
c . execute ( ' select id, username, email, human_name, gpg_keyid, ssh_key, password, comments, postal_address, telephone, affiliation, creation, approval_status, internal_comments, ircnick from person order by id; ' )
print " Converting People Table "
for person in c . fetchall ( ) :
( id , username , email , human_name , gpg_keyid , ssh_key , password , comments , postal_address , telephone , affiliation , creation , approval_status , internal_comments , ircnick ) = person
print " \t %i - %s " % ( id , username )
p = People ( )
p . id = id
p . username = username
p . human_name = human_name
p . gpg_keyid = gpg_keyid
p . ssh_key = ssh_key
2008-03-07 17:27:09 -06:00
p . password = crypt . crypt ( password , " $1$ %s " % generate_salt ( 8 ) )
2008-03-07 15:51:41 -06:00
p . comments = comments
p . postal_address = postal_address
p . telephone = telephone
p . creation = creation
p . internal_comments = internal_comments
p . ircnick = ircnick
p . status = ' active '
try :
session . flush ( )
except IntegrityError , e :
2008-03-08 12:12:48 -06:00
print " \t ERROR - Could not create %s - %s " % ( username , e )
2008-03-07 15:51:41 -06:00
session . close ( )
continue
person_email = PersonEmails ( )
try :
person_email . email = email
except AttributeError :
2008-03-08 12:12:48 -06:00
print " \t ERROR - Could not create email for %s ( %s ) " % ( username , email )
2008-03-07 15:51:41 -06:00
session . close ( )
continue
person_email . person = p
person_email . description = ' Fedora Email '
person_email . verified = True # The first email is verified for free, since this is where their password is sent.
session . flush ( )
email_purpose = EmailPurposes ( )
email_purpose . person = p
email_purpose . person_email = person_email
email_purpose . purpose = ' primary '
session . flush ( )
2008-03-07 17:27:09 -06:00
c . execute ( ' select id, name, owner_id, group_type, needs_sponsor, user_can_remove, prerequisite_id, joinmsg from project_group; ' )
bool_dict = { 0 : False , 1 : True }
2008-03-07 15:51:41 -06:00
print " Creating Groups... "
2008-03-07 17:27:09 -06:00
admin = People . by_username ( ' admin ' )
admin_id = admin . id
2008-03-07 15:51:41 -06:00
for group in c . fetchall ( ) :
( id , name , owner_id , group_type , needs_sponsor , user_can_remove , prerequisite_id , joinmsg ) = group
print " %i - %s " % ( id , name )
try :
group = Groups ( )
group . id = id
group . name = name
group . display_name = name
2008-03-07 17:27:09 -06:00
if owner_id == 100001 :
''' Update to new admin id '''
owner_id = admin_id
2008-03-07 15:51:41 -06:00
group . owner_id = owner_id
group . group_type = group_type
2008-03-07 17:27:09 -06:00
group . needs_sponsor = bool ( bool_dict [ needs_sponsor ] )
group . user_can_remove = bool ( bool_dict [ user_can_remove ] )
2008-03-08 12:12:48 -06:00
# if prerequisite_id:
# prerequisite = Groups.by_id(prerequisite_id)
# group.prerequisite = prerequisite
2008-03-07 15:51:41 -06:00
group . joinmsg = joinmsg
# Log here
session . flush ( )
2008-03-07 17:27:09 -06:00
except IntegrityError , e :
2008-03-08 12:12:48 -06:00
print " \t ERROR - The group: ' %s ' ( %i ) could not be created - %s " % ( name , id , e )
2008-03-07 17:27:09 -06:00
except FlushError , e :
2008-03-08 12:12:48 -06:00
print " \t ERROR - The group: ' %s ' ( %i ) could not be created - %s " % ( name , id , e )
2008-03-07 17:27:09 -06:00
except InvalidRequestError , e :
2008-03-08 12:12:48 -06:00
print " \t ERROR - The group: ' %s ' ( %i ) could not be created - %s " % ( name , id , e )
2008-03-07 17:27:09 -06:00
session . close ( )
2008-03-07 15:51:41 -06:00
c . execute ( ' select person_id, project_group_id, role_type, role_domain, role_status, internal_comments, sponsor_id, creation, approval from role order by person_id; ' )
print " Creating Role Maps... "
for role in c . fetchall ( ) :
( person_id , project_group_id , role_type , role_domain , role_status , internal_comments , sponsor_id , creation , approval ) = role
print " %s - %s " % ( person_id , project_group_id )
2008-03-07 17:27:09 -06:00
try :
role = PersonRoles ( )
2008-03-08 12:12:48 -06:00
if len ( role_status ) > 10 :
role_status = ' approved '
if role_status == ' declined ' :
''' No longer exists '''
continue
2008-03-07 17:27:09 -06:00
role . role_status = role_status
role . role_type = role_type
role . member = People . by_id ( person_id )
role . group = Groups . by_id ( project_group_id )
session . flush ( )
except ProgrammingError , e :
2008-03-08 12:12:48 -06:00
print " \t ERROR - The role %s -> %s could not be created - %s " % ( person_id , project_group_id , e )
2008-03-09 14:21:41 -05:00
session . close ( )
2008-03-07 17:27:09 -06:00
except IntegrityError , e :
2008-03-08 23:21:24 -06:00
if e . message . find ( ' dupilcate key ' ) :
print " \t ERROR - The role %s -> %s already exists! Skipping " % ( person_id , project_group_id )
2008-03-09 14:21:41 -05:00
session . close ( )
2008-03-08 23:21:24 -06:00
continue
2008-03-08 12:12:48 -06:00
print " \t ERROR - The role %s -> %s could not be created - %s " % ( person_id , project_group_id , e )
2008-03-08 23:21:24 -06:00
session . close ( )