![]() Server : Apache/2.4.52 (Ubuntu) System : Linux webserver 6.8.0-49-generic #49~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Nov 6 17:42:15 UTC 2 x86_64 User : www-data ( 33) PHP Version : 8.1.2-1ubuntu2.21 Disable Function : NONE Directory : /lib/python3/dist-packages/landscape/lib/__pycache__/ |
o ���c1 � @ sj d Z ddlZddlZddlmZ dd� Zdd� Zdd � Zd d� Zddd �Z ddd�Z e ZeZddd�Z dS )zFile-system utils� N)�longc C � t | |�d�� dS )z�Create a file with the given content. The content is encoded with utf-8 before writing. @param path: The path to the file. @param content: The content to be written in the file. �utf-8N)�create_binary_file�encode��path�content� r �2/usr/lib/python3/dist-packages/landscape/lib/fs.py�create_text_file s r c C �: t | d��}|�|� W d � dS 1 sw Y dS )z�Create a file with the given binary content. @param path: The path to the file. @param content: The content to be written in the file. �wbN��open�write�r r �fdr r r r s "�r c C r )a Append a file with the given content. The file is created, if it doesn't exist already. The content is utf-8 encoded before it is written. @param path: The path to the file. @param content: The content to be written in the file at the end. r N)�append_binary_filer r r r r �append_text_file s r c C r )z�Append a file with the given binary content. The file is created, if it doesn't exist already. @param path: The path to the file. @param content: The content to be written in the file at the end. �abNr r r r r r + s "�r c C sR t | |du rdn|d �}|�dd�}|du r|S |dkr#|d|� S ||d� S )a� Return the content of the given file as string. @param path: The path to the file. @param limit: An optional read limit. If positive, read up to that number of characters from the beginning of the file. If negative, read up to that number of bytes from the end of the file. @return content: The content of the file string, possibly trimmed to C{limit} characters. N� r �replacer )�read_binary_file�decode)r �limitr r r r �read_text_file7 s r c C s� t | d��1}|dur+tj�| �t|�kr+|dkr$|�|�W d � S |�|tj� |�� W d � S 1 s9w Y dS )a� Return the content of the given file as bytes. @param path: The path to the file. @param limit: An optional read limit. If positive, read up to that number of bytes from the beginning of the file. If negative, read up to that number of bytes from the end of the file. @return content: The content of the file as bytes, possibly trimmed to C{limit}. �rbNr )r �osr �getsize�abs�read�seek�SEEK_END)r r r r r r r R s �$�r c C sD t | d��� |durtt�� �| }||f}nd}t�| |� dS )z�Touch a file, creating it if it doesn't exist. @param path: the path to the file to be touched. @param offset_seconds: a signed integer number of seconds to offset the atime and mtime of the file from the current time. r N)r �closer �timer �utime)r �offset_seconds�offset_time� touch_timer r r � touch_filej s r* )N)�__doc__r r% �twisted.python.compatr r r r r r r � read_file�create_filer* r r r r �<module> s