def __init__(self, dir_jobs, desc=None): if desc: self.uuid = self.__generate_uuid() self.dir = os.path.join(dir_jobs, self.uuid + '.locked') self.description = desc if not os.path.exists(self.dir): os.makedirs(self.dir) spew(os.path.join(self.dir, 'timestamp'), time.time()) else: self.dir = dir_jobs self.uuid = os.path.basename(self.dir).split('.')[0] f = open(self.__job_file(), 'rb') try: self.description = pickle.load(f) finally: f.close()
def __get_local_checksum(self, file): md5_path = file + '.md5' if os.path.exists(md5_path): return slurp(md5_path) if not os.path.isfile(file): return None md5 = hashlib.md5() file = open(file, 'rb') try: while True: data = file.read(0xFFFF) if not data: break md5.update(data) finally: file.close() md5 = md5.hexdigest() spew(md5_path, md5) return md5
def add_information_file(self, name, author = 'unknown'): ''' Adds an information file to the map ''' if not self.__bounds: raise RuntimeError('Boundaries undefined.') dst = os.path.join(self.__dir_temp, 'info.txt') spew(dst, '''map name: {name} generator: XCSoar Map Generator creation time: {time:%d.%m.%Y %T} ({time:%s}) latitude range: {minlat} to {maxlat} longitude range: {minlon} to {maxlon} author: {author} '''.format(name=name, time=datetime.now(), minlat=self.__bounds.bottom, maxlat=self.__bounds.top, minlon=self.__bounds.left, maxlon=self.__bounds.right, author=author)) self.__files.add(dst, True)
def update_status(self, status): spew(self.__status_file(), status)