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
f787cda7
Commit
f787cda7
authored
Jul 24, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #675 from jpmens/assemble1
convert sfromm's assemble to module-magic
parents
12ff9b5b
f6fe9124
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
56 deletions
+33
-56
library/assemble
+33
-56
No files found.
library/assemble
View file @
f787cda7
...
@@ -38,14 +38,6 @@ except ImportError:
...
@@ -38,14 +38,6 @@ except ImportError:
# ===========================================
# ===========================================
# Support methods
# Support methods
def
exit_json
(
rc
=
0
,
**
kwargs
):
print
json
.
dumps
(
kwargs
)
sys
.
exit
(
rc
)
def
fail_json
(
**
kwargs
):
kwargs
[
'failed'
]
=
True
exit_json
(
rc
=
1
,
**
kwargs
)
def
assemble_from_fragments
(
path
):
def
assemble_from_fragments
(
path
):
''' assemble a file from a directory of fragments '''
''' assemble a file from a directory of fragments '''
assembled
=
[]
assembled
=
[]
...
@@ -61,67 +53,52 @@ def write_temp_file(data):
...
@@ -61,67 +53,52 @@ def write_temp_file(data):
os
.
close
(
fd
)
os
.
close
(
fd
)
return
path
return
path
def
md5
(
filename
):
# ==============================================================
''' Return MD5 hex digest of local file, or None if file is not present. '''
# main
if
not
os
.
path
.
exists
(
filename
):
return
None
digest
=
_md5
()
blocksize
=
64
*
1024
infile
=
open
(
filename
,
'rb'
)
block
=
infile
.
read
(
blocksize
)
while
block
:
digest
.
update
(
block
)
block
=
infile
.
read
(
blocksize
)
infile
.
close
()
return
digest
.
hexdigest
()
# ===========================================
if
len
(
sys
.
argv
)
==
1
:
fail_json
(
msg
=
"the assemble module requires arguments (-a)"
)
argfile
=
sys
.
argv
[
1
]
def
main
():
if
not
os
.
path
.
exists
(
argfile
):
fail_json
(
msg
=
"Argument file not found"
)
args
=
open
(
argfile
,
'r'
)
.
read
()
module
=
AnsibleModule
(
items
=
shlex
.
split
(
args
)
argument_spec
=
dict
(
syslog
.
openlog
(
'ansible-
%
s'
%
os
.
path
.
basename
(
__file__
))
src
=
dict
(
required
=
True
),
syslog
.
syslog
(
syslog
.
LOG_NOTICE
,
'Invoked with
%
s'
%
args
)
dest
=
dict
(
required
=
True
),
)
)
if
not
len
(
items
):
changed
=
False
fail_json
(
msg
=
"the assemble module requires arguments (-a)"
)
pathmd5
=
None
destmd5
=
None
src
=
os
.
path
.
expanduser
(
module
.
params
[
'src'
])
dest
=
os
.
path
.
expanduser
(
module
.
params
[
'dest'
])
params
=
{}
if
src
:
for
x
in
items
:
(
k
,
v
)
=
x
.
split
(
"="
)
params
[
k
]
=
v
changed
=
False
pathmd5
=
None
destmd5
=
None
src
=
params
.
get
(
'src'
,
None
)
dest
=
params
.
get
(
'dest'
,
None
)
if
src
:
src
=
os
.
path
.
expanduser
(
src
)
src
=
os
.
path
.
expanduser
(
src
)
if
dest
:
if
dest
:
dest
=
os
.
path
.
expanduser
(
dest
)
dest
=
os
.
path
.
expanduser
(
dest
)
if
not
os
.
path
.
exists
(
src
):
if
not
os
.
path
.
exists
(
src
):
fail_json
(
msg
=
"Source (
%
s) does not exist"
%
src
)
fail_json
(
msg
=
"Source (
%
s) does not exist"
%
src
)
if
not
os
.
path
.
isdir
(
src
):
if
not
os
.
path
.
isdir
(
src
):
fail_json
(
msg
=
"Source (
%
s) is not a directory"
%
src
)
fail_json
(
msg
=
"Source (
%
s) is not a directory"
%
src
)
path
=
write_temp_file
(
assemble_from_fragments
(
src
))
path
=
write_temp_file
(
assemble_from_fragments
(
src
))
pathmd5
=
md5
(
path
)
pathmd5
=
module
.
md5
(
path
)
if
os
.
path
.
exists
(
dest
):
if
os
.
path
.
exists
(
dest
):
destmd5
=
md5
(
dest
)
destmd5
=
module
.
md5
(
dest
)
if
pathmd5
!=
destmd5
:
if
pathmd5
!=
destmd5
:
shutil
.
copy
(
path
,
dest
)
shutil
.
copy
(
path
,
dest
)
changed
=
True
changed
=
True
exit_json
(
md5sum
=
pathmd5
,
changed
=
changed
)
# Mission complete
module
.
exit_json
(
src
=
src
,
dest
=
dest
,
md5sum
=
destmd5
,
changed
=
changed
,
msg
=
"OK"
,
daisychain
=
"file"
,
daisychain_args
=
module
.
params
)
# this is magic, see lib/ansible/module_common.py
#<<INCLUDE_ANSIBLE_MODULE_COMMON>>
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