o ]Lb@sddlmZddlZddlZddlZddlmZddlmZddl m Z ddl m Z m Z GdddeZGd d d eZGd d d eZGd ddeZdddZGdddeZdS))absolute_importN)hex)open)pycompat)hashutilprocutilc@ eZdZdS)BundleWriteExceptionN__name__ __module__ __qualname__rr:/usr/lib/python3/dist-packages/hgext/infinitepush/store.pyr r c@r)BundleReadExceptionNr rrrrrrrc@s2eZdZdZejZejddZejddZ dS)abstractbundlestorea6Defines the interface for bundle stores. A bundle store is an entity that stores raw bundle data. It is a simple key-value store. However, the keys are chosen by the store. The keys can be any Python object understood by the corresponding bundle index (see ``abstractbundleindex`` below). cCdS)zWrite bundle data to the store. This function receives the raw data to be written as a str. Throws BundleWriteException The key of the written data MUST be returned. Nr)selfdatarrrwrite(zabstractbundlestore.writecCr)zObtain bundle data for a key. Returns None if the bundle isn't known. Throws BundleReadException The returned object should be a file object supporting read() and close(). Nr)rkeyrrrread1rzabstractbundlestore.readN) r r r __doc__abcABCMeta __metaclass__abstractmethodrrrrrrrs rc@s8eZdZdZddZddZddZdd Zd d Zd S) filebundlestorezkbundle store in filesystem meant for storing bundles somewhere on disk and on network filesystems cCsT||_||_|dd|_|js|jjdd|_tj|js(t |jdSdS)Ns scratchbranchs storepathsscratchbranchessfilebundlestore) uirepo configpath storepathvfsjoinospathexistsmakedirs)rr r!rrr__init__Bszfilebundlestore.__init__cCs"tj|j|dd|ddS)zFirst two bytes of the hash are the name of the upper level directory, next two bytes are the name of the next level directoryr)r&r'r%r#)r hashvaluerrr_dirpathMs"zfilebundlestore._dirpathcCstj|||S)N)r&r'r%r.)rfilenamerrr _filepathSszfilebundlestore._filepathcCsrtt|}||}tj|st|t | |d}| |Wd|S1s2wY|S)Nswb) rrsha1digestr.r&r'r(r)rr0r)rrr/dirpathfrrrrVs     zfilebundlestore.writecCsVz t||d }|WdWS1swYWdSty*YdSw)Nsrb)rr0rIOError)rrr4rrrrbs( zfilebundlestore.readN) r r r rr*r.r0rrrrrrr<s  rcCsLg}|D]}|r|dkr||q|r|dkr||q||q|S)zFormats `args` with Infinitepush replacements. Hack to get `str.format()`-ed strings working in a BC way with bytes. s {filename}s{handle})append)argsr/handleformatted_argsargrrrformat_placeholders_argsjs     r;c@s,eZdZddZddZddZddZd S) externalbundlestorecCs||_||_||_||_dS)a6 `put_binary` - path to binary file which uploads bundle to external storage and prints key to stdout `put_args` - format string with additional args to `put_binary` {filename} replacement field can be used. `get_binary` - path to binary file which accepts filename and key (in that order), downloads bundle from store and saves it to file `get_args` - format string with additional args to `get_binary`. {filename} and {handle} replacement field can be used. N)put_argsget_args put_binary get_binary)rr?r=r@r>rrrr*|s  zexternalbundlestore.__init__cCs<tjttj|tjtjdd}|\}}|j}|||fS)NT)stdoutstderr close_fds) subprocessPopenrrapplyr tonativestrPIPE communicate returncode)rr7prArBrJrrr _call_binarys   z externalbundlestore._call_binarycCstK}||||dt|j|jd}||j g|\}}}|dkr1t d|| }t |dkrF|dWdSt d|j |f1sRwYdS)Nr)r/s&Failed to upload to external store: %ssBad output from %s: %s) r namedtempfilerflushseekr;r=namerLr?r splitlineslen)rrtempr9rJrArB stdout_linesrrrrs,       zexternalbundlestore.writecCsrt+}t|j|j|d}||jg|\}}}|dkr$td||WdS1s2wYdS)N)r/r8rs*Failed to download from external store: %s) rrNr;r>rQrLr@rr)rr8rTr9rJrArBrrrrs    $zexternalbundlestore.readN)r r r r*rLrrrrrrr<{s  r<)NN) __future__rrr&rDmercurial.nodermercurial.pycompatr mercurialrmercurial.utilsrr Exceptionr robjectrrr;r<rrrrs     .