Your IP : 216.73.216.213


Current Path : /opt/alt/python37/lib/python3.7/site-packages/logilab/common/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/logilab/common/__pycache__/changelog.cpython-37.pyc

B

�d{T��@s�dZdZddlZddlmZddlmZdZdZdZ	Gd	d
�d
e
�ZGdd�de
�ZGd
d�de
�ZGdd�de�ZGdd�de�ZdS)a�Manipulation of upstream change log files.

The upstream change log files format handled is simpler than the one
often used such as those generated by the default Emacs changelog mode.

Sample ChangeLog format::

  Change log for project Yoo
  ==========================

   --
      * add a new functionality

  2002-02-01 -- 0.1.1
      * fix bug #435454
      * fix bug #434356

  2002-01-01 -- 0.1
      * initial release


There is 3 entries in this change log, one for each released version and one
for the next version (i.e. the current entry).
Each entry contains a set of messages corresponding to changes done in this
release.
All the non empty lines before the first entry are considered as the change
log title.
zrestructuredtext en�N)�S_IWRITE)�string_types�*�-z    c@seZdZdZdS)�NoEntryz*raised when we are unable to find an entryN)�__name__�
__module__�__qualname__�__doc__�rr�I/opt/alt/python37/lib/python3.7/site-packages/logilab/common/changelog.pyr:src@seZdZdZdS)�
EntryNotFoundz/raised when we are unable to find a given entryN)rrr	r
rrrrr
=sr
c@s,eZdZdZdd�Zedd��Zdd�ZdS)	�Versionzdsimple class to handle soft version number has a tuple while
    correctly printing it as X.Y.Z
    cCs0t|t�r |�d�}|�|�}n|}t�||�S)Nz :)�
isinstancer�strip�parse�tuple�__new__)�cls�
versionstr�parsedrrrrDs


zVersion.__new__c
CsV|�d�}ydd�|�d�D�Stk
rP}ztd||f��Wdd}~XYnXdS)Nz :cSsg|]}t|��qSr)�int)�.0�irrr�
<listcomp>Psz!Version.parse.<locals>.<listcomp>�.z%invalid literal for version '%s' (%s))r�split�
ValueError)rr�exrrrrLs

z
Version.parsecCsd�dd�|D��S)NrcSsg|]}t|��qSr)�str)rrrrrrUsz#Version.__str__.<locals>.<listcomp>)�join)�selfrrr�__str__TszVersion.__str__N)rrr	r
r�classmethodrr"rrrrr@src@sFeZdZdZeZd
dd�Zdd�Zdd�Zdd	d
�Z	e
jfdd�ZdS)�ChangeLogEntryz`a change log entry, i.e. a set of messages associated to a version and
    its release date
    NcKs4|j�|�|r|�|�|_nd|_||_g|_dS)N)�__dict__�update�
version_class�version�date�messages)r!r)r(�kwargsrrr�__init___szChangeLogEntry.__init__cCs|j�|ggf�dS)zadd a new messageN)r*�append)r!�msgrrr�add_messagehszChangeLogEntry.add_messagecCsN|jstd��|jddr6|jddd�|�n|jdd�|�dS)z*complete the latest added message
        z@unable to complete last message as there is no previous message)����rN)r*rr-)r!Z	msg_suiterrr�complete_latest_messagels
z&ChangeLogEntry.complete_latest_messagecCs:|jstd��|dkr.|jdd�|g�ntd��dS)Nz@unable to complete last message as there is no previous message)r0r1z3sub message to specific key are not implemented yet)r*rr-�NotImplementedError)r!�sub_msg�keyrrr�add_sub_messagevs
zChangeLogEntry.add_sub_messagec	Cs�|�d|jpd|jpdf�x�|jD]�\}}|�dtt|df�|�d�|dd���|rl|�d�x@|D]8}|�dtdt|df�|�d�|dd���qrW|�d�q&W|�d	�dS)
zwrite the entry to file z%s  --  %s
�z%s%s %s
rr1N�
�z

)�writer)r(r*�INDENT�BULLETr �	SUBBULLET)r!�streamr.Zsub_msgsr4rrrr:~s

zChangeLogEntry.write)NN)N)
rrr	r
rr'r,r/r2r6�sys�stdoutr:rrrrr$Ys
	

r$c@sheZdZdZeZddd�Zdd�Zdd�Zdd
d�Z	ddd
�Z
dd�Zdd�Zdd�Z
ejfdd�Zd	S)�	ChangeLogz/object representation of a whole ChangeLog filer7cCs$||_||_d|_g|_|��dS)Nr7)�file�title�additional_content�entries�load)r!Zchangelog_filerCrrrr,�s
zChangeLog.__init__cCsd|jt|�t|j�fS)Nz!<ChangeLog %s at %s (%s entries)>)rB�id�lenrE)r!rrr�__repr__�szChangeLog.__repr__cCs|j�|�dS)z!add a new entry to the change logN)rEr-)r!�entryrrr�	add_entry�szChangeLog.add_entryNcCs�|js$|s|st��|j�|���|sX|jdjrN|dk	rN|j�d|���|jdS|�|�}x|jD]}|j|krj|SqjWt��dS)z` return a given changelog entry
        if version is omitted, return the current entry
        rN)rErr-�entry_classr(�insertr'r
)r!r(�createrJrrr�	get_entry�s


zChangeLog.get_entrycCs|j|d�}|�|�dS)z,add a new message to the latest opened entry)rNN)rOr/)r!r.rNrJrrr�add�sz
ChangeLog.addcCsvyt|j�}Wntk
r"dSXd}d}�x:|��D�],}|��}|��}t|�dkr~|ddkr~d}|��}|�|�q8t|�dkr�|ddkr�d}|�|d|d�}|�|�q8|r�|dkr�d|j	|f|_	q8|�r|dt
k�rd}|�|dd����q8|�r:|�r:|dtk�r:|�
|dd����q8|�rT|j�rT|�|�q8d	}|j|7_q8W|��dS)
z& read a logilab's ChangeLog from file NFr1rz--�r9z%s%sT)�openrB�IOError�	readlinesrrrHrLrKrCr<r/r=r6r*r2rD�close)r!r>�lastZ
expect_sub�line�sline�wordsrrrrF�s:zChangeLog.loadcCsd|j��S)Nz%s

)rCr)r!rrr�format_title�szChangeLog.format_titlecCs.ddlm}||jt�|�t|jd��dS)zwrite back change logr)�ensure_fs_mode�wN)Zlogilab.common.fileutilsr[rBrr:rR)r!r[rrr�save�szChangeLog.savecCs,|�|���x|jD]}|�|�qWdS)zwrite changelog to streamN)r:rZrE)r!r>rJrrrr:�szChangeLog.write)r7)r7N)N)rrr	r
r$rLr,rIrKrOrPrFrZr]r?r@r:rrrrrA�s


'rA)r
�
__docformat__r?�statrZsixrr<r=r;�	Exceptionrr
rr�objectr$rArrrr�<module>-s4