
ddc           @` sW  d  Z  d d l m Z m Z m Z m Z d d l Td d l Z d d l Z d d l	 Z	 d d l
 Z
 d d l Z d d l Z d d l Z e j d  d d l Z d d l Z d d l m Z d d l 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 d d l m Z d d l m Z e j j  j! d  Z" d@ Z# \ Z$ Z% Z& Z' Z( d d d  Z* d   Z+ d   Z, d   Z- d   Z. d   Z/ d   Z0 d   Z1 d   Z2 d   Z3 d   Z4 d e j5 j6 j7 f d     YZ8 d  e8 f d!     YZ9 d" e8 f d#     YZ: d$   Z; d%   Z< d&   Z= e> d'  Z? d(   Z@ d)   ZA d*   ZB d+   ZC d,   ZD d-   ZE d.   ZF d/   ZG d0   ZH d1   ZI eJ eJ d2  ZK d3   ZL d4   ZM d5   ZN d6   ZO d7   ZP d8   ZQ d9   ZR d:   ZS d;   ZT e jU d< eE f d= eF f d> eI f d? eK f g  ZV e jU d= eR f d> eS f d? eT f g  ZW d S(A   uq   Steps to upgrade the plug-in to the latest version (e.g. due to files or
settings being reorganized or removed).
i    (   t   absolute_importt   divisiont   print_functiont   unicode_literals(   t   *Nu   2.0(   t   pdb(   t	   pygimplib(   t   actions(   t   builtin_constraints(   t   builtin_procedures(   t   utils(   t   messagesu   3.3i   i   i   i   u   ask_to_clearc   
      C` s  | d k r! t j j j   } n  t |  rG t j |  |  t d f St j	 j
 j t j j  } t |  | |  \ } } } } } | t j j j k r | | k r t | f S| t j j j k r| t k r|  d j   t |  | t | | | |  t | f S| d k rrt j t d  t j d t j d t j }	 |	 t j k ret j |  |  t | f St  | f Sn0 | d k rt j |  |  t | f St  | f Sd S(	   un  Updates settings and setting sources to the latest version of the plug-in.
  
  This includes renaming settings or replacing obsolete actions.
  
  `handle_invalid` is a string indicating how to handle a failed update:
    
    * `'ask_to_clear'` - a message is displayed asking the user whether to clear
      settings. If the user chose to clear the settings, `CLEAR_SETTINGS` is
      returned, `ABORT` otherwise.
    
    * `'clear'` - settings will be cleared unconditionally and `CLEAR_SETTINGS`
      is returned.
    
    * any other value - no action is taken and `ABORT` is returned.
  
  If `sources` is `None`, default setting sources are updated. Otherwise,
  `sources` must be a dictionary of (key, source) pairs.
  
  Two values are returned - status and an accompanying message.
  
  Status can have one of the following integer values:
  
  * `FRESH_START` - The plug-in was never used before or has no settings stored.
  
  * `UPDATE` - The plug-in was successfully updated to the latest version.
  
  * `CLEAR_SETTINGS` - An old version of the plug-in (incompatible with the
    changes in later versions) was used that required clearing stored settings.
  
  * `NO_ACTION` - No update was performed as the plug-in version remains the
    same.
  
  * `ABORT` - No update was performed. This value is returned if the user
    cancelled clearing settings interactively.
  u    u   main/plugin_versionu   ask_to_clearuN   Due to significant changes in the plug-in, settings need to be reset. Proceed?t   buttonst   button_response_id_to_focusu   clearN(!   t   Nonet   pgt   settingt	   Persistort   get_default_setting_sourcest   _is_fresh_startt   utils_t   save_plugin_versiont   FRESH_STARTt   versiont   Versiont   parset   configt   PLUGIN_VERSIONt+   _get_version_from_sources_and_load_settingst   SUCCESSt	   NO_ACTIONt#   MIN_VERSION_WITHOUT_CLEAN_REINSTALLt   resett   handle_updatet   _UPDATE_HANDLERSt   UPDATER   t   display_messaget   _t   gtkt   MESSAGE_WARNINGt   BUTTONS_YES_NOt   RESPONSE_NOt   RESPONSE_YESt   clear_setting_sourcest   CLEAR_SETTINGSt   ABORT(
   t   settingst   handle_invalidt   sourcest   current_versiont   previous_versiont   load_statust   load_messaget   are_procedures_loadedt   are_constraints_loadedt   response(    (    s>   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/update.pyt   update(   sF    $
!!

			

c         C` s  t  j j j d  } t | |  } t } t } | d  k	 r t |  | |  \ } } } | su t  j j	 j
 } d }	 qt  j j	 j } | }	 n~ |  d j   }
 t d   |
 j j   D  r t  j j	 j
 } n	 |
 j } d j |
 j j    }	 t  j j j |  d j  } | | |	 | | f S(   Nu   utf-8u    u   main/plugin_versionc         s` s$   |  ] } | t  j j j k Vq d  S(   N(   R   R   R   t   SOURCE_NOT_FOUND(   t   .0t   status(    (    s>   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/update.pys	   <genexpr>   s   u   
(   R   R   t   SOURCE_NAMEt   encodet   _parse_version_using_old_formatt   FalseR   t   _load_settings_with_old_formatR   R   R   t   FAILt   loadt   anyt   statuses_per_sourcet   valuesR;   t   joint   messages_per_sourceR   R   R   t   value(   R.   R0   R1   t   keyR2   R5   R6   t   error_messageR3   R4   t   load_result(    (    s>   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/update.pyR   }   s(    				c         C` s   d  } xr |  j   D]d } t | t j j j  r@ t |  } n' t | t j j j  rg t	 |  } n  | d  k	 r Pq q W| d  k	 r t j
 j j |  Sd  Sd  S(   N(   R   RE   t
   isinstanceR   R   R0   t   GimpShelfSourcet"   _parse_version_from_session_sourcet   GimpParasiteSourcet%   _parse_version_from_persistent_sourceR   R   R   (   R0   RI   t   parsed_versiont   source(    (    s>   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/update.pyR>      s    c         C` s9   y t  j |   } Wn t  j k
 r* d  SXt |  Sd  S(   N(   t   gimpt   get_datat   errorR   t   _parse_version(   RI   t   session_data(    (    s>   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/update.pyRN      s
    c         C` s0   t  j |   } | d  k	 r( t | j  Sd  Sd  S(   N(   RS   t   parasite_findR   RV   t   data(   RI   t   parasite(    (    s>   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/update.pyRP      s    c         C` s4   t  j d |   } | d  k	 r, | j   d Sd  Sd  S(   Nu;   main/plugin_version.*?\n.*?\n.*?([0-9]+\.[0-9]+(\.[0-9]+)?)i    (   t   ret   searchR   t   groups(   t   str_t	   str_match(    (    s>   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/update.pyRV      s    c         C` s<  t  | t | t j j j d   t |  } | rA t t | f St |   t	 |  j
    } x | j   D] } t | t j j j  r t | t d  \ } } n3 t | t j j j  r t | t d  \ } } n  | rj t t | f Sqj W|  d | k } t |  d |  |  d | k } t |  d |  | | | f S(   Nu   utf-8u   sessionu
   persistentu   main/procedures/_added_datau   main/proceduresu   main/constraints/_added_datau   main/constraints(   t   fix_element_paths_for_picklet   _FIX_PICKLE_HANDLERSR   R   R<   R=   t'   _rename_settings_with_specific_settingsR?   t   _add_obsolete_settingst   listt   walkRE   RL   R   R0   RM   t   _read_settings_with_old_formatt   OldGimpShelfSourceRO   t   OldGimpParasiteSourcet   _update_format_of_actions(   R.   R0   R1   RJ   t   settings_not_loadedRR   R5   R6   (    (    s>   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/update.pyR@      s*    
c         C` s+   t  d d d d d d d d d d g
 |   S(   Nu!   gui/export_name_preview_sensitiveu   gui/name_preview_sensitiveu"   gui/export_image_preview_sensitiveu   gui/image_preview_sensitiveu)   gui/export_image_preview_automatic_updateu"   gui/image_preview_automatic_updateuC   gui/export_image_preview_automatic_update_if_below_maximum_durationu<   gui/image_preview_automatic_update_if_below_maximum_durationu   gui/dialog_positionu   gui/size/dialog_positionu   gui/dialog_sizeu   gui/size/dialog_sizeu#   gui/paned_outside_previews_positionu(   gui/size/paned_outside_previews_positionu#   gui/paned_between_previews_positionu(   gui/size/paned_between_previews_positionu   gui/settings_vpane_positionu    gui/size/settings_vpane_positionu   gui_session/current_directoryu   gui/current_directory(   u!   gui/export_name_preview_sensitiveu   gui/name_preview_sensitive(   u"   gui/export_image_preview_sensitiveu   gui/image_preview_sensitive(   u)   gui/export_image_preview_automatic_updateu"   gui/image_preview_automatic_update(   uC   gui/export_image_preview_automatic_update_if_below_maximum_durationu<   gui/image_preview_automatic_update_if_below_maximum_duration(   u   gui/dialog_positionu   gui/size/dialog_position(   u   gui/dialog_sizeu   gui/size/dialog_size(   u#   gui/paned_outside_previews_positionu(   gui/size/paned_outside_previews_position(   u#   gui/paned_between_previews_positionu(   gui/size/paned_between_previews_position(   u   gui/settings_vpane_positionu    gui/size/settings_vpane_position(   u   gui_session/current_directoryu   gui/current_directory(   t   _rename_settings(   R0   (    (    s>   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/update.pyRb      s,              c         C` s   d  } x | j   D] } y | j   } Wn  t k
 rK } t |  } Pn X| r x8 |  D]0 \ } } | | k rY | | | | <| | =qY qY W| j |  q q W| S(   N(   R   RE   t   read_data_from_sourcet	   Exceptiont   strt   write_data_to_source(   t   settings_to_renameR0   RJ   RR   RY   t   et   orig_setting_namet   new_setting_name(    (    s>   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/update.pyRk     s    c         C` sj   |  d j  i d d 6d d 6i d d 6d d 6g  |  d j  i d d 6d d 6i d d 6d d 6g  d  S(	   Nu   main/proceduresu   listu   typeu   _added_datau   nameu   dictu   _added_data_valuesu   main/constraints(   t   add(   R.   (    (    s>   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/update.pyRc     s    

c         C` so   | t  j j |  } |  } d  } | j   re y | j |   } Wqe t k
 ra } t |  } qe Xn  | | f S(   N(   R   R   R<   R   t   has_datat   readRm   Rn   (   R.   t   source_classt   source_typeRR   Rj   RJ   Rq   (    (    s>   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/update.pyRf   3  s    t	   OldSourcec           B` s   e  Z d    Z RS(   c         C` s   g  } |  j    } | d  k r" d  Sx{ | D]s } y | | j d  } Wn t k
 rf | j |  q) Xy | j |  Wq) t j j k
 r | j	   q) Xq) W| S(   Nu   root(
   Rl   R   t   get_patht   KeyErrort   appendt	   set_valueR   R   t   SettingValueErrorR    (   t   selfR.   Rj   t   settings_from_sourceR   RH   (    (    s>   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/update.pyRv   D  s    (   t   __name__t
   __module__Rv   (    (    (    s>   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/update.pyRy   B  s   Rg   c           B` s5   e  Z d    Z d   Z d   Z d   Z d   Z RS(   c         C` s   d  t j |  j   <d  S(   N(   R   t	   gimpshelft   shelft   _get_key(   R   (    (    s>   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/update.pyt   clear[  s    c         C` s/   t  j j |  j    o. t  j |  j   d  k	 S(   N(   R   R   t   has_keyR   R   (   R   (    (    s>   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/update.pyRu   ^  s    c         C` s.   y t  j |  j   SWn t k
 r) d  SXd  S(   N(   R   R   R   Rm   R   (   R   (    (    s>   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/update.pyRl   c  s    c         C` s   | t  j |  j   <d  S(   N(   R   R   R   (   R   t   setting_names_and_values(    (    s>   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/update.pyRo   i  s    c         C` s   t  j j |  j  S(   N(   R   R
   t   safe_encode_gimpt   source_name(   R   (    (    s>   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/update.pyR   l  s    (   R   R   R   Ru   Rl   Ro   R   (    (    (    s>   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/update.pyRg   Y  s
   				Rh   c           B` s,   e  Z d    Z d   Z d   Z d   Z RS(   c         C` s0   t  j |  j  d  k r d  St  j |  j  d  S(   N(   RS   RX   R   R   t   parasite_detach(   R   (    (    s>   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/update.pyR   r  s    c         C` s   t  j |  j  d  k	 S(   N(   RS   RX   R   R   (   R   (    (    s>   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/update.pyRu   x  s    c         C` sQ   t  j |  j  } | d  k r" d  Sy t j | j  } Wn t k
 rL d  SX| S(   N(   RS   RX   R   R   t   picklet   loadsRY   Rm   (   R   RZ   R   (    (    s>   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/update.pyRl   {  s    c         C` s5   t  j |  } t j t j |  j t j |   d  S(   N(   R   t   dumpsRS   t   parasite_attacht   ParasiteR   t	   gimpenumst   PARASITE_PERSISTENT(   R   R   RY   (    (    s>   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/update.pyRo     s    (   R   R   R   Ru   Rl   Ro   (    (    (    s>   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/update.pyRh   p  s   			c         ` s^  |  d j  } |  d j  } t j |  d  t j |  d  | rV t j |  d t n  xr| D]j} d | k r | d t j j k r t j j | d <n  d | k r t	 j
 d d | d  | d <n  d	 | k rxJ | d	 D]; } d | k r | d t j j k r t j j | d <q q Wn  d
 | k rFt | d
  rFd | d
 <n  d | k rj| d | d <| d =n  d | k r| d =n  d | k r| d rd | d <n
 d | d <| d =n  t j |  |  q] Wx | j   D]~ \   }   j d  rt	 j
 d d      n  t   f d   d d d g D  r6qn    |  k r|    j |  qqWd  S(   Nu   _added_datau   _added_data_valuest   add_initial_actionsu   typeu	   orig_nameu   _[0-9]+$u    u   nameu	   argumentsu   functionu   operation_groupsu   action_groupsu	   subfilteru   is_pdb_procedureu   gimp_pdbu   originu   builtinu   /operation_groupsu   /operation_groups$u   /action_groupsc         3` s   |  ] }   j  |  Vq d  S(   N(   t   endswith(   R:   t   suffix(   t   path(    s>   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/update.pys	   <genexpr>  s    u   /is_pdb_procedureu
   /subfilteru	   /function(   RH   t   actions_t   removeR   R?   R   R   t   Settingt   GenericSettingR[   t   subt   callableRt   t   itemsR   RC   R}   (   R   t   are_actions_loadedt   action_dictst   setting_valuest   action_dictt   argument_dictRH   (    (   R   s>   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/update.pyRi     sF    " "




%c   
      C` s   x | j    D] } | j   q Wx[ | j   D]M \ } }	 | t j j j |  k  o` | k n r. |	 |  | | |  q. q. W|  j |  d  S(   N(   RE   R   R   R   R   R   R   t   save(
   R.   R0   t   update_handlersR2   R1   R5   R6   RR   t   version_strt   update_handler(    (    s>   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/update.pyR!     s    +c         C` sL   xE | j    D]7 \ } } t j j j |  | k r | |  |  q q Wd  S(   N(   R   R   R   R   R   (   R0   t   fix_pickle_handlersR1   RI   R   t   fix_pickle_handler(    (    s>   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/update.pyR`     s    c         C` s  t  j j |  d d   | D } g  } x| j D]} t | t j  rZ | j |  q2 | d } g  } t |  d k r| s xZ| d D]] } | }	 xA | D]9 }
 | |
 d k r q n  t	 j
 |
 d |
 d |	  }	 q W| j |	  q Wqt | d  } x | D] }
 | |
 d k r$qn  t |
 d  t | d  k rJqn  xK t t |
 d   D]3 } t	 j
 |
 d | |
 d | | |  | | <qaWx@ t t |
 d  t |
 d   D] } | j |
 d |  qWqWn  | j | | f  q2 Wt  j j j |  S(   Nt   fieldsc         S` s    i  |  ] } d    | d  q S(   c          W` s   d  S(   N(   R   (   t   args(    (    s>   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/update.pyt   <lambda>  t    i    (    (   R:   t   item(    (    s>   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/update.pys
   <dictcomp>  s   	 i    i   i   (   R   R   t   StringPatternt   pattern_partsRL   t   typest   StringTypesR|   t   lenR[   R   Rd   t   ranget   reconstruct_pattern(   t   patternt(   field_regexes_arguments_and_replacementst   as_listst   string_patternt   processed_pattern_partst   partt   field_regext   new_argumentst   argumentt   new_argumentR   t   i(    (    s>   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/update.pyt"   replace_field_arguments_in_pattern  s<    	
! 1* c   
      C` s   g  } t  |   } xU t |  D]G \ } } | j j |  r | j | | f  t j |  | j  q q Wxf | D]^ \ } } | | k rq | | }	 | d j |	 d <t j |  |	  } t j	 |  | j |  qq qq W| S(   Nu   enabled(
   Rd   t	   enumeratet   namet
   startswithR|   R   R   RH   Rt   t   reorder(
   R   t   old_action_prefixt   new_action_prefixt   builtin_actions_dictt   removed_actionst   actions_listt   indext   actiont   removed_actionR   (    (    s>   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/update.pyt   _refresh_actions  s    
c         C` sn   g  } t  |   } xU t |  D]G \ } } | j j |  r t j |  | j  | j | | f  q q W| S(   N(   Rd   R   R   R   R   R   R|   (   R   t   action_prefixt   removed_actions_and_indexesR   R   R   (    (    s>   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/update.pyt   _remove_actions   s    c         C` sG   g  |  j  d t  D]0 } t | t j j  r d | j k r | ^ q S(   Nt   include_groupsu   action(   Re   t   TrueRL   R   R   t   Groupt   tags(   R.   R   (    (    s>   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/update.pyt   _get_actions-  s    c         C` s   t  d   |  j   D  S(   Nc         s` s   |  ] } | j    Vq d  S(   N(   Ru   (   R:   RR   (    (    s>   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/update.pys	   <genexpr>5  s    (   t   allRE   (   R0   (    (    s>   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/update.pyR   4  s    c         C` s)   y t  j |   Wn t k
 r$ n Xd  S(   N(   t   osR   Rm   (   t   filepath(    (    s>   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/update.pyt   _try_remove_file8  s    c      
   O` sa   |  d j  t |  d j d d d g d d d g d d d g d d	 d
 g d d	 d g g   d  S(   Nu   main/layer_filename_patternu
   layer nameu   keep extensionu   %eu   keep only identical extensionu   %iu
   image nameu
   layer pathu   \$\$u   %cu   tagsu   %t(   R}   R   RH   (   R.   R0   R   t   kwargs(    (    s>   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/update.pyt   _update_to_3_3_1?  s    

c      
   O` s   t    t   |  d j t |  d j d d d g d d d g g d d g d d d g g d g  d d d g g g d t  t |  d	 d
 d
 t j  d  S(   Nu   main/layer_filename_patternu
   layer pathu   (.*)u   \1u   %eu   %cu   -R   u   main/proceduresu   ignore_folder_structure(	   t&   _remove_obsolete_pygimplib_files_3_3_2t#   _remove_obsolete_plugin_files_3_3_2R}   R   RH   R   R   R	   t   BUILTIN_PROCEDURES(   R.   R0   R   R   (    (    s>   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/update.pyt   _update_to_3_3_2L  s    


c          C` s   x t  j t j  D] }  t  j j t j |   } |  j d  sO |  j d  r t  j j |  rn t |  q t  j j	 |  r t
 j | d t q q |  d k r t  j j	 |  r t
 j | d t q q q Wd  S(   Nu   pgu   _pgt   ignore_errorsu   lib(   R   t   listdirR   t   PYGIMPLIB_DIRPATHR   RF   R   t   isfileR   t   isdirt   shutilt   rmtreeR   (   t   filenameR   (    (    s>   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/update.pyR   c  s    c          C` s   t  j j }  t j j |  d  } xH t j |  D]7 } t j j | |  } | j d  r1 t |  q1 q1 Wt t j j |  d   t t j j |  d   t t j j |  d d   t t j j |  d d   d  S(   Nu   guiu   gui_u   operations.pyu   operations.pyc(	   R   R   t   PLUGIN_SUBDIRPATHR   R   RF   R   R   R   (   t   plugin_subdirectory_dirpatht   gui_package_dirpathR   R   (    (    s>   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/update.pyR   q  s    c         O` sB   t  t j j t j j d   t  t j j t j j d   d  S(   Nu   settings_plugin.pyu   settings_plugin.pyc(   R   R   R   RF   R   R   R   (   R.   R0   R   R   (    (    s>   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/update.pyt   _update_to_3_3_5  s    c         C` s  t  t j j t j j d   t  t j j t j j d   t  t j j t j d   t  t j j t j d   d |  k r |  j d g  n  d |  k r |  j d g  n  d |  d k r |  d j d g  n  | rt	 |  d	 d
 d t
 j  t |  d	  t |  d	 |   n  | rt |  d  t	 |  d d d t j  xB t j |  d  D]- } | d j d k r_| d j t  q_q_Wt	 |  d d d t j  t	 |  d d d t j  t	 |  d d d t j  t	 |  d d d t j  t	 |  d d d t j  n  d  S(   Nu   exportlayers.pyu   exportlayers.pycu   executor.pyu   executor.pycu   gui_sessionu   gui_persistentu   selected_layers_persistentu   mainu   main/proceduresu   rename_layeru   renameu   main/constraintsu   only_visible_layersu   visibleu	   orig_nameu   also_apply_to_parent_foldersu   only_toplevel_layersu	   top_levelu   only_layers_with_tagsu	   with_tagsu   only_layers_without_tagsu   without_tagsu#   only_layers_matching_file_extensionu   matching_file_extensionu   only_selected_layersu   selected_in_preview(   R   R   R   RF   R   R   R   R   R   R   R	   R   t   _update_autocrop_procedurest4   _update_use_file_extensions_in_layer_names_proceduret   _update_include_constraintsR   t   BUILTIN_CONSTRAINTSR   Re   RH   R}   R   (   R.   R0   R5   R6   R   (    (    s>   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/update.pyt   _update_to_4_0  sj    





c         C` s,  t  |  d  } | r | d \ } } t j |  t j  } | d j d  | d j | d j  | d j | d j  t j |  | j |  n  t  |  d  } | r(| d \ } } t j |  t j  } t j |  | j |  | d j d  | d j | d j  | d j | d j  n  d  S(	   Nu   autocrop_backgroundi    u   arguments/drawableu   background_layeru   enabledu   display_nameu   autocrop_foregroundu   foreground_layer(	   R   R   Rt   R   t   plug_in_autocrop_layerR}   RH   R   R   (   t
   procedurest   removed_autocrop_backgroundt
   old_actiont   old_action_indext
   new_actiont   removed_autocrop_foreground(    (    s>   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/update.pyR     s     c         C` s   t  |  d  } | r | d \ } } t j |  t j d  } t j |  | j |  | d j | d j  | d j | d j  | d j | d	 j  n  d  S(
   Nu"   use_file_extensions_in_layer_namesiu   exportu   arguments/output_directoryu   main/output_directoryu   arguments/file_extensionu   main/file_extensionu)   arguments/use_file_extension_in_item_nameu   enabled(	   R   R   Rt   R	   R   R   R   R}   RH   (   R   R.   t   removed_use_file_extensionR   R   R   (    (    s>   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/update.pyR     s    c         C` s   t  |  d  t  |  d  } | s? | r | d d d j r t j |  t j d  } | r t j |  | j | d d  q n  t  |  d  } | s | r | d d d j r t j |  t j d  } | r t j |  | j | d d  q n  d  S(	   Nu   include_empty_layer_groupsu   include_layersi    u   enabledu   layer_groupsi   u   include_layer_groupsu   layers(   R   RH   R   Rt   R   R   R   R   (   t   constraintst   removed_include_layersR   t   removed_include_layer_groups(    (    s>   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/update.pyR     s     $c         C` sk   xd | j    D]V } t | t j j j  r; t |  |  q t | t j j j  r t |  |  q q Wd  S(   N(	   RE   RL   R   R   R0   RM   t#   _fix_pickle_paths_in_session_sourceRO   t&   _fix_pickle_paths_in_persistent_source(   t   paths_to_renameR0   RI   RR   (    (    s>   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/update.pyt   _fix_pickle_paths  s
    c         C` sm   y t  j |  } Wn t  j k
 r) n@ X| } x& |  D] \ } } | j | |  } q7 Wt  j | |  d  S(   N(   RS   RT   RU   t   replacet   set_data(   R   RI   t   session_parasitet   new_datat   old_patht   new_path(    (    s>   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/update.pyR     s    c         C` ss   t  j |  } | d  k	 ro | j } x& |  D] \ } } | j | |  } q+ Wt  j t  j | t j |   n  d  S(   N(	   RS   RX   R   RY   R   R   R   R   R   (   R   RI   t   persistent_parasiteR  R  R  (    (    s>   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/update.pyR   #  s    	c         C` s   t  d d g |  |  d  S(   Ns!   export_layers.pygimplib.pgsettings   export_layers.pygimplib.settings   export_layers.pygimplib.pgutilss   export_layers.pygimplib.utils(   s!   export_layers.pygimplib.pgsettings   export_layers.pygimplib.setting(   s   export_layers.pygimplib.pgutilss   export_layers.pygimplib.utils(   R   (   R0   RI   (    (    s>   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/update.pyt   _fix_pickle_paths_3_3_2-  s    c         C` s   t  d d d	 g |  |  d  S(
   NsA   export_layers.builtin_procedures
use_file_extension_in_layer_names@   export_layers.builtin_procedures
use_file_extension_in_item_namesC   export_layers.builtin_procedures
remove_folder_hierarchy_from_layersB   export_layers.builtin_procedures
remove_folder_hierarchy_from_items=   export_layers.builtin_constraints
is_layer_in_selected_layerss;   export_layers.builtin_constraints
is_item_in_selected_items(   sA   export_layers.builtin_procedures
use_file_extension_in_layer_names@   export_layers.builtin_procedures
use_file_extension_in_item_name(   sC   export_layers.builtin_procedures
remove_folder_hierarchy_from_layersB   export_layers.builtin_procedures
remove_folder_hierarchy_from_item(   s=   export_layers.builtin_constraints
is_layer_in_selected_layerss;   export_layers.builtin_constraints
is_item_in_selected_items(   R   (   R0   RI   (    (    s>   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/update.pyt   _fix_pickle_paths_3_3_56  s       c         C` s/   t  d d d d d d d d d g	 |  |  d  S(   Ns0   export_layers.pygimplib.setting.settings
Settings7   export_layers.pygimplib.setting.settings
GenericSettings0   export_layers.builtin_constraints
is_empty_groups(   export_layers.pygimplib.utils
empty_funcs@   export_layers.builtin_procedures
use_file_extension_in_item_names8   export_layers.builtin_procedures
insert_background_layers;   export_layers.background_foreground
insert_background_layers8   export_layers.builtin_procedures
insert_foreground_layers;   export_layers.background_foreground
insert_foreground_layers1   export_layers.builtin_constraints
is_path_visibles,   export_layers.builtin_constraints
is_visibles6   export_layers.builtin_procedures
autocrop_tagged_layersF   export_layers.pygimplib.setting.settings
ImageIdsAndDirectoriesSettings;   export_layers.settings_custom
ImageIdsAndDirectoriesSetting(   s0   export_layers.pygimplib.setting.settings
Settings7   export_layers.pygimplib.setting.settings
GenericSetting(   s0   export_layers.builtin_constraints
is_empty_groups(   export_layers.pygimplib.utils
empty_func(   s@   export_layers.builtin_procedures
use_file_extension_in_item_names(   export_layers.pygimplib.utils
empty_func(   s8   export_layers.builtin_procedures
insert_background_layers;   export_layers.background_foreground
insert_background_layer(   s8   export_layers.builtin_procedures
insert_foreground_layers;   export_layers.background_foreground
insert_foreground_layer(   s1   export_layers.builtin_constraints
is_path_visibles,   export_layers.builtin_constraints
is_visible(   s6   export_layers.builtin_procedures
autocrop_tagged_layers(   export_layers.pygimplib.utils
empty_func(   s@   export_layers.builtin_procedures
use_file_extension_in_item_names(   export_layers.pygimplib.utils
empty_func(   sF   export_layers.pygimplib.setting.settings
ImageIdsAndDirectoriesSettings;   export_layers.settings_custom
ImageIdsAndDirectoriesSetting(   R   (   R0   RI   (    (    s>   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/update.pyt   _fix_pickle_paths_4_0C  s(             u   3.3.1u   3.3.2u   3.3.5u   4.0(   i    i   i   i   i   (X   t   __doc__t
   __future__R    R   R   R   t   future.builtinst   collectionsR   R   R[   R   R   t   pygtkt   requireR&   RS   R   R   R   t   export_layersR   R   R   R   R   R	   R
   R   t   export_layers.guiR   R   R   R   R   t   _UPDATE_STATUSESR   R#   R,   R   R-   R   R8   R   R>   RN   RP   RV   R@   Rb   Rk   Rc   Rf   R   R0   t   SourceRy   Rg   Rh   Ri   R!   R`   R?   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R  R  R	  t   OrderedDictR"   Ra   (    (    (    s>   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/update.pyt   <module>   s   "
U	!								 					8		.										M						
									                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    # -*- coding: utf-8 -*-

"""Utility functions used in other modules."""

from __future__ import absolute_import, division, print_function, unicode_literals
from future.builtins import *

from export_layers import pygimplib as pg


def get_settings_for_batcher(main_settings):
  return {
    'procedures': main_settings['procedures'],
    'constraints': main_settings['constraints'],
    'edit_mode': main_settings['edit_mode'].value,
    'output_directory': main_settings['output_directory'].value,
    'layer_filename_pattern': main_settings['layer_filename_pattern'].value,
    'file_extension': main_settings['file_extension'].value,
    'overwrite_mode': main_settings['overwrite_mode'].value,
  }


def clear_setting_sources(settings, sources=None):
  if sources is None:
    sources = pg.setting.Persistor.get_default_setting_sources()
  
  pg.setting.Persistor.clear(sources)
  
  save_plugin_version(settings, sources)


def save_plugin_version(settings, sources):
  settings['main/plugin_version'].reset()
  settings['main/plugin_version'].save(sources)
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       