Index: trunk/wmfmailadmin/wmfmailadmin.py |
— | — | @@ -28,7 +28,7 @@ |
29 | 29 | 'i': ('id', "Id", None, None), |
30 | 30 | 'q': ('quota', "Quota", 2**30/1024, None), |
31 | 31 | 'a': ('active', "Active", True, None), |
32 | | - 'f': ('filter', "Filter", None, None) |
| 32 | + 'f': ('filter', "Filter", None, "Filter file or '-' for stdin") |
33 | 33 | } |
34 | 34 | longmappings = {} |
35 | 35 | |
— | — | @@ -37,6 +37,8 @@ |
38 | 38 | |
39 | 39 | supported_hash_algorithms = ('{SHA1}') |
40 | 40 | |
| 41 | +max_filter_size = 4096 |
| 42 | + |
41 | 43 | def list_accounts(fields): |
42 | 44 | """ |
43 | 45 | List accounts in the database |
— | — | @@ -171,11 +173,14 @@ |
172 | 174 | cur = conn.cursor() |
173 | 175 | cur.execute("SELECT " + field + " FROM account WHERE " + where_clause, fields) |
174 | 176 | |
175 | | - value = cur.fetchone()[0] |
176 | | - if value is not None: |
177 | | - print value |
178 | | - else: |
179 | | - print >> sys.stderr, "(NULL)" |
| 177 | + try: |
| 178 | + value = cur.fetchone()[0] |
| 179 | + if value is not None: |
| 180 | + print value |
| 181 | + else: |
| 182 | + print >> sys.stderr, "(NULL)" |
| 183 | + except: |
| 184 | + print >> sys.stderr, "(No rows returned)" |
180 | 185 | |
181 | 186 | def require_fields(required_fields, fields): |
182 | 187 | """ |
— | — | @@ -222,6 +227,8 @@ |
223 | 228 | Reads a filter from a file into fields['filter'] (overwriting) |
224 | 229 | """ |
225 | 230 | |
| 231 | + global max_filter_size |
| 232 | + |
226 | 233 | if fields['filter'] == "": return |
227 | 234 | |
228 | 235 | if fields['filter'] == '-': |
— | — | @@ -232,7 +239,10 @@ |
233 | 240 | except IOError, e: |
234 | 241 | raise Exception("Could not open filter file %s: %e" % (fields['filter'], e.message)) |
235 | 242 | |
236 | | - fields['filter'] = filterfile.read(4096) |
| 243 | + fields['filter'] = filterfile.read(max_filter_size) |
| 244 | + |
| 245 | + if len(fields['filter']) == max_filter_size and filterfile.read(1): |
| 246 | + print >> sys.stderr, "Warning: filter truncated at %d bytes!" % max_filter_size |
237 | 247 | |
238 | 248 | def add_index(dct, fieldindex): |
239 | 249 | """ |