
    Mg                         S SK JrJr  S SKrS SKJr  SrSrSrSr	S r
SS	 jrS
 rS rS r " S S5      r " S S\R                   \5      rg)    )cleandocisclassN)ConnectionErrorMACOSLINUXWINDOWSUNIXc                    ^  U 4S jnU$ )z
Convert function in Plugin Class

@python(platform=LINUX, native="ap-hotspot")
def hotspot_start(jarvis, s):
    system("sudo ap-hotspot start")
c                 $  > [        U R                  [        R                  [	        [        R
                  5      5      nU R                  Ul        [        U 5      (       a  U " 5       n / Ul        / Ul	        / Ul
        TUl        U 4Ul        Xl        U$ N)type__name__Plugin	__bases__dict__dict____doc__r   _require	_complete_alias_name_backend_backend_instance)runplugin_classnames     4/Users/admin/workspace/ai/Jarvis/jarviscli/plugin.pycreate_pluginplugin.<locals>.create_plugin   s    LL&**D-!"  #{{3<<%C !#!# !!$),&     )r   r   s   ` r   pluginr"      s    & r    c                    ^ / mU b  TR                  SU 45        Ub  TR                  SU45        Ub  TR                  SU45        U4S jnU$ )z/Decorator to specify requirements for a plugin.networkplatformnativec                 >   > U R                   R                  T5        U $ r   )r   extend)plugin_instancerequirementss    r   	__requirerequire.<locals>.__require7   s      ''5r    )append)r$   r%   r&   r+   r*   s       @r   requirer.   -   s`    LY01Z23Xv./ r    c                     ^  U 4S jnU$ )z5Decorator to specify completion options for a plugin.c                 >   > U R                   R                  T5        U $ r   )r   r(   )r)   complete_argss    r   
__completecomplete.<locals>.__complete@   s    !!((7r    r!   )r1   r2   s   ` r   completer4   >   s     r    c                     ^  U 4S jnU$ )z*Decorator to specify aliases for a plugin.c                 >   > U R                   R                  T5        U $ r   )r   r(   )r)   
alias_argss    r   __aliasalias.<locals>.__aliasH   s    %%j1r    r!   )r7   r8   s   ` r   aliasr:   F   s     Nr    c              #   $   #    U  S h  vN   g  N7fr   r!   )valuess    r   _yield_somethingr=   N   s     s   c                   4    \ rS rSrSrS rS rS	S jrS rSr	g)
PluginStorageR   z)A storage class for managing sub-plugins.c                     0 U l         g r   _sub_pluginsselfs    r   __init__PluginStorage.__init__U   s
    r    c                      X R                   U'   g)zz
Adds a sub-plugin to the storage.

Args:
    name: The name of the sub-plugin.
    plugin_to_add: The sub-plugin to add.
NrB   )rE   r   plugin_to_adds      r   
add_pluginPluginStorage.add_pluginX   s     #0$r    Nc                 ^    Uc  U R                   $ XR                   ;   a  U R                   U   $ g)z
Retrieves sub-plugins from the storage.

Args:
    name: The name of the sub-plugin to retrieve. If None, all sub-plugins are returned.

Returns:
    All sub-plugins if name is None, otherwise the specified sub-plugin or None if not found
NrB   )rE   r   s     r   get_pluginsPluginStorage.get_pluginsc   s5     <$$$$$$$$T**r    c                 &    U R                   Ul         g)z
Replaces the sub-plugins of another PluginStorage instance with the current sub-plugins.

Args:
    plugin_new: The PluginStorage instance whose sub-plugins will be replaced.
NrB   )rE   
plugin_news     r   change_withPluginStorage.change_witht   s     #'"3"3
r    rB   r   )
r   
__module____qualname____firstlineno__r   rF   rJ   rM   rQ   __static_attributes__r!   r    r   r?   r?   R   s    4	0"4r    r?   c                   f   ^  \ rS rSrSrSrU 4S jrS rS rS r	S r
S	 rS
 rS rS rS rSrU =r$ )r      z
Base class for all plugins.

This class inherits from both IPlugin and PluginStorage, providing a structure
for plugins to be managed and initialized within the Jarvis framework.
Nc                 L   > [         [        R                  U ]  5         0 U l        g r   )superpluginmanagerIPluginrF   rC   )rE   	__class__s    r   rF   Plugin.__init__   s    m##T35r    c                    U R                  5       (       aw  [        U R                  S   R                  S5      (       aO  [	        [        U R                  S   R                  S5      5      (       a  U R                  S   R                  U5        U R                  5       R                  5        H  nUR                  U5        M     g)z
Called before Jarvis starts;
Passes jarvis_api object for plugins to do initialization.
(would not be possible with __init__)
r   initN)	is_callable_pluginhasattrr   r]   callablegetattrr`   rM   r<   )rE   
jarvis_api
sub_plugins      r   r`   Plugin.init   s     ""$$a ** $MM!$..  a %%j1**,335JOOJ' 6r    c                     U R                   SL$ )z
Return True, if this plugin has a executable implementation (e.g. news)
Return False, if this instance is only used for calling other plugins
(e.g. movie in 'movie search' and 'movie plot')
N)r   rD   s    r   ra   Plugin.is_callable_plugin   s     }}D((r    c                     U R                   $ )zSet with @plugin(name))r   rD   s    r   get_namePlugin.get_name   s    zzr    c                     U R                   $ )zSet with @require)r   rD   s    r   r.   Plugin.require   s    }}r    c                     U R                   $ )zSet with @alias)r   rD   s    r   r:   Plugin.alias   s    {{r    c              #      #    U R                  5       (       a  U R                   Sh  vN   U R                  5       R                  5        Sh  vN   g N+ N7f)zSet with @completeN)ra   r   rM   keysrD   s    r   r4   Plugin.complete   sJ      ""$$~~%% ##%**,,, & 	-s!   %AA%AAAAc                 v   SnSnSnU R                   be  [        U R                   5      nUR                  S5      n[        U5      S:  a  X$S   -  nUS   nX-  nUR	                  S5      (       d  US-  nUS-  nU R                  5       R                  5        H  u  pVUSU S3-  nUR                  5       nUR                  S5      n[        U5      S:  a  X'S   -  nUS   nSU;  a  X-  nMV  US	U S
3-  nX7-  nUR	                  S5      (       a  M{  US-  nM     US:w  a	  US-  nX-  nUS:w  a	  US-  nX-  nU$ )zParses plugin doc string z-- Example:   r   
z
Subcommands:z
-> z: z
  z:
z
--Examples:)r   r   splitlenendswithrM   itemsget_doc)rE   docexamplesextended_docdefault_command_docr   sub_commandsub_command_docs           r   r|   Plugin.get_doc   s    <<#"*4<<"8"5";";M"J&'!+22"5a"8&C<<%%t##C "&!1!1!3!9!9!;DU4&##C)113O-33MBO?#a'A..-a0O?*&$tfC 00/&//55 D(L "<" 24KCCr>?"COC
r    c                 T   UR                  X R                  5       R                  5       5      nUS:X  a  U R                  5       (       a%  U R                  S   " UR                  5       U5        gUR                  5       R                  S5        U R                   H6  nUR                  5       R                  SU R                  5        SU 35        M8     gUR                  5       S   nSR                  UR                  5       SS 5      nU R                  U5      R                  X5        g)z$Entry point if this plugin is calledNoner   z8Sorry, I could not recognise your command. Did you mean:z    *  rv   N)find_actionrM   rr   ra   r   get_apisayrC   rk   rx   joinr   )rE   jarvissr   commandnew_ss         r   r   
Plugin.run   s    ((,<,<,>,C,C,EF& &&((a !115 $$%_`#'#4#4KNN$((6$--/1B!K=)QR $5 "'')!,GHH[..045EW%))&8r    c                 r     U" X#5        g! [          a!    UR                  5       R                  5          gf = f)z
Calls run_func(jarvis, s); try-catch ConnectionError

This method is auto-used if require() yields ("network", True). Do not
use m
N)r   r   connection_error)rE   run_funcr   r   s       r   _plugin_run_with_network_error%Plugin._plugin_run_with_network_error   s1    	0V 	0NN--/	0s    (66rB   )r   rS   rT   rU   r   r   rF   r`   ra   rk   r.   r:   r4   r|   r   r   rV   __classcell__)r]   s   @r   r   r      sG     H(")--^9"
0 
0r    r   )NNN)inspectr   r   r[   requestsr   r   r   r   r	   r"   r.   r4   r:   r=   r?   r\   r   r!   r    r   <module>r      s^    %  $ 	
<"*4 *4ZE0]""M E0r    