@@ -75,25 +75,20 @@ def event_from_yaml(event_yaml: dict, tz: datetime.tzinfo = None) -> ics.Event:
7575 interval = repeat ["interval" ]
7676
7777 if not len (interval ) == 1 :
78- print (
78+ raise RuntimeError (
7979 "Error: interval must specify seconds, minutes, hours, days, "
80- "weeks, months, or years only" ,
81- file = sys .stderr ,
80+ "weeks, months, or years only"
8281 )
83- sys .exit (- 1 )
8482
8583 interval_measure = list (interval .keys ())[0 ]
8684 if interval_measure not in interval_type :
87- print (
85+ raise RuntimeError (
8886 "Error: expected interval to be specified in seconds, minutes, "
8987 "hours, days, weeks, months, or years only" ,
90- file = sys .stderr ,
9188 )
92- sys .exit (- 1 )
9389
9490 if "until" not in repeat :
95- print ("Error: must specify end date for repeating events" , file = sys .stderr )
96- sys .exit (- 1 )
91+ raise RuntimeError ("Error: must specify end date for " "repeating events" )
9792
9893 # This causes zero-length events, I guess overriding whatever duration
9994 # might have been specified
@@ -131,6 +126,8 @@ def event_from_yaml(event_yaml: dict, tz: datetime.tzinfo = None) -> ics.Event:
131126
132127 if ics_custom :
133128 for line in ics_custom .split ("\n " ):
129+ if not line :
130+ continue
134131 if ":" not in line :
135132 raise RuntimeError (
136133 f"Invalid custom ICS (expected `fieldname:value`):\n { line } "
@@ -191,19 +188,21 @@ def files_to_calendar(files: list) -> ics.Calendar:
191188
192189def main ():
193190 if len (sys .argv ) < 2 :
194- print ("Usage: yaml2ics.py FILE1.yaml FILE2.yaml ..." )
195- sys .exit (- 1 )
191+ raise RuntimeError ("Usage: yaml2ics.py FILE1.yaml FILE2.yaml ..." )
196192
197193 files = sys .argv [1 :]
198194 for f in files :
199195 if not os .path .isfile (f ):
200- print (f"Error: { f } is not a file" , file = sys .stderr )
201- sys .exit (- 1 )
196+ raise RuntimeError (f"Error: { f } is not a file" )
202197
203198 calendar = files_to_calendar (files )
204199
205200 print (calendar .serialize ())
206201
207202
208- if __name__ == "__main__" :
209- main ()
203+ if __name__ == "__main__" : # pragma: no cover
204+ try :
205+ main ()
206+ except Exception as e :
207+ print (e , file = sys .stderr )
208+ sys .exit (- 1 )
0 commit comments