Sindbad~EG File Manager
�
%Μga����dZddlZddlZddlZddlmZmZddlmZddl m
Z
ddlmZdd�Z
d�Zd �ZGd
�de
�Zd�Zed
k(r ddlmZeddd��ddlmZee�yy)z�Grep dialog for Find in Files functionality.
Inherits from SearchDialogBase for GUI and uses searchengine
to prepare search pattern.
�N)� StringVar�
BooleanVar)�Checkbutton)�SearchDialogBase)�searchenginec���|j�}tj|�}t|d�st |||�|_|j
}|jdd�}|j
|||�y)a�Open the Find in Files dialog.
Module-level function to access the singleton GrepDialog
instance and open the dialog. If text is selected, it is
used as the search phrase; otherwise, the previous entry
is used.
Args:
text: Text widget that contains the selected text for
default search phrase.
io: iomenu.IOBinding instance with default path to search.
flist: filelist.FileList instance for OutputWindow parent.
�_grepdialogz sel.firstzsel.lastN)�_rootr�get�hasattr�
GrepDialogr �open)�text�io�flist�root�engine�dialog�searchphrases �)/usr/local/lib/python3.12/idlelib/grep.py�greprse���:�:�<�D�
�
�
�d�
#�F��6�=�)�'��f�e�<���
�
�
�F��8�8�K��4�L�
�K�K��l�B�'�c��t|�y)zHandle os.walk error.N)�print)�msgs r�
walk_errorr+s �� �#�Jrc#���K�tj|t��D]\�}}��fd�|D�Ed{���|r�yy7��w)z�Generate file names in dir that match pattern.
Args:
folder: Root directory to search.
pattern: File pattern to match.
recursive: True to include subdirectories.
)�onerrorc3��K�|]:}tj|��r"tjj�|����<y�w�N)�fnmatch�os�path�join)�.0�name�dirpath�patterns ��r� <genexpr>zfindfiles.<locals>.<genexpr>9s6�����7� )�����t�W�5��G�G�L�L��$�/� )�s�AAN)r"�walkr)�folderr(� recursive�_� filenamesr's ` @r� findfilesr/0sJ�����"$�����!D����I�7� )�7� 7� 7���"E� 7�s�2A�A�A�Ac�V��eZdZdZdZdZdZ�fd�Zdd�Zd�Z d�Z
d �Zdd
�Zd�Z
�xZS)
r
z$Dialog for searching multiple files.zFind in Files Dialog�Greprc�t��t�|�||�||_t|�|_t|�|_y)a-Create search dialog for searching for a phrase in the file system.
Uses SearchDialogBase as the basis for the GUI and a
searchengine instance to prepare the search.
Attributes:
flist: filelist.Filelist instance for OutputWindow parent.
globvar: String value of Entry widget for path to search.
globent: Entry widget for globvar. Created in
create_entries().
recvar: Boolean value of Checkbutton widget for
traversing through subdirectories.
N)�super�__init__rr�globvarr�recvar)�selfrrr� __class__s �rr4zGrepDialog.__init__Gs2��� ����v�&���
� ����� ��&��rc�d�tj|||�|r|jxsd}nd}tjj|�\}}tjj
|�\}}|sd}|jjtjj|d|z��y)a_Make dialog visible on top of others and ready to use.
Extend the SearchDialogBase open() to set the initial value
for globvar.
Args:
text: Multicall object containing the text information.
searchphrase: String phrase to search.
io: iomenu.IOBinding instance containing file path.
�z.py�*N)
rr�filenamer"r#�split�splitextr5�setr$) r7rrrr#�dir�base�head�tails rrzGrepDialog.openZs��� ���d�D�,�7�
��;�;�$�"�D��D��G�G�M�M�$�'� ��T��W�W�%�%�d�+�
��d���D�����������c�3��:�6�7rc�v�tj|�|jd|j�d|_y)z9Create base entry widgets and add widget for search path.z In files:rN)r�create_entries�
make_entryr5�globent�r7s rrEzGrepDialog.create_entriesps+���'�'��-����{�D�L�L�A�!�D��rc�|�t|j�d|jd��}|jdd��y)z0Add check button to recurse down subdirectories.rzRecurse down subdirectories)�variabler�top�both)�side�fillN)r�
make_framer6�pack)r7�btns r�create_other_buttonszGrepDialog.create_other_buttonsus6������!�!�$�t�{�{�2�4�� ���e�&��)rc�j�tj|�|jd|jd��y)z<Create base command buttons and add button for Search Files.zSearch FilesT)�isdefN)r�create_command_buttons�make_button�default_commandrHs rrUz!GrepDialog.create_command_buttons|s+���/�/��5������)=�)=�T��Jrc�j�|jj�}|sy|jj�}|s|jj�yddlm}tj} ||j�t_ |j||�|t_ y#|t_ wxYw)a
Grep for search pattern in file path. The default command is bound
to <Return>.
If entry values are populated, set OutputWindow as stdout
and perform search. The search dialog is closed automatically
when the search begins.
Nr)�OutputWindow)r�getprogr5rrK�bell�idlelib.outwinrY�sys�stdoutr�grep_it)r7�event�progr#rY�saves rrWzGrepDialog.default_command�s���{�{�"�"�$�����|�|���!����H�H�M�M�O��/��z�z�� �%�d�j�j�1�C�J��L�L��t�$��C�J���C�J�s�,-B%�%
B2c���tjj|�\}}|stj}t t|||jj���}|j�|jj�}td|�d|�d��d} |D]z} t|d��5} t| d�D]Q\}
}|dd d
k(r|d d}|j|�s�%tj j#|�d|
�d|�d
��|dz
}�S d d d ��|t|rd|�d
��y d�y #1swY�$xYw#t$$r}t|�Yd }~��d }~wwxYw#t&$rYy wxYw)a�Search for prog within the lines of the files in path.
For the each file in the path directory, open the file and
search each line for the matching pattern. If the pattern is
found, write the file and line information to stdout (which
is an OutputWindow).
Args:
prog: The compiled, cooked search pattern.
path: String containing the search path.
z
Searching z in z ...r�replace)�errors����N�
z: zHits found: z'
(Hint: right-click to open locations.)zNo hits.)r"r#r=�curdir�sortedr/r6r�closer�getpatrr� enumerate�searchr]r^�write�OSError�AttributeError)
r7rar#r+�filepat�filelist�pat�hits�fn�f�lineno�liners
rr_zGrepDialog.grep_it�sd���'�'�-�-��-������Y�Y�F��)�F�G�T�[�[�_�_�5F�G�H���
�
���k�k� � �"��
�
�3�'��d�V�4�0�1��� ��� ��b��3�q�,5�a��O�L�F�D�#�B�C�y�D�0�'+�C�R�y��#�{�{�4�0� #�
�
� 0� 0�B�4�r�&���D�6��1L� M� $�� ��-<�4���
��!���&N�O�
+�)�
+�4�3�����#�J�J����� �
� �s`�"E'�(
E�51D:�'/D:�E�E'�3E'�:E �?E� E$�E�E'�E$�$E'�' E3�2E3r )�__name__�
__module__�__qualname__�__doc__�title�icon�needwrapbuttonr4rrErRrUrWr_�
__classcell__)r8s@rr
r
@s:���*�"�E��D��N�'�&8�,E�
*�K�
�.%rr
c����
��ddlm}m}m�ddlm}m}ddlm}||�}|jd�tt|j�jd�dd�\}}|jd|�d|dz���||��
||�} | j�|| d �
���j��jdd���
�fd
�}
|| d|
��}|j�y)Nr)�Toplevel�Text�SEL)�Frame�Button)�PyShellFileListzTest GrepDialog�+rf��)�height�1.0zimport grepc�l���j�dd�t�����j�dd�y)Nr�z1.end)r)�tag_addr�
tag_remove)r�rrs���r�show_grep_dialogz&_grep_dialog.<locals>.show_grep_dialog�s-������S�%��)��T�������U�G�,rzShow GrepDialog)r�command)�tkinterr�r�r��tkinter.ttkr�r��idlelib.pyshellr�r~�map�int�geometryr=rP�insert)�parentr�r�r�r�r�rK�x�y�framer��buttonr�rrs @@@r�_grep_dialogr��s����+�+�)�/�
�6�
�C��I�I�� ��s�F�O�O�%�+�+�C�0���4�5�D�A�q��L�L�1�Q�C�q��S�� �"�#��C� �E��#�J�E� �J�J�L���a� �D��I�I�K��K�K��}�%�-�
�E� 1�;K�
L�F�
�K�K�Mr�__main__)�mainzidlelib.idle_test.test_grep�F)� verbosity�exit)�run)NN)r}r!r"r]r�rrr�r�idlelib.searchbaser�idlelibrrrr/r
r�rz�unittestr��idlelib.idle_test.htestr��rr�<module>r�so���
� �
�)�#�/� �(�.�
� }�!�}�@�4�z���� &�!�%�@�+����r
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists