mirror of
				https://git.launchpad.net/ubuntu-dev-tools
				synced 2025-10-31 05:54:03 +00:00 
			
		
		
		
	Removed (superseded by Launchpad API support)
* ubuntutools/lp/cookie.py * ubuntutools/lp/urlopener.py And removed references from these files as necessary: * requestsync * ubuntutools/lp/functions.py
This commit is contained in:
		
							parent
							
								
									a58f36a5db
								
							
						
					
					
						commit
						7eb81c1185
					
				
							
								
								
									
										2
									
								
								debian/changelog
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								debian/changelog
									
									
									
									
										vendored
									
									
								
							| @ -25,6 +25,8 @@ ubuntu-dev-tools (0.75) UNRELEASED; urgency=low | |||||||
|   * ubuntutools/lp/libsupport.py: Fail if we're unable to import launchpadlib |   * ubuntutools/lp/libsupport.py: Fail if we're unable to import launchpadlib | ||||||
|     (we need it to run stuff). |     (we need it to run stuff). | ||||||
|   * ubuntutools/lp/urlopener.py: Removed - module no longer needed. |   * ubuntutools/lp/urlopener.py: Removed - module no longer needed. | ||||||
|  |   * ubuntutools/lp/cookie.py: Removed - module no longer needed - we use | ||||||
|  |     Launchpad API support now. | ||||||
|   * buildd: |   * buildd: | ||||||
|     - Use launchpadlib to check the Ubuntu release is valid. |     - Use launchpadlib to check the Ubuntu release is valid. | ||||||
|     - Moved Launchpad module imports here - speed up usage parsing to improve |     - Moved Launchpad module imports here - speed up usage parsing to improve | ||||||
|  | |||||||
| @ -36,7 +36,6 @@ from optparse import OptionParser | |||||||
| from time import sleep | from time import sleep | ||||||
| 
 | 
 | ||||||
| # ubuntu-dev-tools modules. | # ubuntu-dev-tools modules. | ||||||
| import ubuntutools.lp.cookie as lp_cookie |  | ||||||
| import ubuntutools.lp.functions as lp_functions | import ubuntutools.lp.functions as lp_functions | ||||||
| import ubuntutools.lp.libsupport as lp_libsupport | import ubuntutools.lp.libsupport as lp_libsupport | ||||||
| import ubuntutools.lp.udtexceptions as udtexceptions | import ubuntutools.lp.udtexceptions as udtexceptions | ||||||
| @ -44,21 +43,16 @@ import ubuntutools.lp.udtexceptions as udtexceptions | |||||||
| import ubuntutools.common | import ubuntutools.common | ||||||
| import ubuntutools.packages | import ubuntutools.packages | ||||||
| 
 | 
 | ||||||
| launchpad_cookiefile = lp_cookie.prepareLaunchpadCookie() |  | ||||||
| 
 |  | ||||||
| def checkNeedsSponsorship(srcpkg): | def checkNeedsSponsorship(srcpkg): | ||||||
|     """ |     """ | ||||||
|         Check that the user has the appropriate permissions by checking what |         Check that the user has the appropriate permissions by checking what | ||||||
|         Launchpad returns while authenticating with their cookie. |         Launchpad returns when we check if someone can upload a package or not. | ||||||
| 
 | 
 | ||||||
|         If they are an indirect or direct member of the ~ubuntu-dev team on |         If they are an indirect or direct member of the ~ubuntu-dev team on | ||||||
|         Launchpad - sponsorship is not required if the package is in the |         Launchpad - sponsorship is not required if the package is in the | ||||||
|         universe / multiverse component. |         universe / multiverse component. | ||||||
| 
 | 
 | ||||||
|         If they are in the ~ubuntu-core-dev team, no sponsorship required. |         If they are in the ~ubuntu-core-dev team, no sponsorship required. | ||||||
| 
 |  | ||||||
