Package config_common :: Module deploy
[hide private]
[frames] | no frames]

Source Code for Module config_common.deploy

 1  # 
 2  # Copyright (c) 2008--2016 Red Hat, Inc. 
 3  # 
 4  # This software is licensed to you under the GNU General Public License, 
 5  # version 2 (GPLv2). There is NO WARRANTY for this software, express or 
 6  # implied, including the implied warranties of MERCHANTABILITY or FITNESS 
 7  # FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 
 8  # along with this software; if not, see 
 9  # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. 
10  # 
11  # Red Hat trademarks are not licensed under GPLv2. No permission is 
12  # granted to use or replicate Red Hat trademarks that are incorporated 
13  # in this software or its documentation. 
14  # 
15   
16  import os 
17  import sys 
18   
19  from config_common.transactions import DeployTransaction, FailedRollback 
20  from config_common import file_utils 
21  from config_common import cfg_exceptions 
22   
23 -def deploy_msg_callback(path):
24 print("Deploying %s" % path)
25
26 -def deploy_files(topdir, repository, files, excludes = None, config_channel = None):
27 topdir = topdir or os.sep 28 if not excludes: 29 excludes = [] 30 dep_trans = DeployTransaction(transaction_root=topdir) 31 dep_trans.deploy_callback(deploy_msg_callback) 32 33 for path in files: 34 if path in excludes: 35 print("Excluding %s" % path) 36 else: 37 try: 38 if config_channel: 39 args = (config_channel, path) 40 else: 41 args = (path, ) 42 kwargs = {'auto_delete': 0, 'dest_directory': topdir} 43 finfo = repository.get_file_info(*args, **kwargs) 44 except cfg_exceptions.DirectoryEntryIsFile: 45 e = sys.exc_info()[1] 46 print("Error: unable to deploy directory %s, as it is already a file on disk" % e[0]) 47 continue 48 49 if finfo is None: 50 # File disappeared since we called the function 51 continue 52 53 (processed_path, file_info, dirs_created) = finfo 54 try: 55 dep_trans.add_preprocessed(path, processed_path, file_info, dirs_created) 56 except cfg_exceptions.UserNotFound: 57 e = sys.exc_info()[1] 58 print("Error: unable to deploy file %s, information on user '%s' could not be found." % (path,e[0])) 59 continue 60 except cfg_exceptions.GroupNotFound: 61 e = sys.exc_info()[1] 62 print("Error: unable to deploy file %s, information on group '%s' could not be found." % (path, e[0])) 63 continue 64 65 try: 66 dep_trans.deploy() 67 #5/3/05 wregglej - 136415 added missing user exception stuff. 68 except cfg_exceptions.UserNotFound: 69 e = sys.exc_info()[1] 70 try_rollback(dep_trans, "Error unable to deploy file, information on user '%s' could not be found" % e[0]) 71 except cfg_exceptions.GroupNotFound: 72 e = sys.exc_info()[1] 73 try_rollback(dep_trans, "Error: unable to deploy file, information on group '%s' could not be found" % e[0]) 74 except cfg_exceptions.FileEntryIsDirectory: 75 e = sys.exc_info()[1] 76 try_rollback(dep_trans, "Error: unable to deploy file %s, as it is already a directory on disk" % e[0]) 77 except cfg_exceptions.DirectoryEntryIsFile: 78 e = sys.exc_info()[1] 79 try_rollback(dep_trans, "Error: unable to deploy directory %s, as it is already a file on disk" % e[0]) 80 except Exception: 81 try: 82 try_rollback(dep_trans, "Deploy failed, rollback successful") 83 except: 84 print("Failed rollback") 85 raise
86
87 -def try_rollback(dep_trans, msg):
88 try: 89 dep_trans.rollback() 90 except (FailedRollback, 91 cfg_exceptions.UserNotFound, 92 cfg_exceptions.GroupNotFound): 93 pass 94 print(msg)
95