def update(self, content=None, name=None, category=None, tags=None, **kw): f = self.filepath content = content or f.content name = name or self.name if category: f.remove() # old f = Filepath.from_category(category, name) self.category = category content = f.content if tags: content = content.new(tag_names=[t.name for t in tags]) self.tags = tags content.write() self.content = content self.name = name self.mtime = f.mtime
def execute(opts): content = "" f = Filepath.from_abspath(opts.filepath) if os.path.isfile(f.abspath): content = f.content content = click.edit(content) if content is not None: content = Content(content, filepath=f) session = Session() snippet_query = SnippetQuery(session) if not opts.dry_run: snp = snippet_query.new(content, tag_names=opts.tag_names) if snp: session.add(snp) content.write() session.commit() if opts.verbose: click.secho("create new snippets %s" % f, bold=True)
def filepath(self): return Filepath.from_category(self.category, self.name)