git.ucc.asn.au
/
frenchie
/
icalparse.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
4e836e4
)
Write output, ready for primetime
0.7
version-0.7
author
James French
<
[email protected]
>
Mon, 2 Aug 2010 07:03:48 +0000
(15:03 +0800)
committer
James French
<
[email protected]
>
Mon, 2 Aug 2010 07:03:48 +0000
(15:03 +0800)
icalparse.py
patch
|
blob
|
history
diff --git
a/icalparse.py
b/icalparse.py
index
cc548a3
..
3057560
100755
(executable)
--- a/
icalparse.py
+++ b/
icalparse.py
@@
-202,6
+202,29
@@
def applyRules(ical, rules=[], verbose=False):
return ical
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
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))
cal = lineJoiner(content)
ical = applyRules(splitFields(cal), generateRules())
output = lineFolder(joinFields(ical))
- print output
+ writeOutput(output, options.outfile)
UCC
git Repository :: git.ucc.asn.au