class Instance: key = profile.get_pubkey() # joyride ... # keyHash = util.sha_data(key) # 8.2... # keyHash = util._sha_data(key) # keyHashPrintable = util.printable_hash(keyHash) nick_name = profile.get_nick_name() color_fill = Color() color_fill.init_hex(profile.get_color().get_fill_color()) color_stroke = Color() color_stroke.init_hex(profile.get_color().get_stroke_color()) instance_id = None instance_path = None data_path = None def __init__(self, ca): self.__class__.instance_id = ca._activity_id self.__class__.instance_path = os.path.join(ca.get_activity_root(), "instance") recreate_tmp() self.__class__.data_path = os.path.join(ca.get_activity_root(), "data") recreate_data()
def create_profile(name, color=None): if not color: color = XoColor() client = GConf.Client.get_default() client.set_string('/desktop/sugar/user/nick', name) client.set_string('/desktop/sugar/user/color', color.to_string()) client.suggest_sync() if profile.get_pubkey() and profile.get_profile().privkey_hash: logging.info('Valid key pair found, skipping generation.') return # Generate keypair import commands keypath = os.path.join(env.get_profile_path(), 'owner.key') if os.path.exists(keypath): os.rename(keypath, keypath + '.broken') logging.warning('Existing private key %s moved to %s.broken', keypath, keypath) if os.path.exists(keypath + '.pub'): os.rename(keypath + '.pub', keypath + '.pub.broken') logging.warning('Existing public key %s.pub moved to %s.pub.broken', keypath, keypath) logging.debug("Generating user keypair") cmd = "ssh-keygen -q -t dsa -f %s -C '' -N ''" % (keypath, ) (s, o) = commands.getstatusoutput(cmd) if s != 0: logging.error('Could not generate key pair: %d %s', s, o) logging.debug("User keypair generated")
def __init__(self, handle): """Set up the Maze activity.""" activity.Activity.__init__(self, handle) self._busy_count = 0 self._unbusy_idle_sid = None self.build_toolbar() self.pservice = PresenceService() self.owner = self.pservice.get_owner() state = None if 'state' in self.metadata: state = json.loads(self.metadata['state']) self.game = game.MazeGame(self, self.owner, state) self.set_canvas(self.game) self.game.show() self.connect("key_press_event", self.game.key_press_cb) self.text_channel = None self.my_key = profile.get_pubkey() self._alert = None if self.shared_activity: # we are joining the activity self._add_alert(_('Joining a maze'), _('Connecting...')) self.connect('joined', self._joined_cb) if self.get_shared(): # we have already joined self._joined_cb() else: # we are creating the activity self.connect('shared', self._shared_cb)
def default_nicks(): try: nicks = [conf.get('nick')] + conf.get('altnicks', []) if not nicks[0]: # We're going to generate a nick based on the user's nick name # and their public key. from sugar3 import profile import hashlib user_name = profile.get_nick_name() pubkey = profile.get_pubkey() m = hashlib.sha1() m.update(pubkey) hexhash = m.hexdigest() # Okay. Get all of the alphabetic bits of the username: user_name_letters = "".join([x for x in user_name if x.isalpha()]) # If that came up with nothing, make it 'XO'. Also, shorten it # if it's more than 11 characters (as we need 5 for - and the # hash). if len(user_name_letters) == 0: user_name_letters = "XO" if len(user_name_letters) > 11: user_name_letters = user_name_letters[0:11] # Finally, generate a nick by using those letters plus the first # four hash bits of the user's public key. user_nick = user_name_letters + "-" + hexhash[0:4] nicks = [user_nick] except: nicks = ["purk"] return nicks
def create_profile(user_profile): settings = Gio.Settings('org.sugarlabs.user') settings.set_string('nick', user_profile.nickname) colors = user_profile.colors if colors is None: colors = XoColor() settings.set_string('color', colors.to_string()) if user_profile.gender is not None: settings.set_string('gender', user_profile.gender) else: settings.set_string('gender', '') settings.set_int('birth-timestamp', calculate_birth_timestamp(user_profile.age)) # settings.sync() # DEPRECATED from gi.repository import GConf client = GConf.Client.get_default() client.set_string('/desktop/sugar/user/nick', user_profile.nickname) client.set_string('/desktop/sugar/user/color', colors.to_string()) if user_profile.gender is not None: client.set_string('/desktop/sugar/user/gender', user_profile.gender) client.set_int('/desktop/sugar/user/birth_timestamp', calculate_birth_timestamp(user_profile.age)) client.suggest_sync() if profile.get_pubkey() and profile.get_profile().privkey_hash: logging.info('Valid key pair found, skipping generation.') return # Generate keypair keypath = os.path.join(env.get_profile_path(), 'owner.key') if os.path.exists(keypath): os.rename(keypath, keypath + '.broken') logging.warning('Existing private key %s moved to %s.broken', keypath, keypath) if os.path.exists(keypath + '.pub'): os.rename(keypath + '.pub', keypath + '.pub.broken') logging.warning('Existing public key %s.pub moved to %s.pub.broken', keypath, keypath) logging.debug("Generating user keypair") cmd = "ssh-keygen -q -t dsa -f %s -C '' -N ''" % (keypath, ) (s, o) = subprocess.getstatusoutput(cmd) if s != 0: logging.error('Could not generate key pair: %d %s', s, o) logging.debug("User keypair generated")
def create_profile(user_profile): settings = Gio.Settings('org.sugarlabs.user') if user_profile.nickname in [None, '']: nick = settings.get_string('nick') if nick is not None: logging.debug('recovering old nickname %s' % (nick)) user_profile.nickname = nick settings.set_string('nick', user_profile.nickname) colors = user_profile.colors if colors is None: colors = XoColor() settings.set_string('color', colors.to_string()) genderpicker.save_gender(user_profile.gender) agepicker.save_age(user_profile.age) # DEPRECATED from gi.repository import GConf client = GConf.Client.get_default() client.set_string('/desktop/sugar/user/nick', user_profile.nickname) client.set_string('/desktop/sugar/user/color', colors.to_string()) client.suggest_sync() if profile.get_pubkey() and profile.get_profile().privkey_hash: logging.info('Valid key pair found, skipping generation.') return # Generate keypair keypath = os.path.join(env.get_profile_path(), 'owner.key') if os.path.exists(keypath): os.rename(keypath, keypath + '.broken') logging.warning('Existing private key %s moved to %s.broken', keypath, keypath) if os.path.exists(keypath + '.pub'): os.rename(keypath + '.pub', keypath + '.pub.broken') logging.warning('Existing public key %s.pub moved to %s.pub.broken', keypath, keypath) logging.debug("Generating user keypair") cmd = "ssh-keygen -q -t dsa -f %s -C '' -N ''" % (keypath, ) (s, o) = commands.getstatusoutput(cmd) if s != 0: logging.error('Could not generate key pair: %d %s', s, o) logging.debug("User keypair generated")
def generate_unique_id(): """Generate an id based on the user's nick name and their public key (Based on schema used by IRC activity). """ nick = profile.get_nick_name() pubkey = profile.get_pubkey() m = hashlib.sha1() m.update(pubkey) hexhash = m.hexdigest() nick_letters = "".join([x for x in nick if x.isalpha()]) if not nick_letters: nick_letters = 'XO' return nick_letters + '_' + hexhash[:4]
class Instance: key = profile.get_pubkey() #joyride ... #keyHash = util.sha_data(key) #8.2... #keyHash = util._sha_data(key) #keyHashPrintable = util.printable_hash(keyHash) nickName = profile.get_nick_name() instanceId = None instancePath = None dataPath = None def __init__(self, ca): self.__class__.instanceId = ca._activity_id self.__class__.instancePath = os.path.join(ca.get_activity_root(), "instance") recreateTmp() self.__class__.dataPath = os.path.join(ca.get_activity_root(), "data") recreateData()
def __init__(self, handle): ''' Initiate activity. ''' super(FractionBounceActivity, self).__init__(handle) self.nick = profile.get_nick_name() self.key = profile.get_pubkey() if profile.get_color() is not None: self._colors = profile.get_color().to_string().split(',') else: self._colors = ['#A0FFA0', '#FF8080'] self.max_participants = 4 # sharing self._ignore_messages = False # activity was asked to stop self._setup_toolbars() canvas = self._setup_canvas() # Read any custom fractions from the project metadata if 'custom' in self.metadata: custom = self.metadata['custom'] else: custom = None self._current_ball = 'soccerball' self._toolbar_was_expanded = False # Initialize the canvas self._bounce_window = Bounce(canvas, activity.get_bundle_path(), self) Gdk.Screen.get_default().connect('size-changed', self._configure_cb) # Restore any custom fractions if custom is not None: fractions = custom.split(',') for f in fractions: self._bounce_window.add_fraction(f) self._bounce_window.buddies.append([self.nick, self.key]) self._player_colors = [self._colors] self._player_pixbufs = [ svg_str_to_pixbuf(generate_xo_svg(scale=0.8, colors=self._colors)) ] def on_activity_joined_cb(me): logging.debug('activity joined') self._player.set_from_pixbuf(self._player_pixbufs[0]) self.connect('joined', on_activity_joined_cb) def on_activity_shared_cb(me): logging.debug('activity shared') self._player.set_from_pixbuf(self._player_pixbufs[0]) self._label.set_label(_('Wait for others to join.')) self.connect('shared', on_activity_shared_cb) self._collab = CollabWrapper(self) if self.shared_activity: # We're joining if not self.get_shared(): self._label.set_label(_('Wait for the sharer to start.')) actions = { 'j': self._new_joiner, 'b': self._buddy_list, 'f': self._receive_a_fraction, 't': self._take_a_turn, 'l': self._buddy_left, } def on_message_cb(collab, buddy, msg): logging.debug('on_message_cb buddy %r msg %r' % (buddy, msg)) if not self._ignore_messages: actions[msg.get('action')](msg.get('data')) self._collab.connect('message', on_message_cb) def on_joined_cb(collab, msg): logging.debug('joined') self.send_event('j', [self.nick, self.key, self._colors]) self._collab.connect('joined', on_joined_cb, 'joined') def on_buddy_joined_cb(collab, buddy, msg): logging.debug('on_buddy_joined_cb buddy %r' % (buddy.props.nick)) self._collab.connect('buddy_joined', on_buddy_joined_cb, 'buddy_joined') def on_buddy_left_cb(collab, buddy, msg): logging.debug('on_buddy_left_cb buddy %r' % (buddy.props.nick)) # synthesise a buddy left message in case it did not # arrive; this can happen when the peer terminates # unexpectedly, or the network connection between the # peers fails. self._buddy_left([buddy.props.nick, buddy.props.key]) self._collab.connect('buddy_left', on_buddy_left_cb, 'buddy_left') self._collab.setup()