Sugar.profile: Difference between revisions

From OLPC
Jump to navigation Jump to search
(Updated "How do I get the school server with which this child is associated" with code that works on both older and new implementations)
 
(8 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Sugar Almanac}}

The profile package can be used to get access to user specific details such as his/her nick_name, XO colors, public key, etc. Much of these details are accessed by first creating a Profile object. However, there are several shortcut helper functions that provide access to some user details directly.
The profile package can be used to get access to user specific details such as his/her nick_name, XO colors, public key, etc. Much of these details are accessed by first creating a Profile object. However, there are several shortcut helper functions that provide access to some user details directly.


Line 27: Line 29:
</pre>
</pre>


==- How do I access this XO's public key? ===
=== How do I access this XO's public key? ===
<pre>
<pre>
from sugar import profile
from sugar import profile
Line 42: Line 44:


=== How do I get the nick name, color and public key information for this XO? ===
=== How do I get the nick name, color and public key information for this XO? ===
See the documentation for [[Helper Functions]].
See the documentation for [[#Helper Functions | Helper Functions]].

=== How do I get the school server with which this child is associated? ===

Method on the 82: DEPRECATED
<pre>
from sugar import profile
...
#prof will refer to a Profile object used to access user information
prof = profile.get_profile()

#Print out the name of the school server this XO is registered with
print prof.jabber_server
#Print out whether this XO is actually registered with a school server
print prof.jabber_registered
</pre>

Get school server with both older and new implementations.
<pre>
from sugar import profile
...
prof = profile.get_profile()

jabber_serv = None
if hasattr(profile, 'jabber_server'):
jabber_serv = profile.jabber_server
else:
import gconf
client = gconf.client_get_default()
jabber_serv = client.get_string("/desktop/sugar/collaboration/jabber_server")
</pre>

Latest revision as of 19:55, 7 January 2010

  Sugar Almanac

The profile package can be used to get access to user specific details such as his/her nick_name, XO colors, public key, etc. Much of these details are accessed by first creating a Profile object. However, there are several shortcut helper functions that provide access to some user details directly.

Helper Functions

How do I get the user's nick name?

from sugar import profile 
...
        #prof will refer to a Profile object used to access user information
        prof = profile.get_profile()

        # Two ways to print nickname: either through profile object, or through a helper funciton in sugar.profile
        print prof.nick_name
        print profile.get_nick_name()

How do I get the XO colors set by the user?

from sugar import profile 
...
        #prof will refer to a Profile object used to access user information
        prof = profile.get_profile()

        # Two ways to get the XO colors: through profile object or using helper function
        print prof.color.to_string()
        print profile.get_color().to_string()

How do I access this XO's public key?

from sugar import profile 
...
        #prof will refer to a Profile object used to access user information
        prof = profile.get_profile()

        #Two ways to get the public key for this XO: through Profile object or with helper function
        print prof.pubkey
        print profile.get_pubkey()

Class: Profile

How do I get the nick name, color and public key information for this XO?

See the documentation for Helper Functions.

How do I get the school server with which this child is associated?

Method on the 82: DEPRECATED

from sugar import profile
...
        #prof will refer to a Profile object used to access user information
        prof = profile.get_profile()

        #Print out the name of the school server this XO is registered with
        print prof.jabber_server
        #Print out whether this XO is actually registered with a school server
        print prof.jabber_registered

Get school server with both older and new implementations.

from sugar import profile
...
        prof = profile.get_profile()

        jabber_serv = None
        if hasattr(profile, 'jabber_server'):
            jabber_serv = profile.jabber_server
        else:
            import gconf
            client = gconf.client_get_default()
            jabber_serv = client.get_string("/desktop/sugar/collaboration/jabber_server")