Package pulp :: Package client
[hide private]
[frames] | no frames]

Source Code for Package pulp.client

 1  # 
 2  # Copyright (c) 2010 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  """ 
17  Pulp Client 
18  """ 
19   
20  import os 
21   
22 -class ConsumerId:
23 """ 24 Client identity 25 @ivar uuid: The client id. 26 @type uuid: str 27 """ 28 29 PATH = '/etc/pulp/consumer' 30
31 - def __init__(self, uuid=None):
32 """ 33 @ivar value: The client id. 34 @type value: str 35 """ 36 self.uuid = None 37 if uuid: 38 self.uuid = uuid 39 else: 40 self.read()
41
42 - def read(self):
43 """ 44 Read identity from file. 45 """ 46 if not self.exists(): 47 return 48 f = open(self.PATH) 49 try: 50 self.uuid = f.read().strip() 51 return self 52 finally: 53 f.close()
54
55 - def write(self, id):
56 """ 57 Write identity to file. 58 """ 59 f = open(self.PATH, 'w') 60 try: 61 f.write(self.uuid) 62 return self 63 finally: 64 f.close()
65
66 - def exists(self):
67 return os.path.exists(self.PATH)
68
69 - def __str__(self):
70 return self.uuid
71