← Back
Editing: historyapp.cpython-311.pyc
� �@�c � � � d Z ddlZddlmZ ddlmZ ddlmZ ddlm Z m Z mZ dd lm Z d ZdZ G d� d e� � Z G d� de� � Z G d� de� � ZdS )zb An application for managing IPython history. To be invoked as the `ipython history` subcommand. � N)�Path)�Application� )�BaseIPythonApplication)�Bool�Int�Dict� )� ask_yes_noz�Trim 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 Zd ZeZ edd�� � � d�� � Z edd�� � � d�� � Z e ed ddiiej f� � � � � Z e ed �� � � � Zd� Zd S )�HistoryTrimFz/Keep the old history file as history.sqlite.<N>��helpT��configi� �/Number of recent lines to keep in the database.�backup)r zHistoryTrim.keep)�keepc � � t | j j � � }|dz }t j |� � }t |� d| j dz 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.| dz } |d t | � � z z }|� � � �.t j |� � } | � d� � | � d� � | � d � � | � � � |r\| 5 | � d|� � | � d|� � | � d|� � d d d � � n# 1 swxY w Y | � � � | j red} |d| z z }|� � � r!| dz } |d| z z }|� � � �!|� |� � t d|� � n|� � � |� |� � d S )Nzhistory.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 >= ?zhistory.sqlite.newz�CREATE TABLE IF NOT EXISTS sessions (session integer primary key autoincrement, start timestamp, end timestamp, num_cmds integer, remark text)z�CREATE TABLE IF NOT EXISTS history (session integer, line integer, source text, source_raw text, PRIMARY KEY (session, line))z�CREATE 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 (?,?,?)zhistory.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 �9/usr/lib/python3/dist-packages/IPython/core/historyapp.py�startzHistoryTrim.start6 s� � ��4�+�4�5�5���"2�2� ��o�i�(�(�� �c�k�k� #S�UY�U^�_`�U`�Tb�d� d� e� e���v�;�;�$�)�#�#��Q�TX�T]�]�^�^�^��R�S�S�S��F� �?�$�)�K�L�L�L�� � ����������� Z�"�1�I�a�L�M��3�;�;� (K�MZ�L\�^� ^� _� _�G��C�K�K� )F�HU�GW�Y� Y� Z� Z�H�� � ���� $�&:�:� � ���"�"�$�$� J� ��F�A�'�+?�#�a�&�&�+H�I�M� �"�"�$�$� J� ���/�/����� M� N� N� N� ��� 8� 9� 9� 9� ��� 8� 9� 9� 9� � � ���� � Y�� Y� Y��"�"�#L�h�W�W�W��"�"�#I�6�R�R�R��"�"�#N�PW�X�X�X� Y� Y� Y� Y� Y� Y� Y� Y� Y� Y� Y���� Y� Y� Y� Y� �������;� ��A�*�.E��.I�J��"�)�)�+�+� O��Q���#.�2I�A�2M�#N� � #�)�)�+�+� O� ���-�.�.�.��4�6F�G�G�G�G����������Y�'�'�'�'�'s �>AI � I�IN)�__name__� __module__�__qualname__�trim_hist_help�descriptionr �tagr r r r �dictr �flags�aliasesr3 � � r2 r r ! s� � � � � � � �K� �T�%� >� � � � �#�T�#� � � � �3�t� >� � � � �#�T�#� � � � �D��� �H�t�#4�5��K� �� � � � �E� �D���!�� � � � �G�@(� @(� @(� @(� @(r>