B
    d*                 @   sZ   d dl Z d dlmZmZ d dlmZ d dlmZmZm	Z	 dgZ
e eZG dd dZdS )    N)DEFAULTSECTConfigParser)StringIO)OptionalTextIOUnion
Propertiesc               @   s   e Zd ZdZdZdeZedeZ	e
dee dddZdd Zdd Zdd Zdd ZeedddZe
dd Zdeeeef  dddZdS )r   zWrite Pegasus properties to a file.

    .. code-block:: python

        # Example
        props = Properties()
        props["globus.maxtime"] = 900
        props["globus.maxwalltime"] = 1000
        props["dagman.retry"] = 4

        props.write()

    )z*pegasus.file.cleanup.constraint.*.maxspacezpegasus.log.*zpegasus.metrics.app.*zpegasus.transfer.*.remote.siteszpegasus.transfer.*.implzpegasus.selector.site.env.*zpegasus.selector.regex.rank.*z/pegasus.selector.replica.*.prefer.stagein.sitesz/pegasus.selector.replica.*.ignore.stagein.sitesz pegasus.catalog.replica.output.*zpegasus.catalog.*.timeoutzpegasus.catalog.replica.db.*zenv.*zdagman.*zcondor.*zglobus.*pegasus.modepegasus.home.datadirpegasus.home.sysconfdirpegasus.home.sharedstatedirpegasus.home.localstatedirpegasus.dir.submit.logspegasus.dir.useTimestamppegasus.dir.execpegasus.dir.submit.mapperpegasus.dir.staging.mapperpegasus.dir.storage.mapperpegasus.dir.storage.deeppegasus.dir.create.strategypegasus.schema.daxpegasus.schema.scpegasus.schema.ivrpegasus.catalog.replicapegasus.catalog.replica.file"pegasus.catalog.replica.chunk.size"pegasus.catalog.replica.cache.asrc pegasus.catalog.replica.dax.asrcpegasus.catalog.sitepegasus.catalog.site.filepegasus.catalog.transformation#pegasus.catalog.transformation.filepegasus.selector.replicapegasus.selector.sitepegasus.selector.site.pathpegasus.selector.site.timeoutpegasus.selector.site.keep.tmppegasus.data.configuration%pegasus.transfer.bypass.input.stagingpegasus.transfer.argumentspegasus.transfer.threadspegasus.transfer.lite.argumentspegasus.transfer.worker.package,pegasus.transfer.worker.package.autodownload&pegasus.transfer.worker.package.strictpegasus.transfer.links"pegasus.transfer.staging.delimiter$pegasus.transfer.disable.chmod.sites&pegasus.transfer.setup.source.base.urlpegasus.monitord.eventspegasus.catalog.workflow.url$pegasus.catalog.workflow.amqp.events!pegasus.catalog.workflow.amqp.urlpegasus.catalog.master.urlpegasus.monitord.outputpegasus.dashboard.outputpegasus.monitord.notifications"pegasus.monitord.notifications.max&pegasus.monitord.notifications.timeout'pegasus.monitord.stdout.disable.parsingpegasus.monitord.encodingpegasus.monitord.arguments pegasus.clusterer.job.aggregator*pegasus.clusterer.job.aggregator.arguments,pegasus.clusterer.job.aggregator.seqexec.log5pegasus.clusterer.job.aggregator.seqexec.firstjobfailpegasus.clusterer.allow.singlepegasus.clusterer.label.keypegasus.clusterer.preferencepegasus.log.managerpegasus.log.manager.formatterpegasus.log.memory.usagepegasus.metrics.apppegasus.file.cleanup.strategypegasus.file.cleanup.impl!pegasus.file.cleanup.clusters.num"pegasus.file.cleanup.clusters.sizepegasus.file.cleanup.scope-pegasus.file.cleanup.constraint.deferstageins#pegasus.file.cleanup.constraint.csvpegasus.aws.accountpegasus.aws.region pegasus.aws.batch.job_definition%pegasus.aws.batch.compute_environmentpegasus.aws.batch.job_queuepegasus.aws.batch.s3_bucketpegasus.code.generator!pegasus.condor.concurrency.limitspegasus.registerpegasus.register.deeppegasus.data.reuse.scope%pegasus.catalog.transformation.mapperpegasus.selector.transformation'pegasus.parser.dax.preserver.linebreaks$pegasus.parser.dax.data.dependenciespegasus.integrity.checkingenv.PEGASUS_HOMEenv.GLOBUS_LOCATIONenv.LD_LIBRARY_PATHglobus.countglobus.jobtypeglobus.maxcputimeglobus.maxmemoryglobus.maxtimeglobus.maxwalltimeglobus.minmemoryglobus.projectglobus.queuecondor.universecondor.periodic_releasecondor.periodic_removecondor.filesystemdomaincondor.stream_errorcondor.stream_outputcondor.prioritycondor.request_cpuscondor.request_gpuscondor.request_memorycondor.request_disk
