people.rst 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. ****************
  2. People and Teams
  3. ****************
  4. The Launchpad web service, like Launchpad itself, exposes a unified
  5. interface to people and teams. In other words, people and teams
  6. occupy the same namespace. You treat people and teams as the same
  7. type of object, and need to inspect the object to know whether you're
  8. dealing with a person or a team.
  9. People
  10. ======
  11. You can access Launchpad people through the web service interface.
  12. The list of people is available from the service root.
  13. >>> from launchpadlib.testing.helpers import salgado_with_full_permissions
  14. >>> launchpad = salgado_with_full_permissions.login()
  15. >>> people = launchpad.people
  16. The list of people is not fetched until you actually use data.
  17. >>> print(people._wadl_resource.representation)
  18. None
  19. >>> len(people)
  20. 4
  21. >>> print(people._wadl_resource.representation)
  22. {...}
  23. The 'me' attribute is also available from the service root. It's a
  24. quick way to get a reference to your own user account.
  25. >>> me = launchpad.me
  26. >>> print(me.name)
  27. salgado
  28. You can find a person by name.
  29. >>> salgado = launchpad.people['salgado']
  30. >>> print(salgado.name)
  31. salgado
  32. >>> print(salgado.display_name)
  33. Guilherme Salgado
  34. >>> salgado.is_team
  35. False
  36. But if no person by that name is registered, you get the expected KeyError.
  37. >>> launchpad.people['not-a-registered-person']
  38. Traceback (most recent call last):
  39. ...
  40. KeyError: 'not-a-registered-person'
  41. It's not possible to slice a single person from the top-level
  42. collection of people. launchpadlib will try to use the value you pass
  43. in as a person's name, which will almost always fail.
  44. >>> launchpad.people[1]
  45. Traceback (most recent call last):
  46. ...
  47. KeyError: 1
  48. You can find a person by email.
  49. >>> email = salgado.preferred_email_address.email
  50. >>> salgado = launchpad.people.getByEmail(email=email)
  51. >>> print(salgado.name)
  52. salgado
  53. Besides a name and a display name, a person has many other attributes that you
  54. can read.
  55. XXX 05-Jun-2008 BarryWarsaw Some of these attributes are links to further
  56. collections and are not yet tested. Tests will be added in future
  57. branches.
  58. >>> salgado.karma
  59. 0
  60. >>> print(salgado.homepage_content)
  61. None
  62. >>> #salgado.mugshot
  63. >>> #salgado.languages
  64. >>> salgado.hide_email_addresses
  65. False
  66. >>> salgado.date_created
  67. datetime.datetime(2005, 6, 6, 8, 59, 51, 596025, ...)
  68. >>> print(salgado.time_zone)
  69. UTC
  70. >>> salgado.is_valid
  71. True
  72. >>> #salgado.wiki_names
  73. >>> #salgado.irc_nicknames
  74. >>> #salgado.jabber_ids
  75. >>> #salgado.team_memberships
  76. >>> #salgado.open_membership_invitations
  77. >>> #salgado.teams_participated_in
  78. >>> #salgado.teams_indirectly_participated_in
  79. >>> #salgado.confirmed_email_addresses
  80. >>> #salgado.preferred_email_address
  81. >>> print(salgado.mailing_list_auto_subscribe_policy)
  82. Ask me when I join a team
  83. >>> print(salgado.visibility)
  84. Public
  85. Teams
  86. =====
  87. You also access teams using the same interface.
  88. >>> team = launchpad.people['ubuntu-team']
  89. >>> print(team.name)
  90. ubuntu-team
  91. >>> print(team.display_name)
  92. Ubuntu Team
  93. >>> team.is_team
  94. True
  95. Regular people have team attributes, but they're not used.
  96. >>> print(salgado.team_owner)
  97. None
  98. You can find out how a person has membership in a team.
  99. # XXX: salgado, 2008-08-01: Commented because method has been Unexported;
  100. # it should be re-enabled after the operation is exported again.
  101. # >>> path = salgado.findPathToTeam(
  102. # ... team=launchpad.people['mailing-list-experts'])
  103. # >>> [team.name for team in path]
  104. # [u'admins', u'mailing-list-experts']
  105. You can create a new team through the web interface. The simplest case of
  106. this requires only the new team's name, owner and display name.
  107. >>> launchpad.people['bassists']
  108. Traceback (most recent call last):
  109. ...
  110. KeyError: 'bassists'
  111. >>> bassists = launchpad.people.newTeam(
  112. ... name='bassists', display_name='Awesome Rock Bass Players')
  113. >>> print(bassists.name)
  114. bassists
  115. >>> print(bassists.display_name)
  116. Awesome Rock Bass Players
  117. >>> bassists.is_team
  118. True
  119. And of course, that team is now accessible directly.
  120. >>> bassists = launchpad.people['bassists']
  121. >>> print(bassists.name)
  122. bassists
  123. >>> print(bassists.display_name)
  124. Awesome Rock Bass Players
  125. You cannot create the same team twice.
  126. >>> launchpad.people.newTeam(name='bassists', display_name='Bass Gods')
  127. Traceback (most recent call last):
  128. ...
  129. lazr.restfulclient.errors.BadRequest: HTTP Error 400: Bad Request
  130. ...
  131. Actually, the exception contains other useful information.
  132. >>> from launchpadlib.errors import HTTPError
  133. >>> try:
  134. ... launchpad.people.newTeam(
  135. ... name='bassists', display_name='Bass Gods')
  136. ... except HTTPError as e:
  137. ... error = e
  138. >>> error.response['status']
  139. '400'
  140. >>> print(error.content.decode())
  141. name: bassists is already in use by another person or team.
  142. Besides a name and a display name, a team has many other attributes that you
  143. can read.
  144. >>> bassists.karma
  145. 0
  146. >>> print(bassists.homepage_content)
  147. None
  148. >>> bassists.hide_email_addresses
  149. False
  150. >>> bassists.date_created
  151. datetime.datetime(...)
  152. >>> print(bassists.time_zone)
  153. UTC
  154. >>> bassists.is_valid
  155. True
  156. >>> #bassists.team_memberships
  157. >>> #bassists.open_membership_invitations
  158. >>> #bassists.teams_participated_in
  159. >>> #bassists.teams_indirectly_participated_in
  160. >>> #bassists.confirmed_email_addresses
  161. >>> #bassists.team_owner
  162. >>> #bassists.preferred_email_address
  163. >>> #bassists.members
  164. >>> #bassists.admins
  165. >>> #bassists.participants
  166. >>> #bassists.deactivated_members
  167. >>> #bassists.expired_members
  168. >>> #bassists.invited_members
  169. >>> #bassists.member_memberships
  170. >>> #bassists.proposed_members
  171. >>> print(bassists.visibility)
  172. Public
  173. >>> print(bassists.team_description)
  174. None
  175. >>> print(bassists.subscription_policy)
  176. Moderated Team
  177. >>> print(bassists.renewal_policy)
  178. invite them to apply for renewal
  179. >>> print(bassists.default_membership_period)
  180. None
  181. >>> print(bassists.default_renewal_period)
  182. None