Cleaning up of apt_repository module and removing wget parts

This commit is contained in:
James Cammarata 2013-08-13 16:11:03 -05:00
parent de404eac06
commit 10a0f03cdc

View file

@ -30,7 +30,6 @@ notes:
- This module works on Debian and Ubuntu and requires only C(python-apt) package. - This module works on Debian and Ubuntu and requires only C(python-apt) package.
- This module supports Debian Squeeze (version 6) as well as its successors. - This module supports Debian Squeeze (version 6) as well as its successors.
- This module treats Debian and Ubuntu distributions separately. So PPA could be installed only on Ubuntu machines. - This module treats Debian and Ubuntu distributions separately. So PPA could be installed only on Ubuntu machines.
- For PPA support you either need python-pycurl or wget on the client.
options: options:
repo: repo:
required: true required: true
@ -45,7 +44,7 @@ options:
- A source string state. - A source string state.
author: Alexander Saltanov author: Alexander Saltanov
version_added: "0.7" version_added: "0.7"
requirements: [ python-apt ] requirements: [ python-apt, python-pycurl ]
''' '''
EXAMPLES = ''' EXAMPLES = '''
@ -67,7 +66,6 @@ import glob
import json import json
import os import os
import re import re
import subprocess
import tempfile import tempfile
try: try:
@ -78,6 +76,11 @@ try:
except ImportError: except ImportError:
HAVE_PYTHON_APT = False HAVE_PYTHON_APT = False
try:
import pycurl
HAVE_PYCURL = True
except ImportError:
HAVE_PYCURL = False
VALID_SOURCE_TYPES = ('deb', 'deb-src') VALID_SOURCE_TYPES = ('deb', 'deb-src')
@ -94,15 +97,6 @@ class InvalidSource(Exception):
pass pass
def get_executable_from_path(cmd):
full_path = [os.path.join(p, cmd)
for p in os.environ.get("PATH", "").split(":")
if os.path.isfile(os.path.join(p, cmd))]
if full_path:
return full_path[0]
return None
# Simple version of aptsources.sourceslist.SourcesList. # Simple version of aptsources.sourceslist.SourcesList.
# No advanced logic and no backups inside. # No advanced logic and no backups inside.
class SourcesList(object): class SourcesList(object):
@ -272,20 +266,9 @@ class UbuntuSourcesList(SourcesList):
def _get_ppa_info(self, owner_name, ppa_name): def _get_ppa_info(self, owner_name, ppa_name):
# we can not use urllib2 here as it does not do cert verification # we can not use urllib2 here as it does not do cert verification
lp_api = self.LP_API % (owner_name, ppa_name) lp_api = self.LP_API % (owner_name, ppa_name)
try:
return self._get_ppa_info_curl(lp_api) return self._get_ppa_info_curl(lp_api)
except ImportError:
return self._get_ppa_info_wget(lp_api)
def _get_ppa_info_wget(self, lp_api):
wget = get_executable_from_path("wget")
p = subprocess.Popen([wget, "-q", "-O", "-",
"--header=Accept: application/json",
lp_api], stdout=subprocess.PIPE)
return json.loads(p.communicate()[0])
def _get_ppa_info_curl(self, lp_api): def _get_ppa_info_curl(self, lp_api):
import pycurl
callback = CurlCallback() callback = CurlCallback()
curl = pycurl.Curl() curl = pycurl.Curl()
curl.setopt(pycurl.SSL_VERIFYPEER, 1) curl.setopt(pycurl.SSL_VERIFYPEER, 1)
@ -351,14 +334,8 @@ def main():
if not HAVE_PYTHON_APT: if not HAVE_PYTHON_APT:
module.fail_json(msg='Could not import python modules: apt_pkg. Please install python-apt package.') module.fail_json(msg='Could not import python modules: apt_pkg. Please install python-apt package.')
# see if we have something that can download from https with cert if not HAVE_PYCURL:
# checking module.fail_json(msg='Could not import python modules: pycurl. Please install python-pycurl package.')
try:
import pycurl
except ImportError:
wget = get_executable_from_path("wget")
if not wget:
module.fail_json(msg="Need the python-pycurl or wget package")
repo = module.params['repo'] repo = module.params['repo']
state = module.params['state'] state = module.params['state']