- commit
- d5ea86b3543793a5548f21b315779c3e98ac27d8
- parent
- 5f9ad73666a9739096ce58d82cea77accd626bf8
- Author
- Tobias Bengfort <tobias.bengfort@gmx.net>
- Date
- 2015-04-11 07:20
Gardening
Diffstat
| M | cctool.py | 40 | +++++++++++++++++++++------------------- |
1 files changed, 21 insertions, 19 deletions
diff --git a/cctool.py b/cctool.py
@@ -31,6 +31,8 @@ 31 31 # - parse vcard name (N) 32 32 # - use mintained vcard/ical libs 33 33 -1 34 from __future__ import print_function -1 35 34 36 import os 35 37 import sys 36 38 import argparse @@ -47,13 +49,13 @@ except ImportError: 47 49 48 50 try: 49 51 import ldif50 -1 except ImportError as e:51 -1 ldif = e-1 52 except ImportError as err: -1 53 ldif = err 52 54 53 55 try: 54 56 import vobject55 -1 except ImportError as e:56 -1 vobject = e-1 57 except ImportError as err: -1 58 vobject = err 57 59 58 60 59 61 NOTSET = object() @@ -224,12 +226,12 @@ class ABook(Format): 224 226 225 227 @classmethod 226 228 def load(cls, fh):227 -1 cp = ConfigParser()228 -1 cp.readfp(fh)229 -1 for section in cp.sections():-1 229 config_parser = ConfigParser() -1 230 config_parser.readfp(fh) -1 231 for section in config_parser.sections(): 230 232 if section != u'format': 231 233 d = MultiDict()232 -1 for key, value in cp.items(section):-1 234 for key, value in config_parser.items(section): 233 235 if key == 'bday': 234 236 if value[0] == '-': 235 237 value = '1900' + value[1:] @@ -284,9 +286,9 @@ class LDIF(Format): 284 286 parser = LDIFParser(fh) 285 287 try: 286 288 parser.parse()287 -1 except ValueError as e:288 -1 log.warning("ValueError after reading %i records: %s"289 -1 % (parser.records_read, e))-1 289 except ValueError as err: -1 290 log.warning("ValueError after reading %i records: %s", -1 291 parser.records_read, err) 290 292 for entry in parser.entries.itervalues(): 291 293 yield MultiDict(entry) 292 294 @@ -409,19 +411,19 @@ def main(): 409 411 outformat = get_outformat(args) 410 412 411 413 data = []412 -1 for fn in args.input:-1 414 for filename in args.input: 413 415 if args.informat is not None: 414 416 informat = args.informat 415 417 else:416 -1 informat = get_informat(fn)-1 418 informat = get_informat(filename) 417 419418 -1 infile = sys.stdin if fn == '-' else open(fn)-1 420 infile = sys.stdin if filename == '-' else open(filename) 419 421 try: 420 422 data += informats[informat]().load(infile)421 -1 except Exception as e:422 -1 log.error(e)-1 423 except Exception as err: -1 424 log.error(err) 423 425 sys.exit(1)424 -1 if fn != '-':-1 426 if filename != '-': 425 427 infile.close() 426 428 427 429 if args.merge is not None: @@ -433,8 +435,8 @@ def main(): 433 435 outfile = sys.stdout if args.output is None else open(args.output, 'w') 434 436 try: 435 437 outformats[outformat]().dump(data, outfile)436 -1 except Exception as e:437 -1 log.error(e)-1 438 except Exception as err: -1 439 log.error(err) 438 440 sys.exit(1) 439 441 440 442