Mercurial > hg > decoupage
comparison decoupage/formatters.py @ 45:650e1b62a628
add order formatter (untested)
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Wed, 08 Sep 2010 23:12:57 -0700 |
parents | 677e2fe1239c |
children | 8002dcdb8e82 |
comparison
equal
deleted
inserted
replaced
44:445af840aa5c | 45:650e1b62a628 |
---|---|
94 | 94 |
95 if 'reverse' in self.args: | 95 if 'reverse' in self.args: |
96 data['files'] = list(reversed(data['files'])) | 96 data['files'] = list(reversed(data['files'])) |
97 | 97 |
98 | 98 |
99 class Order(object): | |
100 """ | |
101 put the files in a particular order | |
102 """ | |
103 def __init__(self, pattern): | |
104 if '=' in pattern: | |
105 key, value = pattern.split('=', 1) | |
106 assert key == 'file' | |
107 self.file = value | |
108 else: | |
109 self.order = [i.strip() for i in pattern.split(',')] | |
110 | |
111 def __call__(self, request, data): | |
112 | |
113 if self.file: | |
114 raise NotImplementedError | |
115 | |
116 files = [] | |
117 file_hash = dict([(i['name'], i) for i in data['files']]) | |
118 for f in self.order: | |
119 files.append(file_hash.get(f, None)) | |
120 files = [ i for i in files if i is not None ] | |
121 | |
122 | |
99 class FilenameDescription(FormatterBase): | 123 class FilenameDescription(FormatterBase): |
100 """ | 124 """ |
101 obtain the description from the filename | 125 obtain the description from the filename |
102 the file extension (if any) will be dropped and | 126 the file extension (if any) will be dropped and |
103 spaces will be substituted for underscores | 127 spaces will be substituted for underscores |