%PDF- %PDF-
Direktori : /lib/python2.7/site-packages/salt/modules/ |
Current File : //lib/python2.7/site-packages/salt/modules/logrotate.pyc |
� ���^c @@ s� d Z d d l m Z m Z m Z d d l Z d d l Z d d l m Z d d l Z d d l Z d d l Z d d l m Z e j e � Z d Z i d d 6Z d � Z d � Z e d � Z e d � Z d e d � Z d e d � Z d � Z d S( u Module for managing logrotate. i ( t absolute_importt print_functiont unicode_literalsN( t six( t SaltInvocationErroru /etc/logrotate.confu setu set_c C@ s t j j j � r t d f St S( u) Only work on POSIX-like systems uW The logrotate execution module cannot be loaded: only available on non-Windows systems.( t saltt utilst platformt is_windowst Falset True( ( ( s: /usr/lib/python2.7/site-packages/salt/modules/logrotate.pyt __virtual__ s c C@ s1 y t t j | � � } Wn t k r, n X| S( u� Convert to an int if necessary. :param str value: The value to check/convert. :return: The converted or passed value. :rtype: bool|int|str ( t intR t text_typet ValueError( t value( ( s: /usr/lib/python2.7/site-packages/salt/modules/logrotate.pyt _convert_if_int) s c C@ s� i } d } g } i } d } t j j j | d � �D} x:| D]2} t j j j | � j � } | sm q@ n | j d � r� q@ n | j � } d | k r� d | k r� d } t | � d k r� | r� | } q@ | } | j � q@ n d | k r"d } x | D] } | | | <q� Wg } i } q@ n | d k r7| } n | } | d d k rd | k rfi | d <n x� t j | d � D]� } | | d k r�g | d | <n t j j | d | � } t | � } x1 | D]) } | | | | <| d | j | � q�WqzWn | } t | � d k r7d j | d � | | d <q@ t | � d k rdt | d � | | d <q@ t | | d <q@ WWd QX| S( uf Parse a logrotate configuration file. Includes will also be parsed, and their configuration will be stored in the return dict, as if they were part of the main config file. A dict of which configs came from which includes will be stored in the 'include files' dict inside the return dict, for later reference by the user or module. u singleu ru #u {u }u multii i u includeu include filesi u N( t NoneR R t filest fopent stringutilst to_unicodet stript startswitht splitt lent popt ost listdirt patht joint _parse_conft appendR R ( t conf_filet rett modet multi_namest multit prev_compst ifilet linet compst multi_namet keyt includet include_patht include_conft file_key( ( s: /usr/lib/python2.7/site-packages/salt/modules/logrotate.pyR 9 s` c C@ s t | � S( u� Show parsed configuration :param str conf_file: The logrotate configuration file. :return: The parsed configuration. :rtype: dict CLI Example: .. code-block:: bash salt '*' logrotate.show_conf ( R ( R! ( ( s: /usr/lib/python2.7/site-packages/salt/modules/logrotate.pyt show_conf~ s c C@ sQ t | � } | j | t � } | rM | r: | j | t � St j d | � n | S( u Get the value for a specific configuration line. :param str key: The command or stanza block to configure. :param str value: The command value or command of the block specified by the key parameter. :param str conf_file: The logrotate configuration file. :return: The value for a specific configuration line. :rtype: bool|int|str CLI Example: .. code-block:: bash salt '*' logrotate.get rotate salt '*' logrotate.get /var/log/wtmp rotate /etc/logrotate.conf u Block '%s' not present or empty.( R t getR t _LOGt warning( R+ R R! t current_conft stanza( ( s: /usr/lib/python2.7/site-packages/salt/modules/logrotate.pyR1 � s c C@ s< t | � } xB | d D]6 } | | d | k r t j j | d | � } q q Wt j � } i d d 6t d 6| d 6d j | � d 6t d 6} | d k rD| j | t � } t | t � r� d j | � } t | � � n | | k r� t j d | | � t S| t k r| } n | r-d j | | � } n | j i t d 6� n� | j | t � � } | r�t | t � r�d } t | � � n | | j | t � k r�t j d | | � t S| r�| | | <n | | =t | | � } | j i d j | � d 6d d 6t d 6� | j i | d 6� t j d | | � t d | � S( u Set a new value for a specific configuration line. :param str key: The command or block to configure. :param str value: The command value or command of the block specified by the key parameter. :param str setting: The command value for the command specified by the value parameter. :param str conf_file: The logrotate configuration file. :return: A boolean representing whether all changes succeeded. :rtype: bool CLI Example: .. code-block:: bash salt '*' logrotate.set rotate 2 Can also be used to set a single value inside a multiline configuration block. For instance, to change rotate in the following block: .. code-block:: text /var/log/wtmp { monthly create 0664 root root rotate 1 } Use the following command: .. code-block:: bash salt '*' logrotate.set /var/log/wtmp rotate 2 This module also has the ability to scan files inside an include directory, and make changes in the appropriate file. u include filesu includei u flagsu backupu pathu ^{0}.*u patternu show_changesuS Error: {0} includes a dict, and a specific setting inside the dict was not declaredu Command '%s' already has: %su {0} {1}u prepend_if_not_founduX Error: A setting for a dict was declared, but the configuration line given is not a dictu ^{0}.*?{{.*?}}i u append_if_not_foundu replu Setting file '%s' line: %su file.replaceN( R R R R R R R t formatR R1 t isinstancet dictR R2 t debugR t updatet _dict_to_stanzat __salt__( R+ R t settingR! t confR, t new_linet kwargst current_valuet error_msgR5 ( ( s: /usr/lib/python2.7/site-packages/salt/modules/logrotate.pyt set_� sV & c C@ s^ d } xE | D]= } | | t k r0 d | | <n | d j | | | � 7} q Wd j | | � S( u/ Convert a dict to a multi-line stanza u u {0} {1} u {0} {{ {1}}}( R R6 ( R+ R5 R"