def sync_avatars(self, client): response = {'data':{'synced':[]}} new_profiles = [] profiles = Profile.objects.all() os_profiles = OSUserAccounts.objects.using('grid').all() new_profiles = [] new_osprofiles = [] #sync osprofile to profile for os_profile in os_profiles: match = False for profile in profiles: profile_name = '%s %s' % (profile.first_name,profile.last_name) osprofile_name = '%s %s' % (os_profile.FirstName, os_profile.LastName) if profile.uuid == os_profile.PrincipalID.UUID: match = True elif (profile_name == osprofile_name): match = True if match == False: new_profiles.append(os_profile) for new_profile in new_profiles: profile = Profile() profile.username = '******' % (new_profile.FirstName, new_profile.LastName) profile.first_name = new_profile.FirstName profile.last_name = new_profile.LastName profile.email = new_profile.Email profile.is_active = 1 profile.uuid = new_profile.PrincipalID.UUID profile.salt = new_profile.PrincipalID.passwordSalt profile.password = new_profile.PrincipalID.passwordHash profile.ip = '0.0.0.0' profile.date_joined = datetime.now() profile.save() #sync profile to osprofile for profile in profiles: match = False for os_profile in os_profiles: profile_name = '%s %s' % (profile.first_name,profile.last_name) osprofile_name = '%s %s' % (os_profile.FirstName, os_profile.LastName) if profile.uuid == os_profile.PrincipalID.UUID: match = True elif (profile_name == osprofile_name): match = True if match == False: new_osprofiles.append(profile) for _profile in new_osprofiles: self.change_avatar(client, _profile) client_response, tpl_params = self._get_avatars(client) _target_state = '/opensim/avatars/' client_response.update({ 'status':{ 'code':'PROFILE_SYNC_OK', 'i18n':_('%(profiles)s/%(osprofiles)s profile(s)/avatar(s) were synced!') % {'profiles':len(new_profiles),'osprofiles':len(new_osprofiles)}, 'type': HWIOS.ws_realm._t['notify-info'] } }) notify_others(client, client_response,'/opensim/avatars/modified/', '^/opensim/avatars/$', tpl_params, _target_state) publish_activity(client.profile, _('Avatar(s) synced'),'/opensim/avatars/',[0,0,1,0,0]) return client_response
def get_anonymous_profile(self): profile = Profile() profile.is_authenticated = False while True: pk = random.randrange(0, 10001, 2) username = '******' % pk if not HWIOS.ws_realm.pool.name_taken(username): profile.username = username profile.pk = pk try: profile.uuid = uuid.uuid5(uuid.NAMESPACE_DNS, str(self.session_id)) except AttributeError: profile.uuid = uuid.uuid5(uuid.NAMESPACE_DNS, self.transport.getPeer().host) break return profile
def get_anonymous_profile(self): """Return a random anonymous profile object""" profile = Profile() profile.is_authenticated = False while True: #random id of a visitor is set in the http bootstrapping call, and transferred using the session object username = '******' % self.transport.session['id'] if not HWIOS.ws_realm.pool.name_taken(username): profile.username = username profile.id = self.transport.session['id'] try: profile.uuid = uuid.uuid5(uuid.NAMESPACE_DNS, str(self.session_id)) except AttributeError: profile.uuid = uuid.uuid5(uuid.NAMESPACE_DNS, self.transport.getPeer().host) break else: self.transport.session['id'] = random.randint(1000,9999) self.get_anonymous_profile() return profile