Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/dist-packages/DistUpgrade/
Upload File :
Current File : //usr/lib/python2.7/dist-packages/DistUpgrade/utils.pyc


RSc@s@ddlmZddlmZddlmZmZmZddlmZddl	Z	e	j
ddlZddlZddl
Z
ddlZddlZddlZddlZddlZddlZddlZddlZddlmZddlmZdefd	YZd
ZdZdZdd
ZdZdddZ dZ!dZ"dZ#dZ$dZ%dej&fdYZ'ddZ(ddZ)dZ*dZ+dZ,dZ-dZ.d Z/d!Z0d"Z1d#Z2d$Z3d%Z4d&Z5e6d'kr<e5GHndS((i(tgettext(tngettext(tS_IMODEtST_MODEtS_IXUSR(tceilN(tcopy(turlsplitt
ExecutionTimecBs,eZdZddZdZdZRS(s
    Helper that can be used in with statements to have a simple
    measure of the timing of a particular block of code, e.g.
    with ExecutionTime("db flush"):
        db.flush()
    tcCs
||_dS(N(tinfo(tselfR
((s5/usr/lib/python2.7/dist-packages/DistUpgrade/utils.pyt__init__5scCstj|_dS(N(ttimetnow(R((s5/usr/lib/python2.7/dist-packages/DistUpgrade/utils.pyt	__enter__7scCs#d|jtj|jfGHdS(Ns%s: %s(R
R
R(Rttypetvaluetstack((s5/usr/lib/python2.7/dist-packages/DistUpgrade/utils.pyt__exit__9s(t__name__t
__module__t__doc__RRR(((s5/usr/lib/python2.7/dist-packages/DistUpgrade/utils.pyR.s	cCsst|}t|j}|jrB|jj|jd|_n|jri|jj|jd|_nt|S(Nshidden-ushidden-p(RRturitusernametreplacetpasswordtstr(tentryttmpt	url_parts((s5/usr/lib/python2.7/dist-packages/DistUpgrade/utils.pyt)get_string_with_no_auth_from_source_entry<s		cCsNd}tjd}x1tjd|D]}|tjj|7}q*W|S(sE estimate the amount of space that the current kernel takes in /boot iis
/boot/*%s*(tostunametglobtpathtgetsize(tsizetkvertf((s5/usr/lib/python2.7/dist-packages/DistUpgrade/utils.pytestimate_kernel_size_in_bootEs
cCsLt}y+ddl}|j}|jd}WntjdnX|S(s+ return True if Unity is currently running iNscom.canonical.Unitys&could not check for Unity dbus service(tFalsetdbust
SessionBustname_has_ownertloggingt	exception(t
unity_runningR*tbus((s5/usr/lib/python2.7/dist-packages/DistUpgrade/utils.pytis_unity_runningMscCs|stj}nx|dkrd|}t|j}|jddjdd}||krptSt|jddjd}qWtS(Nis
/proc/%s/statt(it)i(	R tgetpidtopentreadt	partitiontTruetinttsplitR)(tprocessnametpidt	stat_filetstattcommand((s5/usr/lib/python2.7/dist-packages/DistUpgrade/utils.pytis_child_of_process_nameXs
 'cCsFtjjds&tjjdr*tStjdtjdkS(s- returns True if we are inside a chroot 
    s/procs/proc/1t/s/proc/1/root(R R#texistsR8R>(((s5/usr/lib/python2.7/dist-packages/DistUpgrade/utils.pyt
inside_chrootfs&iFR	cCsid}x\|jD]N}t||jdt||krS|d|7}n||d7}qW|S(s helpers inspired after textwrap - unfortunately
        we can not use textwrap directly because it break
        packagenames with "-" in them into new lines
    R	s
t (R:tlentrfind(tttwidthtsubsequent_indenttoutts((s5/usr/lib/python2.7/dist-packages/DistUpgrade/utils.pytwrapos)cKsGd}|jd}x+|D]#}t||}||d7}qW|S(NR	s
(R:RL(RKtkwargstmsgtparastpar((s5/usr/lib/python2.7/dist-packages/DistUpgrade/utils.pyttwrap{s
cCsg}tjjdsgStjdgdtj}|jdjd}|d=x.|D]&}|r^|j|jdq^q^W|S(s= return list of loaded modules (or [] if lsmod is not found) s/sbin/lsmodtstdoutis
(	R R#RBt
subprocesstPopentPIPEtcommunicateR:tappend(tmodulestptlinestline((s5/usr/lib/python2.7/dist-packages/DistUpgrade/utils.pytlsmods
cCsZtjj|sdSttj|t}|t@tksVtj||tBndS(sB check if a given binary has the executable bit and if not, add itN(R R#RBRR>RRtchmod(R#tmode((s5/usr/lib/python2.7/dist-packages/DistUpgrade/utils.pytcheck_and_fix_xbits
cCsidd6}dtjkr dStjdj}|d |krO||d Sd|kr|jddjdd}d	|kr|jd	d}n|dS|d
 dSdS(s: helper to get the country mirror from the current locale R	tctLANGit_t.iit@i(R tenvirontlowerR:(tlang_mirrortlangtcountry((s5/usr/lib/python2.7/dist-packages/DistUpgrade/utils.pytcountry_mirrors
 cCstjjd}|r-tjd||Sddlm}m}|dddgd|}|j}|d	krt	j
jd
|dS|jj
j}|S(s2 return the codename of the current runing distro tMETA_RELEASE_FAKE_CODENAMEsQusing fake release name '%s' (because of META_RELEASE_FAKE_CODENAME environment) i(RTRUtlsb_releases-cs-sRRis"lsb_release returned exitcode: %i
sunknown distribution(R RetgetR-twarnRSRTRUtwaittsyststderrtwriteRRtreadlinetstrip(tdistRTRURYtres((s5/usr/lib/python2.7/dist-packages/DistUpgrade/utils.pytget_diststHeadRequestcBseZdZRS(cCsdS(NtHEAD((R((s5/usr/lib/python2.7/dist-packages/DistUpgrade/utils.pyt
get_methods(RRRz(((s5/usr/lib/python2.7/dist-packages/DistUpgrade/utils.pyRxscCs|sdn|d|tj|\}}}}}|d|||||f|dkry:tjt|}|j|jdkrtStSWqt	k
r}|d|tSXn|dkrdd	l
}	y|	j|}
|
j|
j
tjj||
jtjj|}|
j|rP|d
|n|dkr`tSWqt	k
r}|r|d|ntSXntS(
s
  helper that checks if the given uri exists and is downloadable
  (supports optional debug_func function handler to support 
   e.g. logging)

  Supports http (via HEAD) and ftp (via size request)
  cSstS(N(R8(tx((s5/usr/lib/python2.7/dist-packages/DistUpgrade/utils.pyt<lambda>ssurl_downloadable: %ss"s='%s' n='%s' p='%s' q='%s' f='%s'thttpiserror from httplib: '%s'tftpiNsftplib.size() returned: %siserror from ftplib: '%s'(turlparseRturllib2turlopenRxtclosetcodeR8R)t	ExceptiontftplibtFTPtlogintcwdR R#tdirnameR%tbasenametquit(Rt
debug_functschemetnetlocR#tquerrytfragmentt	http_fileteRR'R%((s5/usr/lib/python2.7/dist-packages/DistUpgrade/utils.pyturl_downloadables@



c	Cs>d}d
}tjjddkr9tjjd}ntjj|rtj}tj|||j	dt
}|r|jd}t|jd}|r|rd||f}qqn|r:t
jd|stjd	|IJd
Stji|d6}tj|}tj|tjd|n|S(
s init proxy settings 

  * first check for http_proxy environment (always wins),
  * then check the apt.conf http proxy, 
  * then look into synaptics conffile
  * then into gconf  (if gconfclient was supplied)
  s/root/.synaptic/synaptic.confsAcquire::http::ProxyR	sSynaptic::useProxysSynaptic::httpProxysSynaptic::httpProxyPorts
http://%s:%s/s
http://\w+sproxy '%s' looks invalidNR}t
http_proxy(tNonetapt_pkgtconfigtfindR R#RBt
Configurationtread_config_filetfind_bR)Rtfind_itretmatchRpRqRtProxyHandlertbuild_openertinstall_openertputenv(	t	gsettingstSYNAPTIC_CONF_FILEtproxytcnft	use_proxyt
proxy_hostt
proxy_portt
proxy_supporttopener((s5/usr/lib/python2.7/dist-packages/DistUpgrade/utils.pyt
init_proxys,
cCsyddl}|j|jj}y8|jdd}|j|d}|jddSWn_|jjk
r}|jdkrn|jdd	}|j|d}|jdd
SXWnt	k
r}t
SXdS(s
  Check via dbus if the system is running on battery.
  This function is using UPower per default, if UPower is not
  available it falls-back to DeviceKit.Power. 
  iNsorg.freedesktop.UPowers/org/freedesktop/UPowersorg.freedesktop.DBus.Propertiest	OnBatterys)org.freedesktop.DBus.Error.ServiceUnknownsorg.freedesktop.DeviceKit.Powers /org/freedesktop/DeviceKit/Powert
on_battery(R*tBustTYPE_SYSTEMt
get_objectt	InterfacetGett
exceptionst
DBusExceptiont_dbus_error_nameRR)(R*R0tdevobjtdevR((s5/usr/lib/python2.7/dist-packages/DistUpgrade/utils.pyR"s"				cCsyeddl}|j|jj}|jdd}|j|d}|jdd}||fSWntk
rttfSXdS(sm
  Send a dbus signal to power-manager to not suspend
  the system, using the freedesktop common interface
  iNsorg.freedesktop.PowerManagements(/org/freedesktop/PowerManagement/Inhibits'org.freedesktop.PowerManagement.Inhibitt
UpdateManagersUpdating system(R*RtTYPE_SESSIONRRtInhibitRR)(R*R0RRtcookie((s5/usr/lib/python2.7/dist-packages/DistUpgrade/utils.pyt
inhibit_sleep<s		
cCs4y|j|Wntk
r/}d|GHnXdS(sLSend a dbus signal to gnome-power-manager to allow a suspending
  the systems,could not send the dbus UnInhibit signal: %sN(t	UnInhibitR(RRR((s5/usr/lib/python2.7/dist-packages/DistUpgrade/utils.pytallow_sleepMscCs&|dks|jdkr"tStS(Nt0tFALSE(tupperR)R8(R((s5/usr/lib/python2.7/dist-packages/DistUpgrade/utils.pytstr_to_boolVscCst|djdS(Ntlatin1sutf-8(tunicodetencode(R((s5/usr/lib/python2.7/dist-packages/DistUpgrade/utils.pytutf8[scCsLddl}ytj\}}|SWntk
rG|jddSXdS(Nisgedefaultlocale() failed(R-tlocaletgetdefaultlocaleRR.R(R-tlocale_stencoding((s5/usr/lib/python2.7/dist-packages/DistUpgrade/utils.pytget_lang^s

cCsqtjjdd}d|kr%dSd|kr5dSd|ksMd|krQdSd	|ksid
|krmdSdS(s6 try to guess the flavor based on the running desktop tDESKTOP_SESSIONR	tgnometubuntutkdetkubuntutxfcetxubuntutLXDEtLubuntutlubuntu(R ReRm(tdenv((s5/usr/lib/python2.7/dist-packages/DistUpgrade/utils.pytget_ubuntu_flavorgsc	Csddlm}m}|jd|d|jjd|jjd|jj	}|j
d||f|j|jj
|jj|jd|j|jtS(	Ni(tGtktGdktparenttflagsRtbuttonss<big><b>%s</b></big>

%sR	(t
gi.repositoryRRt
MessageDialogtDialogFlagstMODALtMessageTypetERRORtButtonsTypetCLOSEt
set_markuptrealizet
get_windowt
set_functionst
WMFunctiontMOVEt	set_titletruntdestroyR)(RtsummarytmessageRRtd((s5/usr/lib/python2.7/dist-packages/DistUpgrade/utils.pyterrorxs



cCse|dkrCtt|td}tdd|i|d6Stjtd|ddSdS(sG
    Convert a given size in bytes to a nicer better readable unit
    is
%(size).0f kBR%s%.1f MBg@@Ni@B(R9RtfloatRRt
format_stringRb(tbytest
size_in_kb((s5/usr/lib/python2.7/dist-packages/DistUpgrade/utils.pyt
humanize_sizescCstjjdS(NsAPT::Architecture(RtConfigR(((s5/usr/lib/python2.7/dist-packages/DistUpgrade/utils.pytget_archsc	Csd}d}d}xtdD]|}|j}|s=qn|j}||}||kreqn||jdd}t|d}||krtSqWtS(s@ check if the current system is listening on the given tcp port iit0As
/proc/net/tcpt:i(R5RtR:R9R8R)(	tporttINDEX_LOCAL_ADDRtINDEX_STATEtSTATE_LISTENINGR[tvalueststatetlocal_port_strt
local_port((s5/usr/lib/python2.7/dist-packages/DistUpgrade/utils.pytis_port_already_listenings 
cCsvd}tjdkr$tdntjjds:tStjddgdtjj	d}||krrtSt
S(s# Return True if iptables is active sChain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         
is%Need root to check the iptables states/sbin/iptablestiptabless-LRR(R tgetuidtOSErrorR#RBR)RSRTRURVR8(tiptables_emptyRJ((s5/usr/lib/python2.7/dist-packages/DistUpgrade/utils.pytiptables_activest__main__(7RRbRR>RRRtmathRRtinit_configRR-RR tos.pathR"RSRpR
RRRRtobjectRRR(R1RR@RCRLRQR\R_RjRwtRequestRxRRRRRRRRRRRRRR	R(((s5/usr/lib/python2.7/dist-packages/DistUpgrade/utils.pyt<module>s^
											)3