Mercurial > piecrust2
comparison piecrust/commands/builtin/util.py @ 11:617191dec18e
Fixes for Windows, make `findPagePath` return a ref path.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Mon, 18 Aug 2014 16:47:44 -0700 |
parents | 474c9882decf |
children | afcfecd3bf92 |
comparison
equal
deleted
inserted
replaced
10:cd35d356ccce | 11:617191dec18e |
---|---|
84 | 84 |
85 def run(self, ctx): | 85 def run(self, ctx): |
86 app = ctx.app | 86 app = ctx.app |
87 source = ctx.args.source | 87 source = ctx.args.source |
88 metadata = source.buildMetadata(ctx.args) | 88 metadata = source.buildMetadata(ctx.args) |
89 page_path = source.findPagePath(metadata, MODE_CREATING) | 89 rel_path, metadata = source.findPagePath(metadata, MODE_CREATING) |
90 name, ext = os.path.splitext(page_path) | 90 path = source.resolveRef(rel_path) |
91 name, ext = os.path.splitext(path) | |
91 if ext == '.*': | 92 if ext == '.*': |
92 page_path = '%s.%s' % (name, | 93 path = '%s.%s' % (name, |
93 app.config.get('site/default_auto_format')) | 94 app.config.get('site/default_auto_format')) |
94 if os.path.exists(page_path): | 95 if os.path.exists(path): |
95 raise Exception("'%s' already exists." % page_path) | 96 raise Exception("'%s' already exists." % path) |
96 | 97 |
97 logger.info("Creating page: %s" % os.path.relpath(page_path, app.root_dir)) | 98 logger.info("Creating page: %s" % os.path.relpath(path, app.root_dir)) |
98 if not os.path.exists(os.path.dirname(page_path)): | 99 if not os.path.exists(os.path.dirname(path)): |
99 os.makedirs(os.path.dirname(page_path), 0o755) | 100 os.makedirs(os.path.dirname(path), 0o755) |
100 with open(page_path, 'w') as f: | 101 with open(path, 'w') as f: |
101 f.write('---\n') | 102 f.write('---\n') |
102 f.write('title: %s\n' % 'Unknown title') | 103 f.write('title: %s\n' % 'Unknown title') |
103 f.write('---\n') | 104 f.write('---\n') |
104 f.write("This is a new page!\n") | 105 f.write("This is a new page!\n") |
105 | 106 |