Your IP : 172.28.240.42


Current Path : /usr/share/python/debpython/
Upload File :
Current File : //usr/share/python/debpython/tools.pyc


JQc@sddlmZddlZddlZddlZddlZddlmZddlmZddl	m
Z
mZmZm
Z
ddlmZddlmZmZddlmZmZmZejeZejd	Zejd
ZejdZejdeejZejd
eejZ de"dZ#dZ$dZ%dZ&dZ'dZ(de)fdYZ*dZ+dZ,dS(i(twith_statementN(tdumps(tglob(texiststisdirtjointsplit(trmtree(tPIPEtPopen(t
RANGE_PATTERNtgetvertget_requested_versionss/(.*?)(-py\d\.\d(?:-[^.]*)?)?(\.egg-info|\.pth)$s8^#!\s*/usr/bin/(?:env\s+)?(python(\d+\.\d+)?(?:-dbg)?).*sNEEDED.*libpython(\d\.\d)s
    (?P<pattern>.+?)  # file pattern
    (?:\s+  # optional Python module name:
    (?P<module>[A-Za-z][A-Za-z0-9_.]*)?
    )?
    \s*  # optional version range:
    (?P<vrange>%s)?$
s^
    (?P<pattern>.+?)  # file pattern
    \s*  # optional version range:
    (?P<vrange>%s)?$
cCst|tr1td|jdD}n|d	krJd|}n
d|}|rgd|}n|rd||f}n|S(
sReturn path to site-packages directory.

    >>> sitedir((2, 5))
    '/usr/lib/python2.5/site-packages/'
    >>> sitedir((2, 7), 'python-foo', True)
    'debian/python-foo/usr/lib/debug/usr/lib/python2.7/dist-packages/'
    css|]}t|VqdS(N(tint(t.0ti((s$/usr/share/python/debpython/tools.pys	<genexpr>>st.iis#/usr/lib/python%d.%d/dist-packages/s#/usr/lib/python%d.%d/site-packages/s/usr/lib/debug%ssdebian/%s%s(ii(t
isinstancet
basestringttupleR(tversiontpackagetgdbtpath((s$/usr/share/python/debpython/tools.pytsitedir5s"


cCsi|jd}|jd}x&|d|dkrF|d=|d=q!Wdjdgt|d|S(s~Return relative path.

    >>> relpath('/usr/share/python-foo/foo.py', '/usr/bin/foo', )
    '../share/python-foo/foo.py'
    t/is..i(RRtlen(ttargettlinktttl((s$/usr/share/python/debpython/tools.pytrelpathMs
cCstjt|||S(sCreate relative symlink.(tostsymlinkR(RR((s$/usr/share/python/debpython/tools.pytrelative_symlinkZscCsyt|r}|jd}tj|}|s:dS|j}|dkr}|dry|dt|df}n|SWdQXWn!tk
rtj	d|nXdS(spCheck file's shebang.

    :rtype: tuple
    :returns: pair of Python interpreter string and Python version
    i iiNscannot open %s(NN(
topentreadt
SHEBANG_REtmatchtNonetgroupsRtIOErrortlogterror(tfpathtfptdataR&tres((s$/usr/share/python/debpython/tools.pyt
shebang2pyver_s

cCsXd|}t|dtdt}tj|jj}|rTt|jdSdS(shReturn libpython version file is linked to or None.

    :rtype: tuple
    :returns: Python version
    sreadelf -Wd '%s'tstdouttshelliN(	R	RtTruetSHAREDLIB_REtsearchR1R$RR((R,tcmdtprocessR&((s$/usr/share/python/debpython/tools.pytso2pyverts

cCsGtj|}|rC|jddk	rCdj|jddS|S(sRemove Python version and platform name from Egg files/dirs.

    >>> clean_egg_name('python_pipeline-0.1.3_py3k-py3.1.egg-info')
    'python_pipeline-0.1.3_py3k.egg-info'
    >>> clean_egg_name('Foo-1.2-py2.7-linux-x86_64.egg-info')
    'Foo-1.2.egg-info'
    itiiN(t
EGGnPTH_RER&tgroupR'R(tnameR&((s$/usr/share/python/debpython/tools.pytclean_egg_namestmemoizecBseZdZdZRS(cCs||_i|_dS(N(tfunctcache(tselfR?((s$/usr/share/python/debpython/tools.pyt__init__s	cOsHt||f}||jkr=|j|||j|<n|j|S(N(RR@R?(RAtargstkwargstkey((s$/usr/share/python/debpython/tools.pyt__call__s(t__name__t
__module__RBRF(((s$/usr/share/python/debpython/tools.pyR>s	c	Cst}d|}t|s |St|}xtj|ddD]m}|sB|jdrdqBntj|}|st}t	j
d||qBn|j}|dr|djdd|d<n|t|d	@}|st	j
d
||qBnt|d}|s7t}t	jd||dqBnxu|D]m}	|	jd
}	|dr}t|dt|	d}
n"|	jdr|	d}
n|	}
x	|D]}tt|||
}t|d}
t|
sytj|
Wqtk
rt	jd|
tSXnt|rfytj|Wqftk
rbt}t	jd|qqfXnytj|	|Wqtk
rt}t	jd|	|
qXqWq>WqBW|S(sDInstall local files listed in pkg.pyinstall files as public modules.s./debian/%s.pyinstalltencodingsutf-8t#s#%s.pyinstall: unrecognized line: %stmoduleRRtvranges.%s.pyinstall: no matching versions for line %stpatterns %s.pyinstall: file not found: %ss/.isdebian/iiscannot create %s directoryscannot replace %s filescannot copy %s file to %s(R3RRtcodecsR#t
startswitht
INSTALL_RER&tFalseR*twarnt	groupdicttreplacetdebugRR+tlstripRRRR tmakedirst	ExceptiontremoveR(RRLtstatustsrcfpathtversionstlinetdetailstmyverstfilesR,tdstnameRtdstfpathtdstdir((s$/usr/share/python/debpython/tools.pyt	pyinstallsr
	

	
	

 





#c
Cst}d|}t|s |St|}xtj|ddD]}|sB|jdrdqBntj|}|st}t	j
d||qBn|j}|t|d@}|st	jd||qBnx|D]}t
t|||d}	|	s't	jd	|||dqnx|	D]}
t|
rzyt|
Wqtk
rv}t}t	j|qXq.ytj|
Wq.ttfk
r}t}t	j|q.Xq.WqWqBW|S(
s2Remove public modules listed in pkg.pyremove file.s./debian/%s.pyremoveRIsutf-8RJs"%s.pyremove: unrecognized line: %sRLs-%s.pyremove: no matching versions for line %sRMs/%s.pyremove: nothing to remove: python%d.%d, %s(R3RRRNR#ROt	REMOVE_RER&RQR*RRRSRURRRRRXR+R RYR)tOSError(RRLRZR[R\R]R^R_RR`R,te((s$/usr/share/python/debpython/tools.pytpyremovesN
	
	

	
(-t
__future__RRNtloggingR tretcPickleRRtos.pathRRRRtshutilRt
subprocessRR	tdebpython.versionR
RRt	getLoggerRGR*tcompileR:R%R4tVERBOSERPReR'RQRRR"R0R8R=tobjectR>RdRh(((s$/usr/share/python/debpython/tools.pyt<module>s6"	
					?