Merge lp:~fginther/ppa-dev-tools/ppa_sync-fix-source-package-search into lp:~sergiusens/ppa-dev-tools/ppa_sync

Proposed by Francis Ginther
Status: Needs review
Proposed branch: lp:~fginther/ppa-dev-tools/ppa_sync-fix-source-package-search
Merge into: lp:~sergiusens/ppa-dev-tools/ppa_sync
Diff against target: 106 lines (+65/-6)
2 files modified
bin/credentials.py (+52/-0)
bin/ppa_sync.py (+13/-6)
To merge this branch: bzr merge lp:~fginther/ppa-dev-tools/ppa_sync-fix-source-package-search
Reviewer Review Type Date Requested Status
Sergio Schvezov Pending
Review via email: mp+182908@code.launchpad.net

Commit message

Fix for ppa_sync issue of not syncing packages for all series. Add launchpad credentials pattern from lp:jenkins-launchpad-plugin as launchpad appears to require it now.

Description of the change

Fix for ppa_sync issue of not syncing packages for all series. Add launchpad credentials pattern from lp:jenkins-launchpad-plugin as launchpad appears to require it now.

To post a comment you must log in.

Unmerged revisions

23. By Francis Ginther

Remove credentials file print.

22. By Francis Ginther

Add credentials module from jlp.

21. By Francis Ginther

Use jlp credentials pattern.

20. By Francis Ginther

Look for credentials file in users home dir.

19. By Francis Ginther

Check all source packages before exiting when there is no arch match.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'bin/credentials.py'
2--- bin/credentials.py 1970-01-01 00:00:00 +0000
3+++ bin/credentials.py 2013-08-29 13:49:09 +0000
4@@ -0,0 +1,52 @@
5+
6+import sys
7+import time
8+from launchpadlib.credentials import RequestTokenAuthorizationEngine
9+from lazr.restfulclient.errors import HTTPError
10+
11+
12+ACCESS_TOKEN_POLL_TIME = 1
13+WAITING_FOR_USER = """Open this link:
14+{}
15+to authorize this program to access Launchpad on your behalf.
16+Waiting to hear from Launchpad about your decision. . . ."""
17+
18+
19+class AuthorizeRequestTokenWithConsole(RequestTokenAuthorizationEngine):
20+ """Authorize a token in a server environment (with no browser).
21+
22+ Print a link for the user to copy-and-paste into his/her browser
23+ for authentication.
24+ """
25+
26+ def __init__(self, *args, **kwargs):
27+ # as implemented in AuthorizeRequestTokenWithBrowser
28+ kwargs['consumer_name'] = None
29+ kwargs.pop('allow_access_levels', None)
30+ super(AuthorizeRequestTokenWithConsole, self).__init__(*args, **kwargs)
31+
32+ def make_end_user_authorize_token(self, credentials, request_token):
33+ """Ask the end-user to authorize the token in their browser.
34+
35+ """
36+ authorization_url = self.authorization_url(request_token)
37+ print WAITING_FOR_USER.format(authorization_url)
38+ # if we don't flush we may not see the message
39+ sys.stdout.flush()
40+ while credentials.access_token is None:
41+ time.sleep(ACCESS_TOKEN_POLL_TIME)
42+ try:
43+ credentials.exchange_request_token_for_access_token(
44+ self.web_root)
45+ break
46+ except HTTPError, e:
47+ if e.response.status == 403:
48+ # The user decided not to authorize this
49+ # application.
50+ raise e
51+ elif e.response.status == 401:
52+ # The user has not made a decision yet.
53+ pass
54+ else:
55+ # There was an error accessing the server.
56+ raise e
57
58=== modified file 'bin/ppa_sync.py'
59--- bin/ppa_sync.py 2013-08-06 17:40:01 +0000
60+++ bin/ppa_sync.py 2013-08-29 13:49:09 +0000
61@@ -1,12 +1,15 @@
62 #!/usr/bin/python
63
64 from launchpadlib.launchpad import Launchpad
65+from launchpadlib.credentials import UnencryptedFileCredentialStore
66+from credentials import AuthorizeRequestTokenWithConsole
67
68 import apt
69 import argparse
70 import os.path
71
72-credentials_file = '/home/ubuntu/.launchpad.credentials'
73+credentials_file = os.path.join(
74+ os.path.expanduser('~'), '.launchpad.credentials')
75
76
77 class StringSplitAction(argparse.Action):
78@@ -82,9 +85,9 @@
79 raise EnvironmentError('%s - %s has not built yet' %
80 (package, version))
81 arches.add(title[0])
82- if not arches:
83- raise EnvironmentError('%s - %s seems to be a binary copy' %
84- (package, version))
85+ if not arches:
86+ raise EnvironmentError('%s - %s seems to be a binary copy' %
87+ (package, version))
88 return arches
89
90
91@@ -106,9 +109,13 @@
92 creds = credentials_file
93 else:
94 creds = None
95- launchpad = Launchpad.login_with('ppa_sync', 'production',
96+ LP_APP = 'ppa_sync'
97+ LP_ENV = 'production'
98+ store = UnencryptedFileCredentialStore(creds)
99+ authorization_engine = AuthorizeRequestTokenWithConsole(LP_ENV, LP_APP)
100+ launchpad = Launchpad.login_with(LP_APP, LP_ENV,
101 credentials_file=creds,
102- version='devel')
103+ authorization_engine=authorization_engine)
104
105 ppa_team = launchpad.people[args.source_team]
106 ppa = ppa_team.getPPAByName(name=args.source_ppa)

Subscribers

People subscribed via source and target branches