dagman.predagman.pre.argumentsdagman.postdagman.post.pathdagman.post.argumentsdagman.retrydagman.categorydagman.prioritydagman.abort-dag-ondagman.maxpredagman.maxpostdagman.maxjobsdagman.maxidledagman.post.scopepegasus.cluster.numpegasus.clusters.sizepegasus.job.aggregatorpegasus.gridstartpegasus.gridstart.pathpegasus.gridstart.argumentspegasus.gridstart.launcher$pegasus.gridstart.launcher.argumentspegasus.stagein.clusterspegasus.stagein.local.clusterspegasus.stagein.remote.clusterspegasus.stageout.clusterspegasus.stageout.local.clusters pegasus.stageout.remote.clusterspegasus.grouppegasus.change.dirpegasus.create.dirpegasus.transfer.proxypegasus.stylepegasus.pmc_request_memorypegasus.pmc_request_cpuspegasus.pmc_prioritypegasus.pmc_task_argumentspegasus.exitcode.failuremsgpegasus.exitcode.successmsgpegasus.checkpoint.timepegasus.maxwalltimepegasus.glite.argumentspegasus.condor.arguments.quotepegasus.runtimepegasus.clusters.maxruntimepegasus.corespegasus.nodespegasus.ppnpegasus.memorypegasus.diskspaceselector.execution.siteselector.pfnselector.grid.jobtype#pegasus.catalog.replica.db.passwordpegasus.catalog.replica.db.userpegasus.catalog.replica.db.url!pegasus.catalog.replica.db.driverz[{}]
N)propc             C   s\   | rDt  }x tjD ]}| |kr|| qW |  t|ddi ntttjddi dS )a  List property keys. Refer to
        `Configuration docs <https://pegasus.isi.edu/documentation/configuration.php>`_
        for additional information. If :code:`prop` is given, all properties
        containing prop will be printed, else all properties will be printed.

        .. code-block:: python

            # Example
            >>> P.ls("request")
            condor.request_cpus
            condor.request_disk
            condor.request_gpus
            condor.request_memory
            pegasus.pmc_request_cpus
            pegasus.pmc_request_memory

        :param prop: properties containing "prop" will be listed in alphabetical order, defaults to None
        :type prop: Optional[str]
        sep
N)listr   _propsappendsortprintsorted)r   Zto_printp r   c/work/yifan.wang/ringdown/master-ringdown-env/lib/python3.7/site-packages/Pegasus/api/properties.pyls   s    zProperties.lsc             C   s   t  | _t| j_i | jt< d S )N)r   _confstroptionxformr   )selfr   r   r   __init__   s    zProperties.__init__c             C   s:   |  || jt |< | |s6td||  | d S )Nz4Unrecognized property key: '{}' has been set to '{}')_escaper   r   
_check_keylogwarningformat)r   kvr   r   r   __setitem__  s
    
zProperties.__setitem__c             C   s   | j t | S )N)r   r   )r   r   r   r   r   __getitem__  s    zProperties.__getitem__c             C   s   | j t| d S )N)r   remove_optionr   )r   r   r   r   r   __delitem__  s    zProperties.__delitem__)returnc             C   sd   d}|| j krd}nLxJ| jD ]@}|d}||d r||d rt|t|krd}P qW |S )z7Check if the key :code:`k` is a valid Pegasus property.FT*r      )r   _pattern_propssplit
startswithendswithlen)clsr   rvr   _r   r   r   r     s    

,zProperties._check_keyc             C   s   t | tr| S t| S dS )zEscape value :code:`v`.N)
isinstancer   )r   r   r   r   r   #  s    
zProperties._escape)filec          	   C   s   t  $}| j| | tjd }W dQ R X |dkr<d}t|trht|d}|| W dQ R X n$t	|dr~|| nt
d|dS )a  Write these properties to a file. If :code:`file` is not given, these
        properties are written to :code:`./pegasus.properties`

        .. code-block:: python

            # Example 1
            props.write()

            # Example 2
            with open("conf", "w") as f:
                props.write(f)

        :param file: file path or file object where properties will be written to, defaults to None
        :type file: Optional[Union[str, TextIO]]
        :raises TypeError: file must be of type str or file like object
        Nzpegasus.propertieswreadz>invalid file: {}; file must be of type str or file like object)r   r   writegetvaluer   _cfg_header_lenr   r   openhasattr	TypeErrorr   )r   r   siopropsfr   r   r   r   +  s    

zProperties.write)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!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   rd   re   rf   rg   rh   ri   rj   rk   rl   rm   rn   ro   rp   rq   rr   rs   rt   ru   rv   rw   rx   ry   rz   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   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   r   r   r   r   r   )N)N)__name__
__module____qualname____doc__r   r   r   r   r   r   staticmethodr   r   r   r   r   r   r   classmethodboolr   r   r   r   r   r   r   r   r   r      sn                                                                                                                                                                          
)loggingconfigparserr   r   ior   typingr   r   r   __all__	getLoggerr   r   r   r   r   r   r   <module>   s   
