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
dfcb9d3c
Commit
dfcb9d3c
authored
Sep 04, 2012
by
Daniel Hokka Zakrisson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move backup to module_common
parent
7c2fe3da
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
18 deletions
+15
-18
lib/ansible/module_common.py
+14
-0
library/copy
+1
-18
No files found.
lib/ansible/module_common.py
View file @
dfcb9d3c
...
@@ -47,6 +47,8 @@ import subprocess
...
@@ -47,6 +47,8 @@ import subprocess
import sys
import sys
import syslog
import syslog
import types
import types
import time
import shutil
try:
try:
from hashlib import md5 as _md5
from hashlib import md5 as _md5
...
@@ -274,6 +276,18 @@ class AnsibleModule(object):
...
@@ -274,6 +276,18 @@ class AnsibleModule(object):
infile.close()
infile.close()
return digest.hexdigest()
return digest.hexdigest()
def backuplocal(self, fn):
'''make a date-marked backup of the specified file, return True or False on success or failure'''
# backups named basename-YYYY-MM-DD@HH:MM~
ext = time.strftime("
%
Y-
%
m-
%
d@
%
H:
%
M~", time.localtime(time.time()))
backupdest = '
%
s.
%
s'
%
(fn, ext)
try:
shutil.copy2(fn, backupdest)
except shutil.Error, e:
self.fail_json(msg='Could not make backup of
%
s to
%
s:
%
s'
%
(fn, backupdest, e))
return backupdest
# == END DYNAMICALLY INSERTED CODE ===
# == END DYNAMICALLY INSERTED CODE ===
...
...
library/copy
View file @
dfcb9d3c
...
@@ -20,19 +20,6 @@
...
@@ -20,19 +20,6 @@
import
os
import
os
import
shutil
import
shutil
import
time
def
backuplocal
(
fn
):
"""make a date-marked backup of the specified file, return True or False on success or failure"""
# backups named basename-YYYY-MM-DD@HH:MM~
ext
=
time
.
strftime
(
"
%
Y-
%
m-
%
d@
%
H:
%
M~"
,
time
.
localtime
(
time
.
time
()))
backupdest
=
'
%
s.
%
s'
%
(
fn
,
ext
)
try
:
shutil
.
copy2
(
fn
,
backupdest
)
except
shutil
.
Error
,
e
:
return
False
,
'Could not make backup of
%
s to
%
s:
%
s'
%
(
fn
,
backupdest
,
e
)
return
True
,
backupdest
def
main
():
def
main
():
...
@@ -76,11 +63,7 @@ def main():
...
@@ -76,11 +63,7 @@ def main():
try
:
try
:
if
backup
:
if
backup
:
if
os
.
path
.
exists
(
dest
):
if
os
.
path
.
exists
(
dest
):
success
,
msg
=
backuplocal
(
dest
)
backup_file
=
module
.
backuplocal
(
dest
)
if
not
success
:
module
.
fail_jason
(
msg
=
msg
)
else
:
backup_file
=
msg
shutil
.
copyfile
(
src
,
dest
)
shutil
.
copyfile
(
src
,
dest
)
except
shutil
.
Error
:
except
shutil
.
Error
:
module
.
fail_json
(
msg
=
"failed to copy:
%
s and
%
s are the same"
%
(
src
,
dest
))
module
.
fail_json
(
msg
=
"failed to copy:
%
s and
%
s are the same"
%
(
src
,
dest
))
...
...
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