def to_file(self, f): """Save self.fields to file.""" if not type(self.fields) is dict: raise TypeError('self.fields must be a dict') with lock(f, 'w') as fp: fp.write(to_json(self.fields, indent=4)) return True
def save(self): """Save the issue to file.""" # We need to set updated, even if it's the same as created, # so we have a consistent timestamp to sort issues by. self.updated = time.time() if not hasattr(self, 'id'): # IDs are generated from the JSON dump of the # issue. This includes the UTC-format timestamp, so # they can be considered pretty unique. self.created = self.updated self.id = get_hash(to_json(self.fields)) # set the paths now that we have an id self._set_paths() # Make the parent directory if it doesn't exist. if not os.path.isdir(self.paths['root']): os.mkdir(self.paths['root']) # Make the comments dir if it doesn't exist. if not os.path.isdir(self.paths['comments']): os.mkdir(self.paths['comments']) # Save it in the db. self.tracker.db.insert(self) # Save it. return self.to_file(self.paths['issue'])
def save(self): """Save the comment to file.""" self.timestamp = time.time() self.id = get_hash(to_json(self.fields)) if not os.path.isdir(self.issue.paths['comments']): os.mkdir(self.issue.paths['comments']) # replace the issue in the db self.issue.tracker.db.insert(self.issue) return self.to_file(self.issue.get_comment_path(self.id))