X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;ds=sidebyside;f=icalparse.py;h=3057560db8a16a2e6cc2d340d45c1b2a8963fc62;hb=e21f977abbd6f72899bafaf97670f443ea2e1217;hp=cc548a39515d0a6d72d5a5718cc75a5ba3e07e5c;hpb=4e836e4fb0a86d33033f8c53b9cb8f3ca6942ee7;p=frenchie%2Ficalparse.git diff --git a/icalparse.py b/icalparse.py index cc548a3..3057560 100755 --- a/icalparse.py +++ b/icalparse.py @@ -202,6 +202,29 @@ def applyRules(ical, rules=[], verbose=False): return ical +def writeOutput(cal, outfile=''): + '''Takes a list of lines and outputs to the specified file''' + + if not cal: + sys.stderr.write('Refusing to write out an empty file') + sys.exit(0) + + if not outfile: + out = sys.stdout + else: + try: + out = open(outfile, 'w') + except (IOError, OSError), e: + sys.stderr.write('%s\n'%e) + sys.exit(1) + + if cal[-1]: cal.append('') + + out.write('\r\n'.join(cal)) + + if not out == sys.stdout: + out.close() + if __name__ == '__main__': from optparse import OptionParser @@ -228,4 +251,4 @@ if __name__ == '__main__': cal = lineJoiner(content) ical = applyRules(splitFields(cal), generateRules()) output = lineFolder(joinFields(ical)) - print output + writeOutput(output, options.outfile)