Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
02d5e831
Commit
02d5e831
authored
Apr 02, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
have apt module raise an error if apt cannot be imported
parent
2cb89c12
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
2 deletions
+11
-2
library/apt
+11
-2
No files found.
library/apt
View file @
02d5e831
...
@@ -23,7 +23,6 @@ except ImportError:
...
@@ -23,7 +23,6 @@ except ImportError:
import
simplejson
as
json
import
simplejson
as
json
import
os
import
os
import
sys
import
sys
import
apt
import
shlex
import
shlex
import
subprocess
import
subprocess
import
traceback
import
traceback
...
@@ -44,6 +43,11 @@ def fail_json(**kwargs):
...
@@ -44,6 +43,11 @@ def fail_json(**kwargs):
kwargs['
failed
'] = True
kwargs['
failed
'] = True
exit_json(rc=1, **kwargs)
exit_json(rc=1, **kwargs)
try:
import apt
except ImportError:
fail_json(msg="could not import apt")
def run_apt(command):
def run_apt(command):
try:
try:
cmd = subprocess.Popen(command, shell=True,
cmd = subprocess.Popen(command, shell=True,
...
@@ -117,24 +121,29 @@ purge = params.get('purge', 'no')
...
@@ -117,24 +121,29 @@ purge = params.get('purge', 'no')
if state not in ['
installed
', '
latest
', '
removed
']:
if state not in ['
installed
', '
latest
', '
removed
']:
fail_json(msg='
invalid
state
')
fail_json(msg='
invalid
state
')
if update_cache not in ['
yes
', '
no
']:
if update_cache not in ['
yes
', '
no
']:
fail_json(msg='
invalid
value
for
update_cache
(
requires
yes
or
no
--
default
is
no
')
fail_json(msg='
invalid
value
for
update_cache
(
requires
yes
or
no
--
default
is
no
')
if purge not in ['
yes
', '
no
']:
if purge not in ['
yes
', '
no
']:
fail_json(msg='
invalid
value
for
purge
(
requires
yes
or
no
--
default
is
no
)
')
fail_json(msg='
invalid
value
for
purge
(
requires
yes
or
no
--
default
is
no
)
')
if package is None and update-cache != '
yes
':
if package is None and update-cache != '
yes
':
fail_json(msg='
pkg
=
name
and
/
or
update
-
cache
=
yes
is
required
')
fail_json(msg='
pkg
=
name
and
/
or
update
-
cache
=
yes
is
required
')
cache = apt.Cache()
cache = apt.Cache()
if update_cache == '
yes
':
if update_cache == '
yes
':
cache.update()
cache.update()
cache.open()
cache.open()
if state == '
latest
':
if state == '
latest
':
changed = install(package, cache, upgrade=True)
changed = install(package, cache, upgrade=True)
if state == '
installed
':
el
if state == '
installed
':
changed = install(package, cache)
changed = install(package, cache)
elif state == '
removed
':
elif state == '
removed
':
changed = remove(package, cache, purge == '
yes
')
changed = remove(package, cache, purge == '
yes
')
exit_json(changed=changed)
exit_json(changed=changed)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment