comparison piecrust/sources/posts.py @ 54:a46354306738

Use properly formatted date components for the blog sources.
author Ludovic Chabant <ludovic@chabant.com>
date Mon, 25 Aug 2014 08:46:11 -0700
parents 485682a6de50
children 838a9dd0e23c
comparison
equal deleted inserted replaced
53:73956224eb67 54:a46354306738
34 year = metadata.get('year') 34 year = metadata.get('year')
35 month = metadata.get('month') 35 month = metadata.get('month')
36 day = metadata.get('day') 36 day = metadata.get('day')
37 slug = metadata.get('slug') 37 slug = metadata.get('slug')
38 38
39 if year is not None:
40 year = int(year)
41 if month is not None:
42 month = int(month)
43 if day is not None:
44 day = int(day)
45
39 ext = metadata.get('ext') 46 ext = metadata.get('ext')
40 if ext is None: 47 if ext is None:
41 if len(self.supported_extensions) == 1: 48 if len(self.supported_extensions) == 1:
42 ext = self.supported_extensions[0] 49 ext = self.supported_extensions[0]
43 elif mode == MODE_CREATING and self.default_auto_format: 50 elif mode == MODE_CREATING and self.default_auto_format:
44 ext = self.default_auto_format 51 ext = self.default_auto_format
45 52
46 replacements = { 53 replacements = {
47 'year': year, 54 'year': '%04d' % year,
48 'month': month, 55 'month': '%02d' % month,
49 'day': day, 56 'day': '%02d' % day,
50 'slug': slug, 57 'slug': slug,
51 'ext': ext 58 'ext': ext
52 } 59 }
53 needs_recapture = False 60 needs_recapture = False
54 if year is None: 61 if year is None:
84 'month': '(?P<month>\d{2})', 91 'month': '(?P<month>\d{2})',
85 'day': '(?P<day>\d{2})', 92 'day': '(?P<day>\d{2})',
86 'slug': '(?P<slug>.*)', 93 'slug': '(?P<slug>.*)',
87 'ext': '(?P<ext>.*)' 94 'ext': '(?P<ext>.*)'
88 } 95 }
89 #sanitized_fs_endpoint_path = (self.fs_endpoint_path.
90 # replace('\\', '/').rstrip('/'))
91 #pattern = (re.escape(sanitized_fs_endpoint_path) + '/' +
92 # self.path_format % regex_repl)
93 pattern = self.path_format % regex_repl + '$' 96 pattern = self.path_format % regex_repl + '$'
94 m = re.search(pattern, path.replace('\\', '/')) 97 m = re.search(pattern, path.replace('\\', '/'))
95 if not m: 98 if not m:
96 raise Exception("Expected to be able to match path with path " 99 raise Exception("Expected to be able to match path with path "
97 "format: %s" % path) 100 "format: %s" % path)