B
    18™\ó  ã               @   sX   d Z daddlZddlZddlZdadadaddd„Zdd„ Z	d	d
„ Z
edkrTe	ƒ  dS )aæ  (Ostensibly) fix copyright notices in files.

Actually, this script will simply replace a block of text in a file from one
string to another.  It will only do this once though, i.e. not globally
throughout the file.  It writes a backup file and then does an os.rename()
dance for atomicity.

Usage: fixnotices.py [options] [filenames]
Options:
    -h / --help
        Print this message and exit

    --oldnotice=file
        Use the notice in the file as the old (to be replaced) string, instead
        of the hard coded value in the script.

    --newnotice=file
        Use the notice in the file as the new (replacement) string, instead of
        the hard coded value in the script.

    --dry-run
        Don't actually make the changes, but print out the list of files that
        would change.  When used with -v, a status will be printed for every
        file.

    -v / --verbose
        Print a message for every file looked at, indicating whether the file
        is changed or not.
a¸  /***********************************************************
Copyright (c) 2000, BeOpen.com.
Copyright (c) 1995-2000, Corporation for National Research Initiatives.
Copyright (c) 1990-1995, Stichting Mathematisch Centrum.
All rights reserved.

See the file "Misc/COPYRIGHT" for information on usage and
redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
******************************************************************/
é    NÚ c             C   s(   t ttƒ  ƒ |rt |ƒ t | ¡ d S )N)ÚprintÚ__doc__ÚglobalsÚsysÚexit)ÚcodeÚmsg© r
   úW/oak/stanford/groups/akundaje/marinovg/programs/Python-3.7.3/Tools/scripts/fixnotice.pyÚusage4   s    r   c           
   C   sö   y*t   tjdd … ddddddg¡\} }W n. t jk
rX } ztd|ƒ W d d }~X Y nX x€| D ]x\}}|dkrztd	ƒ q`|d
krˆdaq`|dkr–daq`|dkr¸t|ƒ}| ¡ a	| 
¡  q`|dkr`t|ƒ}| ¡ a| 
¡  q`W x|D ]}t|ƒ qâW d S )Né   ZhvÚhelpz
oldnotice=z
newnotice=zdry-runÚverbose)z-hz--helpr   )z-vz	--verbosez	--dry-runz--oldnoticez--newnotice)Úgetoptr   ÚargvÚerrorr   ÚVERBOSEÚDRYRUNÚopenÚreadÚ
OLD_NOTICEÚcloseÚ
NEW_NOTICEÚprocess)ÚoptsÚargsr	   ÚoptÚargÚfpr
   r
   r   Úmain;   s.    


r    c             C   sÂ   t | ƒ}| ¡ }| ¡  | t¡}|dk r<tr8td| ƒ d S tsDtrNtd| ƒ trVd S |d |… t ||t	tƒ d …  }| d }| d }t |dƒ}| 
|¡ | ¡  t | |¡ t || ¡ d S )Nr   z
no change:z
   change:z.newz.bakÚw)r   r   r   Úfindr   r   r   r   r   ÚlenÚwriteÚosÚrename)ÚfileÚfÚdataÚiÚnewÚbackupr
   r
   r   r   X   s(    


$

r   Ú__main__)r   )r   r   r%   r   r   r   r   r   r   r    r   Ú__name__r
   r
   r
   r   Ú<module>   s   
