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
f2e3fa95
Commit
f2e3fa95
authored
Jul 24, 2013
by
Andreas Kaiser
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix pkgin search (yielding wrong results under certain conditions, see inline comments).
parent
d1effecb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
8 deletions
+36
-8
library/packaging/pkgin
+36
-8
No files found.
library/packaging/pkgin
View file @
f2e3fa95
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
# (c) 2013, Shaun Zinck
# (c) 2013, Shaun Zinck
# Written by Shaun Zinck <shaun.zinck at gmail.com>
# Written by Shaun Zinck <shaun.zinck at gmail.com>
# Based on pacman module written by Afterburn <http://github.com/afterburn>
# Based on pacman module written by Afterburn <http://github.com/afterburn>
# that was based on apt module written by Matthew Williams <matthew@flowroute.com>
# that was based on apt module written by Matthew Williams <matthew@flowroute.com>
#
#
# This module is free software: you can redistribute it and/or modify
# This module is free software: you can redistribute it and/or modify
...
@@ -49,7 +49,7 @@ EXAMPLES = '''
...
@@ -49,7 +49,7 @@ EXAMPLES = '''
# remove package foo
# remove package foo
- pkgin: name=foo state=absent
- pkgin: name=foo state=absent
# remove packages foo and bar
# remove packages foo and bar
- pkgin: name=foo,bar state=absent
- pkgin: name=foo,bar state=absent
'''
'''
...
@@ -59,6 +59,7 @@ import shlex
...
@@ -59,6 +59,7 @@ import shlex
import
os
import
os
import
sys
import
sys
def
query_package
(
module
,
pkgin_path
,
name
,
state
=
"present"
):
def
query_package
(
module
,
pkgin_path
,
name
,
state
=
"present"
):
if
state
==
"present"
:
if
state
==
"present"
:
...
@@ -66,13 +67,40 @@ def query_package(module, pkgin_path, name, state="present"):
...
@@ -66,13 +67,40 @@ def query_package(module, pkgin_path, name, state="present"):
rc
,
out
,
err
=
module
.
run_command
(
"
%
s list | grep ^
%
s"
%
(
pkgin_path
,
name
))
rc
,
out
,
err
=
module
.
run_command
(
"
%
s list | grep ^
%
s"
%
(
pkgin_path
,
name
))
if
rc
==
0
:
if
rc
==
0
:
return
True
# At least one package with a package name that starts with ``name``
# is installed. For some cases this is not sufficient to determine
# wether the queried package is installed.
#
# E.g. for ``name='gcc47'``, ``gcc47`` not being installed, but
# ``gcc47-libs`` being installed, ``out`` would be:
#
# gcc47-libs-4.7.2nb4 The GNU Compiler Collection (GCC) support shared libraries.
#
# Multiline output is also possible, for example with the same query
# and bot ``gcc47`` and ``gcc47-libs`` being installed:
#
# gcc47-libs-4.7.2nb4 The GNU Compiler Collection (GCC) support shared libraries.
# gcc47-4.7.2nb3 The GNU Compiler Collection (GCC) - 4.7 Release Series
# Loop over lines in ``out``
for
line
in
out
.
split
(
'
\n
'
):
# Strip description
# (results in sth. like 'gcc47-libs-4.7.2nb4')
pkgname_with_version
=
out
.
split
(
' '
)[
0
]
# Strip version
# (results in sth like 'gcc47-libs')
pkgname_without_version
=
'-'
.
join
(
pkgname_with_version
.
split
(
'-'
)[:
-
1
])
if
name
==
pkgname_without_version
:
return
True
return
False
return
False
def
remove_packages
(
module
,
pkgin_path
,
packages
):
def
remove_packages
(
module
,
pkgin_path
,
packages
):
remove_c
=
0
remove_c
=
0
# Using a for loop incase of error, we can report the package that failed
# Using a for loop incase of error, we can report the package that failed
for
package
in
packages
:
for
package
in
packages
:
...
@@ -84,7 +112,7 @@ def remove_packages(module, pkgin_path, packages):
...
@@ -84,7 +112,7 @@ def remove_packages(module, pkgin_path, packages):
if
query_package
(
module
,
pkgin_path
,
package
):
if
query_package
(
module
,
pkgin_path
,
package
):
module
.
fail_json
(
msg
=
"failed to remove
%
s:
%
s"
%
(
package
,
out
))
module
.
fail_json
(
msg
=
"failed to remove
%
s:
%
s"
%
(
package
,
out
))
remove_c
+=
1
remove_c
+=
1
if
remove_c
>
0
:
if
remove_c
>
0
:
...
@@ -108,7 +136,7 @@ def install_packages(module, pkgin_path, packages):
...
@@ -108,7 +136,7 @@ def install_packages(module, pkgin_path, packages):
module
.
fail_json
(
msg
=
"failed to install
%
s:
%
s"
%
(
package
,
out
))
module
.
fail_json
(
msg
=
"failed to install
%
s:
%
s"
%
(
package
,
out
))
install_c
+=
1
install_c
+=
1
if
install_c
>
0
:
if
install_c
>
0
:
module
.
exit_json
(
changed
=
True
,
msg
=
"present
%
s package(s)"
%
(
install_c
))
module
.
exit_json
(
changed
=
True
,
msg
=
"present
%
s package(s)"
%
(
install_c
))
...
@@ -136,5 +164,5 @@ def main():
...
@@ -136,5 +164,5 @@ def main():
# this is magic, see lib/ansible/module_common.py
# this is magic, see lib/ansible/module_common.py
#<<INCLUDE_ANSIBLE_MODULE_COMMON>>
#<<INCLUDE_ANSIBLE_MODULE_COMMON>>
main
()
main
()
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