|         The prepareLaunchpadCookie function above shall ensure that a cookie |  | ||||||
|         file exists first. |  | ||||||
|     """ |     """ | ||||||
|     if not lp_functions.canUploadPackage(srcpkg): |     if not lp_functions.canUploadPackage(srcpkg): | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1,106 +0,0 @@ | |||||||
| # |  | ||||||
| #   cookie.py - functions related to the creation of Launchpad cookie files |  | ||||||
| #                 and authentication. |  | ||||||
| # |  | ||||||
| #   Copyright (C) 2008 Jonathan Davies <jpds@ubuntu.com> |  | ||||||
| #   Copyright (C) 2008 Siegfried-Angel Gevatter Pujals <rainct@ubuntu.com> |  | ||||||
| # |  | ||||||
| #   This program is free software; you can redistribute it and/or |  | ||||||
| #   modify it under the terms of the GNU General Public License |  | ||||||
| #   as published by the Free Software Foundation; either version 3 |  | ||||||
| #   of the License, or (at your option) any later version. |  | ||||||
| #  |  | ||||||
| #   This program is distributed in the hope that it will be useful, |  | ||||||
| #   but WITHOUT ANY WARRANTY; without even the implied warranty of |  | ||||||
| #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the |  | ||||||
| #   GNU General Public License for more details. |  | ||||||
| # |  | ||||||
| #   Please see the /usr/share/common-licenses/GPL file for the full text of |  | ||||||
| #   the GNU General Public License license. |  | ||||||
| # |  | ||||||
| 
 |  | ||||||
| # Modules. |  | ||||||
| import glob |  | ||||||
| import os |  | ||||||
| import sys |  | ||||||
| 
 |  | ||||||
| def prepareLaunchpadCookie(): |  | ||||||
|     """ |  | ||||||
|         Search for a cookie file in the places as defined by try_globs. |  | ||||||
|         We shall use this cookie for authentication with Launchpad. |  | ||||||
|     """ |  | ||||||
|      |  | ||||||
|     # We do not have our cookie. |  | ||||||
|     launchpad_cookiefile = None |  | ||||||
|     # Look in common locations. |  | ||||||
|     try_globs = ('~/.lpcookie.txt', '~/.mozilla/*/*/cookies.sqlite', |  | ||||||
|                  '~/.mozilla/*/*/cookies.txt') |  | ||||||
|      |  | ||||||
|     cookie_file_list = [] |  | ||||||
|     if launchpad_cookiefile == None: |  | ||||||
|         for try_glob in try_globs: |  | ||||||
|             try: |  | ||||||
|                 cookie_file_list += glob.glob(os.path.expanduser(try_glob)) |  | ||||||
|             except: |  | ||||||
|                 pass |  | ||||||
| 
 |  | ||||||
|     for cookie_file in cookie_file_list: |  | ||||||
|         launchpad_cookiefile = _check_for_launchpad_cookie(cookie_file) |  | ||||||
|         if launchpad_cookiefile != None: |  | ||||||
|             break |  | ||||||
| 
 |  | ||||||
|     # Unable to find a correct file. |  | ||||||
|     if launchpad_cookiefile == None: |  | ||||||
|         print >> sys.stderr, "Could not find cookie file for Launchpad. " |  | ||||||
|         print >> sys.stderr, "Looked in: %s" % ", ".join(try_globs) |  | ||||||
|         print >> sys.stderr, "You should be able to create a valid file by " \ |  | ||||||
|             "logging into Launchpad with Firefox." |  | ||||||
|         sys.exit(1) |  | ||||||
| 
 |  | ||||||
|     return launchpad_cookiefile |  | ||||||
| 
 |  | ||||||
| def _check_for_launchpad_cookie(cookie_file): |  | ||||||
|     # Found SQLite file? Parse information from it. |  | ||||||
|     if 'cookies.sqlite' in cookie_file: |  | ||||||
|         import sqlite3 as sqlite |  | ||||||
| 
 |  | ||||||
|         con = sqlite.connect(cookie_file) |  | ||||||
|         cur = con.cursor() |  | ||||||
|         try: |  | ||||||
|             cur.execute("select host, path, isSecure, expiry, name, value from moz_cookies where host like ?", ['%%launchpad%%']) |  | ||||||
|         except sqlite.OperationalError: |  | ||||||
|             print 'Warning: Database "%s" is locked; ignoring it.' % cookie_file |  | ||||||
|             return None |  | ||||||
| 
 |  | ||||||
|         # No matching cookies?  Abort. |  | ||||||
|         items = cur.fetchall() |  | ||||||
|         if len(items) == 0: |  | ||||||
|             return None |  | ||||||
| 
 |  | ||||||
