toolsutils.py
branchstable
changeset 7155 4bab50b02927
parent 6495 3187112bc7cc
child 7301 93e96700e0c0
equal deleted inserted replaced
7151:04d0624a1832 7155:4bab50b02927
    56 
    56 
    57 def create_dir(directory):
    57 def create_dir(directory):
    58     """create a directory if it doesn't exist yet"""
    58     """create a directory if it doesn't exist yet"""
    59     try:
    59     try:
    60         makedirs(directory)
    60         makedirs(directory)
    61         print '-> created directory %s.' % directory
    61         print '-> created directory %s' % directory
    62     except OSError, ex:
    62     except OSError, ex:
    63         import errno
    63         import errno
    64         if ex.errno != errno.EEXIST:
    64         if ex.errno != errno.EEXIST:
    65             raise
    65             raise
    66         print '-> directory %s already exists, no need to create it.' % directory
    66         print '-> no need to create existing directory %s' % directory
    67 
    67 
    68 def create_symlink(source, target):
    68 def create_symlink(source, target):
    69     """create a symbolic link"""
    69     """create a symbolic link"""
    70     if exists(target):
    70     if exists(target):
    71         remove(target)
    71         remove(target)
   152     fobj.close()
   152     fobj.close()
   153 
   153 
   154 def restrict_perms_to_user(filepath, log=None):
   154 def restrict_perms_to_user(filepath, log=None):
   155     """set -rw------- permission on the given file"""
   155     """set -rw------- permission on the given file"""
   156     if log:
   156     if log:
   157         log('set %s permissions to 0600', filepath)
   157         log('set permissions to 0600 for %s', filepath)
   158     else:
   158     else:
   159         print '-> set %s permissions to 0600' % filepath
   159         print '-> set permissions to 0600 for %s' % filepath
   160     chmod(filepath, 0600)
   160     chmod(filepath, 0600)
   161 
   161 
   162 def read_config(config_file):
   162 def read_config(config_file):
   163     """read the instance configuration from a file and return it as a
   163     """read the instance configuration from a file and return it as a
   164     dictionnary
   164     dictionnary