o
    .jd                     @   s   d Z ddlmZ ddlmZ ddlZddlmZ ddlZdZdej	j
fdd	Zd
d Zdd Zdd Zdd ZedkrPze  W dS  eyO   ed Y dS w dS )z7Translate an ics file's events to a different timezone.    )datetime)OptionParserN)tzz0.1Fc           
      C   s   t | dg D ]7}t |dd}t |dd}||fD ]$}|r<|j}	t|	tr<|r+|	j|kr<|	jdu r6|	j|d}	|	||_qqdS )a  
    Change the timezone of the specified component.

    Args:
        cal (Component): the component to change
        new_timezone (tzinfo): the timezone to change to
        default (tzinfo): a timezone to assume if the dtstart or dtend in cal doesn't have an existing timezone
        utc_only (bool): only convert dates that are in utc
        utc_tz (tzinfo): the tzinfo to compare to for UTC when processing utc_only=True
    vevent_listdtstartNdtend)tzinfo)getattrvalue
isinstancer   r   replace
astimezone)
calnew_timezonedefaultutc_onlyutc_tzveventstartendnodedt r   F/home/thesage/.local/lib/python3.10/site-packages/vobject/change_tz.py	change_tz   s   
r   c                  C   s   t jD ]} t|  qd S )N)pytzall_timezonesprint)	tz_stringr   r   r   show_timezones&   s   

r   c                 C   s   t d| rdnd |d }t|dkr|d nd}t d| tt|}t|t|td| d d	|}t d
| t|d}|	| W d    n1 sXw   Y  t d d S )NzConverting {} eventszonly UTCallr      UTCz... Reading {})r   r   r   z{}.convertedz... Writing {}wbDone)
r   formatlenvobjectreadOneopenr   r   gettz	serialize)r   argsics_file_tzoner   out_nameoutr   r   r   convert_events+   s   
r1   c                  C   s4   t  \} }| jrt  d S |rt| j|d d S d S )N)r   r,   )get_optionslistr   r1   utc)optionsr,   r   r   r   main<   s   

r6   c                  C   s   d} t | tjd}|d |jdddddd	d
 |jddddddd
 | \}}|s=|js=td t|  |dfS ||fS )Nz*usage: %prog [options] ics_file [timezone])usageversionz5change_tz will convert the timezones in an ics file. z-uz
--only-utcr4   
store_trueFzOnly change UTC events.)destactionr   helpz-lz--listr3   zList available timezoneszerror: too few arguments given)	r   r'   VERSIONset_description
add_option
parse_argsr3   r   format_help)r7   parsercmdline_optionsr,   r   r   r   r2   E   s   

r2   __main__Aborted)__doc__r   optparser   r   dateutilr   r'   r8   	icalendarr4   r   r   r1   r6   r2   __name__KeyboardInterruptr   r   r   r   r   <module>   s&    	