1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
import os
from snakeoil.osutils import (ensure_dirs as snakeoil_ensure_dirs)
def ensure_dirs(path, gid=-1, uid=-1, mode=0o700, minimal=True, failback=None, fatal=False):
'''Wrapper to snakeoil.osutil's ensure_dirs()
This additionally allows for failures to run
cleanup or other code and/or raise fatal errors.
@param path: directory to ensure exists on disk
@param gid: a valid GID to set any created directories to
@param uid: a valid UID to set any created directories to
@param mode: permissions to set any created directories to
@param minimal: boolean controlling whether or not the specified mode
must be enforced, or is the minimal permissions necessary. For example,
if mode=0755, minimal=True, and a directory exists with mode 0707,
this will restore the missing group perms resulting in 757.
@param failback: function to run in the event of a failed attemp
to create the directory.
@return: True if the directory could be created/ensured to have those
permissions, False if not.
'''
succeeded = snakeoil_ensure_dirs(path, gid=-1, uid=-1, mode=mode, minimal=True)
if not succeeded:
if failback:
failback()
if fatal:
raise IOError(
"Failed to create directory: %s" % path)
return succeeded
def updatefiles(config, logger):
filename = config['dev-seedfile']
old = filename + '.old'
try:
logger.info("Backing up existing file...")
if os.path.exists(old):
logger.debug(
"MAIN: _action_updatefile; Removing 'old' seed file: %s"
% old)
os.unlink(old)
if os.path.exists(filename):
logger.debug(
"MAIN: _action_updatefile; Renaming current seed file to: "
"%s" % old)
os.rename(filename, old)
if os.path.exists(filename + '.new'):
logger.debug(
"MAIN: _action_updatefile; Renaming '.new' seed file to: %s"
% filename)
os.rename(filename + '.new', filename)
except IOError:
raise
return False
return True
|