Mercurial > piecrust2
comparison piecrust/commands/builtin/scaffolding.py @ 947:a85b2827ba1a
prepare: Fix old API calls.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Thu, 05 Oct 2017 00:25:10 -0700 |
parents | c445a3d5d950 |
children | 74c0c7483986 |
comparison
equal
deleted
inserted
replaced
946:8ca228956cc6 | 947:a85b2827ba1a |
---|---|
81 if tpl_text is None: | 81 if tpl_text is None: |
82 raise Exception("Error loading template: %s" % tpl_name) | 82 raise Exception("Error loading template: %s" % tpl_name) |
83 | 83 |
84 source = ctx.args.source | 84 source = ctx.args.source |
85 content_item = source.createContent(vars(ctx.args)) | 85 content_item = source.createContent(vars(ctx.args)) |
86 if content_item is None: | |
87 raise Exception("Can't create item.") | |
86 | 88 |
87 config_tokens = { | 89 config_tokens = { |
88 '%title%': "Untitled Content", | 90 '%title%': "Untitled Content", |
89 '%time.today%': time.strftime('%Y/%m/%d'), | 91 '%time.today%': time.strftime('%Y/%m/%d'), |
90 '%time.now%': time.strftime('%H:%M:%S') | 92 '%time.now%': time.strftime('%H:%M:%S') |
95 config_tokens['%%%s%%' % k] = v | 97 config_tokens['%%%s%%' % k] = v |
96 tpl_text = multi_replace(tpl_text, config_tokens) | 98 tpl_text = multi_replace(tpl_text, config_tokens) |
97 | 99 |
98 logger.info("Creating content: %s" % content_item.spec) | 100 logger.info("Creating content: %s" % content_item.spec) |
99 mode = 'w' if ctx.args.force else 'x' | 101 mode = 'w' if ctx.args.force else 'x' |
100 with content_item.open(mode) as f: | 102 with source.openItem(content_item, mode) as f: |
101 f.write(tpl_text) | 103 f.write(tpl_text) |
102 | 104 |
103 # If this was a file-system content item, see if we need to auto-open | 105 # If this was a file-system content item, see if we need to auto-open |
104 # an editor on it. | 106 # an editor on it. |
105 editor = ctx.app.config.get('prepare/editor') | 107 editor = ctx.app.config.get('prepare/editor') |