|         ftstr = ["FALSE", "TRUE"] |  | ||||||
| 
 |  | ||||||
|         # This shall be where our new cookie file lives - at ~/.lpcookie.txt |  | ||||||
|         newLPCookieLocation = os.path.expanduser("~/.lpcookie.txt") |  | ||||||
| 
 |  | ||||||
|         # Open file for writing. |  | ||||||
|         try: |  | ||||||
|             newLPCookie = open(newLPCookieLocation, 'w') |  | ||||||
|             # For security reasons, change file mode to write and read |  | ||||||
|             # only by owner. |  | ||||||
|             os.chmod(newLPCookieLocation, 0600) |  | ||||||
|             newLPCookie.write("# HTTP Cookie File for Launchpad.\n") # Header. |  | ||||||
| 
 |  | ||||||
|             for item in items: |  | ||||||
|                 # Write entries. |  | ||||||
|                 newLPCookie.write("%s\t%s\t%s\t%s\t%s\t%s\t%s\n" % ( |  | ||||||
|                     item[0], ftstr[item[0].startswith('.')], item[1], |  | ||||||
|                     ftstr[item[2]], item[3], item[4], item[5])) |  | ||||||
|         finally: |  | ||||||
|             newLPCookie.close()     # And close file. |  | ||||||
| 
 |  | ||||||
|         return newLPCookieLocation |  | ||||||
|     else: |  | ||||||
|         if open(cookie_file).read().find('launchpad.net') != -1: |  | ||||||
|             return cookie_file |  | ||||||
| 
 |  | ||||||
|     return None |  | ||||||
| @ -18,7 +18,6 @@ | |||||||
| #   the GNU General Public License license. | #   the GNU General Public License license. | ||||||
| # | # | ||||||
| 
 | 
 | ||||||
| import cookie |  | ||||||
| import urllib2 | import urllib2 | ||||||
| import sys | import sys | ||||||
| from udtexceptions import PackageNotFoundException, SeriesNotFoundException | from udtexceptions import PackageNotFoundException, SeriesNotFoundException | ||||||
|  | |||||||
| @ -1,40 +0,0 @@ | |||||||
| # |  | ||||||
| #   urlopener.py - set up a special URL opener which uses a Launchpad cookie |  | ||||||
| #                    file for authentication. |  | ||||||
| # |  | ||||||
| #   Copyright (C) 2008 Jonathan Davies <jpds@ubuntu.com> |  | ||||||
| # |  | ||||||
| #   This program is free software; you can redistribute it and/or |  | ||||||
| #   modify it under the terms of the GNU General Public License |  | ||||||
| #   as published by the Free Software Foundation; either version 3 |  | ||||||
| #   of the License, or (at your option) any later version. |  | ||||||
| #  |  | ||||||
| #   This program is distributed in the hope that it will be useful, |  | ||||||
| #   but WITHOUT ANY WARRANTY; without even the implied warranty of |  | ||||||
| #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the |  | ||||||
| #   GNU General Public License for more details. |  | ||||||
| # |  | ||||||
| #   Please see the /usr/share/common-licenses/GPL file for the full text of |  | ||||||
| #   the GNU General Public License license. |  | ||||||
| # |  | ||||||
| 
 |  | ||||||
| # Modules. |  | ||||||
| import cookielib |  | ||||||
| import urllib2 |  | ||||||
| 
 |  | ||||||
| def setupLaunchpadUrlOpener(cookie): |  | ||||||
|     """ Build HTML opener with cookie file. """ |  | ||||||
| 
 |  | ||||||
|     # Attempt to load our cookie file. |  | ||||||
|     try: |  | ||||||
|         cj = cookielib.MozillaCookieJar() |  | ||||||
|         cj.load(cookie) |  | ||||||
|     except cookielib.LoadError, error: |  | ||||||
|         print "Unable to load cookie file: %s (%s)" % (cookie, error) |  | ||||||
|         sys.exit(1) |  | ||||||
| 
 |  | ||||||
|     # Add cookie to our URL opener. |  | ||||||
|     urlopener = urllib2.build_opener() |  | ||||||
|     urlopener.add_handler(urllib2.HTTPCookieProcessor(cj)) |  | ||||||
|      |  | ||||||
|     return urlopener |  | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user