Package conary :: Package build :: Module buildinfo
[hide private]
[frames] | no frames]

Source Code for Module conary.build.buildinfo

 1  # 
 2  # Copyright (c) 2004-2008 rPath, Inc. 
 3  # 
 4  # This program is distributed under the terms of the Common Public License, 
 5  # version 1.0. A copy of this license should have been distributed with this 
 6  # source file in a file called LICENSE. If it is not present, the license 
 7  # is always available at http://www.rpath.com/permanent/licenses/CPL-1.0. 
 8  # 
 9  # This program is distributed in the hope that it will be useful, but 
10  # without any warranty; without even the implied warranty of merchantability 
11  # or fitness for a particular purpose. See the Common Public License for 
12  # full details. 
13  # 
14   
15  """  
16  Contains information gathered during cooking, to be used mostly if the cook  
17  failed in order to resume using the same destdir 
18  """ 
19   
20  import time 
21   
22 -class BuildInfo(dict):
23
24 - def __init__(self, builddir):
25 self.__builddir = builddir 26 self.__infofile = builddir + "/conary-build-info" 27 self.__fd = None
28
29 - def __del__(self):
30 if self.__fd: 31 self.stop()
32
33 - def read(self):
34 # don't catch this error 35 self.__fd = open(self.__infofile, "r") 36 lines = self.__fd.readlines() 37 self.__fd.close() 38 for line in lines: 39 if line == '\n': 40 continue 41 (key, value) = line.split(None, 1) 42 #handle macros.foo 43 keys = key.split('.') 44 if len(keys) > 1: 45 subdicts = keys[:-1] 46 key = keys[-1] 47 curdict = self 48 for subdict in subdicts: 49 if subdict not in curdict: 50 curdict[subdict] = {} 51 curdict = curdict[subdict] 52 #unescape \\ and \n 53 value = value.replace('\\\\', '\0') 54 value = value.replace('\\n', '\n') 55 value = value.replace('\0', '\\') 56 curdict[key] = value[:-1] 57 else: 58 #unescape \\ and \n 59 value = value.replace('\\\\', '\0') 60 value = value.replace('\\n', '\n') 61 value = value.replace('\0', '\\') 62 self[key] = value[:-1]
63
64 - def begin(self):
65 self.__fd = open(self.__infofile, "w") 66 tm = time.time() 67 tmstr = time.asctime() 68 self.start = "%s (%s)" % (tm, tmstr)
69
70 - def write(self, str):
71 self.__fd.write(str) 72 self.__fd.flush()
73
74 - def stop(self):
75 tm = time.time() 76 tmstr = time.asctime() 77 self.end = "%s (%s)" % (tm, tmstr) 78 self.__fd.close() 79 self.__fd = None
80
81 - def __setattr__(self, name, value):
82 # Note that using buildinfo.foo = y 83 # causes foo to be written to file, while using buildinfo['foo'] = y 84 # does not 85 if not name.startswith('_BuildInfo_'): 86 #escape \\ and \n 87 value = str(value).replace('\\', '\\\\') 88 value = value.replace('\n', '\\n') 89 self.write('%s %s\n' % (name,value)) 90 self[name] = value
91
92 - def __getattr__(self, name):
93 return self[name]
94