
    9 f                         d Z ddlZddlmZ ddlmZ ddlmZ ddlm	Z	m
Z
mZ dd	lmZ d
ZdZ G d de          Z G d de          Z G d de          ZdS )zb
An application for managing IPython history.

To be invoked as the `ipython history` subcommand.
    N)Path)Application   )BaseIPythonApplication)BoolIntDict   )
ask_yes_nozTrim the IPython history database to the last 1000 entries.

This actually copies the last 1000 entries to a new database, and then replaces
the old file with the new. Use the `--keep=` argument to specify a number
other than 1000.
a  Clear the IPython history database, deleting all entries.

Because this is a destructive operation, IPython will prompt the user if they
really want to do this. Passing a `-f` flag will force clearing without a
prompt.

This is an handy alias to `ipython history trim --keep=0`
c                      e Zd ZeZ edd                              d          Z edd                              d          Z	 e
 ed ddiiej        f	                    Z e
 ed
                    Zd ZdS )HistoryTrimFz/Keep the old history file as history.sqlite.<N>helpTconfigi  /Number of recent lines to keep in the database.backup)r   zHistoryTrim.keep)keepc                    t          | j        j                  }|dz  }t          j        |          }t          |                    d| j        dz   f                    }t          |          | j        k    r(t          d| j        z             t          d           d S t          d| j        z             |
                                 |                                 |rV|d         d         }t          |                    d|f                    }t          |                    d	|f                    }|                                 |d
z  }d}	|                                r.|	dz  }	|d
t          |	          z   z  }|                                .t          j        |          }
|
                    d           |
                    d           |
                    d           |
                                 |r\|
5  |
                    d|           |
                    d|           |
                    d|           d d d            n# 1 swxY w Y   |
                                 | j        red}	|d|	z  z  }|                                r!|	dz  }	|d|	z  z  }|                                !|                    |           t          d|           n|                                 |                    |           d S )Nzhistory.sqlitez^SELECT session, line, source, source_raw FROM history ORDER BY session DESC, line DESC LIMIT ?r   z=There are already at most %d entries in the history database.z>Not doing anything. Use --keep= argument to keep fewer entriesz/Trimming history to the most recent %d entries.r   zCSELECT session, line, output FROM output_history WHERE session >= ?zMSELECT session, start, end, num_cmds, remark FROM sessions WHERE session >= ?zhistory.sqlite.newzCREATE TABLE IF NOT EXISTS sessions (session integer
                            primary key autoincrement, start timestamp,
                            end timestamp, num_cmds integer, remark text)zCREATE TABLE IF NOT EXISTS history
                        (session integer, line integer, source text, source_raw text,
                        PRIMARY KEY (session, line))zCREATE TABLE IF NOT EXISTS output_history
                        (session integer, line integer, output text,
                        PRIMARY KEY (session, line))z'insert into sessions values (?,?,?,?,?)z$insert into history values (?,?,?,?)z)insert into output_history values (?,?,?)zhistory.sqlite.old.%dz Backed up longer history file to)r   profile_dirlocationsqlite3connectlistexecuter   lenprintpopreversecloseexistsstrcommitexecutemanyr   renameunlink)selfr   	hist_fileconinputsfirst_sessionoutputssessionsnew_hist_fileinew_dbbackup_hist_files               M/var/www/equiseq/venv/lib/python3.11/site-packages/IPython/core/historyapp.pystartzHistoryTrim.start2   s   4+455"22	oi(( ckk #SUYU^_`U`Tbd d e ev;;$)##QTXT]]^^^RSSSF?$)KLLL

 	Z"1IaLM3;; (KMZL\^ ^ _ _GCKK )FHUGWY Y Z ZH		 $&::""$$ 	JFA'+?#a&&+HIM ""$$ 	J // M 	N 	N 	N 	 8 	9 	9 	9 	 8 	9 	9 	9 	  	Y Y Y""#LhWWW""#I6RRR""#NPWXXX	Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y
 	; 		A*.E.IJ"))++ OQ#.2IA2M#N  #))++ O -...46FGGGGY'''''s   >AIIIN)__name__
__module____qualname__trim_hist_helpdescriptionr   tagr   r   r   r	   dictr   flagsaliasesr3        r2   r   r   !   s         KT%OPPPTT U  F 3tKLLLPP Q  D Dmh%56DEEE E d44/00011G@( @( @( @( @(r>   r   c                       e Zd ZeZ edd          Z edd                              d          Z	 e
 ed ddiie	j        fd	ddiie	j        f
                    Z e
            Zd ZdS )HistoryClearr   r   r   Fz"Don't prompt user for confirmationTr   forcer   )rA   fc                 p    | j         st          ddd          rt                              |            d S d S )Nz#Really delete all ipython history? no)default	interrupt)rA   r   r   r3   r'   s    r2   r3   zHistoryClear.start   sO    : 	$144
 
 
 	$ d#####	$ 	$r>   N)r4   r5   r6   clear_hist_helpr8   r   r   r   r9   rA   r	   r:   r   r;   r<   r3   r=   r>   r2   r@   r@   u   s        !K3qHIIIDDABBBFFdFSSED"WdO4ejA/<	
 	
 	
 E dffG$ $ $ $ $r>   r@   c                       e Zd ZdZdZ e eeej                                        d         fe	e	j                                        d         f                    Z
d ZdS )
HistoryAppzipython-historyz$Manage the IPython history database.r   )trimclearc           	      @   | j         t          dd                    t          t          | j                            z   dz              |                                  |                                  |                     d           d S | j         	                                S )Nz.No subcommand specified. Must specify one of: z, z.
r   )
subappr   joinmapreprsubcommandsprint_descriptionprint_subcommandsexitr3   rG   s    r2   r3   zHistoryApp.start   s    ;@))Cd&677889  
 ""$$$""$$$IIaLLLLL;$$&&&r>   N)r4   r5   r6   namer8   r	   r:   r   
splitlinesr@   rR   r3   r=   r>   r2   rJ   rJ      s        D8K$tt[4??AA!DE|7BBDDQGH    K
' ' ' ' 'r>   rJ   )__doc__r   pathlibr   traitlets.config.applicationr   applicationr   	traitletsr   r   r	   utils.ior   r7   rH   r   r@   rJ   r=   r>   r2   <module>r^      s            4 4 4 4 4 4 / / / / / / % % % % % % % % % % ! ! ! ! ! !Q( Q( Q( Q( Q(( Q( Q( Q(h$ $ $ $ $; $ $ $*' ' ' ' ' ' ' ' ' 'r>   