def get_or_create_file(self, path): try: if self.playbook.id: file_ = (models.File.query .filter_by(path=path) .filter_by(playbook_id=self.playbook.id) .one()) return file_ except models.NoResultFound: pass file_ = models.File(path=path, playbook=self.playbook) db.session.add(file_) db.session.commit() try: with open(path, 'r') as fd: data = fd.read() sha1 = models.content_sha1(data) content = models.FileContent.query.get(sha1) if content is None: content = models.FileContent(content=data) file_.content = content except IOError: log.warning('failed to open %s for reading', path) return file_
def model(self): sha1 = hashlib.sha1(self.content).hexdigest() content = m.FileContent.query.get(sha1) if content is None: return m.FileContent(content=self.content) else: return content
def model(self): sha1 = m.content_sha1(self.content) content = m.FileContent.query.get(sha1) if content is None: return m.FileContent(content=self.content) else: return content