
    ed                     .    d Z ddlZdZdZddgZd Zd	dZy)
z System utility functions     NzDatabio Labznathan@code.databio.orgis_command_callableis_writablec                    t        | t              s$t        dj                  | t	        |                   | st        d      t        j                  j                  |       sCt        j                  j                  |       r%t        j                  | t        j                        sydj                  |       }t        t        j                  |             S )a  
    Check if command can be called.

    :param str cmd: actual command to check for callability
    :return bool: whether given command's call succeeded
    :raise TypeError: if the alleged command isn't a string
    :raise ValueError: if the alleged command is empty
    z'Alleged command isn't a string: {} ({})z&Empty command to check for callabilityFz/command -v {0} >/dev/null 2>&1 || {{ exit 1; }})
isinstancestr	TypeErrorformattype
ValueErrorospathisdirisfileaccessX_OKboolsystem)cmdchecks     /lib/python3.12/site-packages/ubiquerg/system.pyr   r      s     c35<<S$s)L
 	
 ABB	ww}}SbggnnS1"))C:Q=DDSIEBIIe$%%%    c                    | xs d} t         j                  j                  |       rJt        j                  | t         j                        xr$ t        j                  | t         j
                        S |rt        j                  |        y|rt        dj                  |             t        t         j                  j                  |       |      S )a  
    Make sure a folder is writable.

    Given a folder, check that it exists and is writable. Errors if requested on
    a non-existent folder. Otherwise, make sure the first existing parent folder
    is writable such that this folder could be created.

    :param str folder: Folder to check for writeability.
    :param bool check_exist: Throw an error if it doesn't exist?
    :param bool create: Create the folder if it doesn't exist?
    .zFolder not found: {}N)r   r   existsr   W_OKr   mkdirOSErrorr	   r   dirname)foldercheck_existcreates      r   r   r   !   s     ]sF	ww~~fyy)Hbii.HH	
	,33F;<< 277??62K@@r   )FF)__doc__r   
__author__	__email____all__r   r    r   r   <module>r'      s*      	
%	 -
0&,Ar   