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

Source Code for Module config_client.cli_repository

 1  #!/usr/bin/python 
 2  # 
 3  # Copyright (c) 2008--2016 Red Hat, Inc. 
 4  # 
 5  # This software is licensed to you under the GNU General Public License, 
 6  # version 2 (GPLv2). There is NO WARRANTY for this software, express or 
 7  # implied, including the implied warranties of MERCHANTABILITY or FITNESS 
 8  # FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 
 9  # along with this software; if not, see 
10  # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. 
11  # 
12  # Red Hat trademarks are not licensed under GPLv2. No permission is 
13  # granted to use or replicate Red Hat trademarks that are incorporated 
14  # in this software or its documentation. 
15  # 
16   
17  import os 
18   
19  from config_common import cfg_exceptions, repository 
20   
21  # this is a bit odd; right now, we instantiate a regular 
22  # repository.Repository object since it does a lot of local disk 
23  # access for us.  In the future, though, it is unlikely Repository and 
24  # ClientRepository classes/APIs will actually share this in common 
25  # since Repository mostly requires user perms and ClientRepository 
26  # mostly requires server perms 
27   
28 -class ClientRepository:
29 - def __init__(self):
30 self.server_repository = repository.Repository() 31 tmp_channels = os.environ.get("RHNCFG_CHANNELS") or "all" 32 33 # listed in order of losers first, ie, entry 2 overrides entry 34 # 1, etc 35 self.config_channels = tmp_channels.split(":") 36 self.cfg_files = {}
37
38 - def list_files(self):
39 # iterate over channels, accumulating hash of what files 40 # come from where; subsequent entries override previous ones, 41 # so the final hash is the result we seek 42 43 if self.cfg_files: 44 return self.cfg_files 45 46 self.cfg_files = {} 47 for ns in self.config_channels: 48 for file in self.server_repository.list_files(ns): 49 self.cfg_files[file] = [ ns, file ] 50 51 return self.cfg_files
52
53 - def get_file(self, file):
54 if not self.cfg_files: 55 raise "never did a list_files" 56 57 if file not in self.cfg_files: 58 raise cfg_exceptions.ConfigNotManaged(file) 59 60 return self.server_repository.get_file(self.cfg_files[file][0], self.cfg_files[file][1])
61
62 - def list_config_channels(self):
63 return self.config_channels
64