Package config_client :: Module handler_base
[hide private]
[frames] | no frames]

Source Code for Module config_client.handler_base

 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 os.path 
18   
19  from config_common import handler_base, utils 
20  from config_common.rhn_log import log_debug 
21   
22 -class HandlerBase(handler_base.HandlerBase):
23 - def get_dest_file(self, file):
24 target_dir = os.sep 25 return utils.normalize_path(target_dir + os.sep + file)
26 27 # Returns a list of valid files
28 - def get_valid_files(self):
29 files_hash = {} 30 for file in self.repository.list_files(): 31 files_hash[file[1]] = None 32 33 if not self.args: 34 # No file specified; use all of them 35 files = list(files_hash.keys()) 36 files.sort() 37 return files 38 39 files = [] 40 for file in self.args: 41 #5/9/05 wregglej - 151197 make sure that trailing /'s aren't passed through for directories. 42 if os.path.isdir(file): 43 if file[-1] == "/": 44 file = file[0:-1] 45 46 if file not in files_hash: 47 print("Not found on server: %s" % file) 48 continue 49 files.append(file) 50 files.sort() 51 return files
52 53 # Main function to be run
54 - def run(self):
55 log_debug(2) 56 for file in self.get_valid_files(): 57 (src, file_info, dirs_created) = self.repository.get_file_info(file) 58 59 ftype = file_info.get('filetype') 60 61 if not src: 62 continue 63 64 dst = self.get_dest_file(file) 65 66 self._process_file(src, dst, file, ftype, file_info)
67 68 # To be overridden with specific actions in subclasses
69 - def _process_file(self, *args):
70 pass
71
72 -class TopdirHandlerBase(HandlerBase):
73 _options_table = [ 74 HandlerBase._option_class( 75 '--topdir', action="store", 76 help="Make all file operations relative to this directory.", 77 ), 78 HandlerBase._option_class( 79 '--exclude', action="append", 80 help="Excludes a file from being deployed with 'get'. May be used multiple times.", 81 ), 82 ] 83
84 - def get_dest_file(self, file):
85 target_dir = self.options.topdir or os.sep 86 return utils.normalize_path(target_dir + os.sep + file)
87