Mercurial > piecrust2
comparison piecrust/processing/base.py @ 203:29165f2f315d
processing: More powerful syntax to specify pipeline processors.
The syntax now supports `* -foo -bar` to load all processors except `foo` and
`bar`.
| author | Ludovic Chabant <ludovic@chabant.com> |
|---|---|
| date | Thu, 15 Jan 2015 22:54:59 -0800 |
| parents | 0c9de41689bb |
| children | e725af1d48fb |
comparison
equal
deleted
inserted
replaced
| 202:cd049786c008 | 203:29165f2f315d |
|---|---|
| 20 | 20 |
| 21 | 21 |
| 22 PRIORITY_FIRST = -1 | 22 PRIORITY_FIRST = -1 |
| 23 PRIORITY_NORMAL = 0 | 23 PRIORITY_NORMAL = 0 |
| 24 PRIORITY_LAST = 1 | 24 PRIORITY_LAST = 1 |
| 25 | |
| 26 | |
| 27 split_processor_names_re = re.compile(r'[ ,]+') | |
| 25 | 28 |
| 26 | 29 |
| 27 class Processor(object): | 30 class Processor(object): |
| 28 PROCESSOR_NAME = None | 31 PROCESSOR_NAME = None |
| 29 | 32 |
| 143 def filterProcessors(self, authorized_names): | 146 def filterProcessors(self, authorized_names): |
| 144 if not authorized_names or authorized_names == '*': | 147 if not authorized_names or authorized_names == '*': |
| 145 return self.processors | 148 return self.processors |
| 146 | 149 |
| 147 if isinstance(authorized_names, str): | 150 if isinstance(authorized_names, str): |
| 148 authorized_names = authorized_names.split(',') | 151 authorized_names = split_processor_names_re.split(authorized_names) |
| 152 | |
| 153 procs = [] | |
| 154 has_star = '*' in authorized_names | |
| 155 for p in self.processors: | |
| 156 for name in authorized_names: | |
| 157 if name == p.PROCESSOR_NAME: | |
| 158 procs.append(p) | |
| 159 break | |
| 160 if name == ('-%s' % p.PROCESSOR_NAME): | |
| 161 break | |
| 162 else: | |
| 163 if has_star: | |
| 164 procs.append(p) | |
| 165 return procs | |
| 166 | |
| 149 return list(filter( | 167 return list(filter( |
| 150 lambda p: p.PROCESSOR_NAME in authorized_names, | 168 lambda p: p.PROCESSOR_NAME in authorized_names, |
| 151 self.processors)) | 169 self.processors)) |
| 152 | 170 |
| 153 def run(self, src_dir_or_file=None, *, | 171 def run(self, src_dir_or_file=None, *, |
