Files
controller-wisetopdataserver/python/biopro/exp_pro/__pycache__/manager.cpython-37.opt-2.pyc
T

235 lines
39 KiB
Plaintext
Raw Normal View History

2021-12-20 14:52:55 +08:00
B
2021-12-22 14:29:56 +08:00
ñ0Àaõ¬ã@sPddlZddlmZddlmZddlmZmZddlm Z m
2021-12-20 14:52:55 +08:00
Z
m Z ddl m
Z
ddlmZddlmZdd lTdd
lmZmZmZdd lTdd lTdd lmZdd lmZmZdd
lmZm Z m!Z!ddl"m#Z#dd l$TdZ%dZ&dZ'Gddde(j)dZ*Gddde+ƒZ,Gdddee*eƒZ-GdddƒZ.Gddde/ƒZ0Gdddee1ƒZ2dS) éN)ÚPath)ÚIterable)ÚDeviceResponseInfoÚDeviceSerialNumber)ÚCompletedDeviceÚDeviceConfigurationÚDeviceLibraryRepository)Ú
DeviceLock)Úpath_start_with)ÚControlServerAPI)Ú*)Ú str_addressÚ address_strÚ
2021-12-22 14:29:56 +08:00
EMPTY_ADDRESS)ÚGREEN)Ú synchronizedÚ Synchronized)Ú
2021-12-20 14:52:55 +08:00
LoggerFlagÚlogging_verboseÚ logging_info)Ú part_suffixéF)zbiopro.exp_proÚtypingÚ)ÚsysÚosÚpathlibZbioprobuiltinsc@s,eZdZdZeejeedœddƒƒZ ejee
dœddƒZ eje e
dœdd „ƒZ
eje e ed
œd d ƒZejeedœd
dƒZejeedœddƒZejeeefeedœddƒZejdEeeefe eedœddƒZejdFeeefee dœddƒZejeedœddƒZejeedœddƒZejeedœdd „ƒZejeedœd!d"„ƒZejeedœd#d$„ƒZejdGeedœd&d'„ƒZejeeefe dœd(d)„ƒZ!ejeeefe dœd*d+„ƒZ"ejeeefe dœd,d-„ƒZ#ejeeefe dœd.d/„ƒZ$ejeeefe dœd0d1„ƒZ%ejeeefe dœd2d3„ƒZ&ejeeefee'dœd4d5„ƒZ(ejeeefedœd6d7„ƒZ)ejeeefe dœd8d9„ƒZ*ejeeefd:œd;d<„ƒZ+ejeeefd:œd=d>„ƒZ,ejeeefd:œd?d@„ƒZ-ejeeefd:œdAdB„ƒZ.ejdCdD„ƒZ/dS)HÚ
ExpManagerApi©)ÚreturncCsdS)Nr)Úselfrrú;/home/pi/wisetopdataserver/python/biopro/exp_pro/manager.pyÚ
protocol_root)szExpManagerApi.protocol_rootcCsdS)Nr)r rrr!Úlist_available_protocol/sz%ExpManagerApi.list_available_protocol)ÚnamercCsdS)Nr)r r$rrr!Úget_protocol_info4szExpManagerApi.get_protocol_info)Ú
protocol_nameÚ user_namercCsdS)Nr)r r&r'rrr!Úcreate_protocol9szExpManagerApi.create_protocolcCsdS)Nr)r rrr!Ú
list_protocolCszExpManagerApi.list_protocol)ÚprotocolrcCsdS)Nr)r r*rrr!Ú get_protocolKszExpManagerApi.get_protocolcCsdS)Nr)r r*rrr!Úprotocol_optionsUs zExpManagerApi.protocol_optionsN)r*ÚoptionÚvaluercCsdS)Nr)r r*r-r.rrr!Úprotocol_option`s zExpManagerApi.protocol_option)r*ÚoptionscCsdS)Nr)r r*r0rrr!Úprotocol_resetmszExpManagerApi.protocol_resetcCsdS)Nr)r rrr!Úget_configuring_protocolvsz&ExpManagerApi.get_configuring_protocolcCsdS)Nr)r rrr!Úget_pending_protocol~sz"ExpManagerApi.get_pending_protocolcCsdS)Nr)r rrr!Úget_running_protocol†sz"ExpManagerApi.get_running_protocolcCsdS)Nr)r rrr!Úget_completed_protocolŽsz$ExpManagerApi.get_completed_protocolcCsdS)Nr)r rrr!Úget_interrupted_protocolsz&ExpManagerApi.get_interrupted_protocolFcCsdS)Nr)r Ú
only_errorrrr!Úget_terminated_protocolžsz%ExpManagerApi.get_terminated_protocolcCsdS)Nr)r r*rrr!Úis_protocol_configuring§sz%ExpManagerApi.is_protocol_configuringcCsdS)Nr)r r*rrr!Úis_protocol_pending°sz!ExpManagerApi.is_protocol_pendingcCsdS)Nr)r r*rrr!Úis_protocol_running¹sz!ExpManagerApi.is_protocol_runningcCsdS)Nr)r r*rrr!Úis_protocol_suspendÂsz!ExpManagerApi.is_protocol_suspendcCsdS)Nr)r r*rrr!Úis_protocol_completedËsz#ExpManagerApi.is_protocol_completedcCsdS)Nr)r r*rrr!Úis_protocol_interruptedÔsz%ExpManagerApi.is_protocol_interruptedcCsdS)Nr)r r*rrr!Úprotocol_statusÝszExpManagerApi.protocol_statuscCsdS)Nr)r r*rrr!Úprotocol_status_codeæsz"ExpManagerApi.protocol_status_codecCsdS)Nr)r r*rrr!Úensure_protocolïszExpManagerApi.ensure_protocol)r*cCsdS)Nr)r r*rrr!Úsubmit_protocoløszExpManagerApi.submit_protocolcCsdS)Nr)r r*rrr!Úinterrupt_protocolsz ExpManagerApi.interrupt_protocolcCsdS)Nr)r r*rrr!Úsuspend_protocol
szExpManagerApi.suspend_protocolcCsdS)Nr)r r*rrr!Úresume_protocolszExpManagerApi.resume_protocolcCsdS)Nr)r rrr!Ú
interrupt_allszExpManagerApi.interrupt_all)N)N)F)0Ú__name__Ú
__module__Ú __qualname__Ú __slots__ÚpropertyÚabcÚabstractmethodÚListrr"ÚExpProtocolInfor#Ústrr%Ú ExpProtocolr(r)Úintr+ÚUnionÚ ExpOptionr,ÚAnyr/ÚOptionalr1r2r3r4r5r6r8Úboolr9r:r;r<r=r>ÚReadonlyExpProtocolStater?r@rArBrCrDrErFrrrr!r$sv  
  r)Ú metaclassc@sNeZdZddZedddeedœddƒZed d
ddeedœd d ƒZd
S)ÚExpManagerOptioncCsg|_g|_tƒ|_d|_dS)NF)ÚpathÚ allow_modulerÚ
repositoryÚ
debug_mode)r rrr!Ú__init__$szExpManagerOption.__init__z-PÚPATH)r.)Úoptr.cCs|j |¡dS)N)r[Úappend)r rar.rrr!Ú_path*szExpManagerOption._pathz-Lz --librarycCs|j |¡dS)N)r]Úadd_library_path)r rar.rrr!Ú
_library_path/szExpManagerOption._library_pathN)rGrHrIr_Ú cli_optionsrPrcrerrrr!rZ#s

 rZc@eZdZiZdZeddƒZeedœddZ e
e e e
ee e e
ffdœdd „ƒZe
d
d ƒZe
die
eed
œddƒZdje
ee eedœddZeeedœddƒZddZee
ddƒƒZeee
dœddƒZeedœddZe eedœdd „Ze
e ed!œd"d#„ƒZeee e e d$œd%d&„ƒƒZ!e
ee dœd'd(„ƒZ"e
e#e d
œd)d*„ƒZ$e e#e fd+d
œd,d-„Z%e
e#ee&d
œd.d/„ƒZ'e
dke e#e fe e(e(d1œd2d3„ƒZ)e
e e#e fe d4œd5d6„ƒZ*e#ee#d7œd8d9„Z+ee#dœd:d;„Z,ee#dœd<d=„Z-ee#dœd>d?„Z.ee#dœd@dA„Z/ee#dœdBdC„Z0ee#dœdDdE„Z1dlee#dœdGdH„Z2e e#e fe#e3dIœdJdK„Z4e e#e fe3d
œdLdM„Z5e e#e fe3d
œdNdO„Z6e e#e fe3d
œdPdQ„Z7e e#e fe3d
œdRdS„Z8e e#e fe3d
œdTdU„Z9e e#e fe3d
œdVdW„Z:e e#e fee;d
œdXdY„Z<e e#e fe#d
œdZd[„Z=ee e#e fe3d
œd\d]„ƒZ>eee e#e fd^œd_d`„ƒƒZ?eee e#e fd^œdadb„ƒƒZ@eee e#e fd^œdcdd„ƒƒZAeee e#e fd^œdedf„ƒƒZBdgdh„ZCd0S)mÚ
ExpManager)ÚopenÚ
memoryviewÚexitÚinputÚexecÚcompileÚevalÚprintcCsLt|jƒdkrFx6ttƒD]*}||jkr(q|dkr2qtt|ƒ|j|<qW|jS)NrÚ
__import__)ÚlenÚ_ExpManager__BUILTINÚdirÚbuiltinsÚ_ExpManager__BLACKLIST_BUILTINÚgetattr)ÚclsÚkrrr!Z__init_builtinCs
zExpManager.__init_builtin)Ú
controllerr-cCsXt |dt¡t |¡||_||_g|_g|_g|_d|_ | 
|j ¡t |j
ƒ|_dS)Nrg)rr_ÚBLUErÚ_serverÚ_optionÚ_protocol_rootÚ_protocol_infoÚ _protocolÚ
_schedulerÚappend_protocol_rootr[Úlistr\Ú
_allow_module)r ryr-rrr!r_Ps
 zExpManager.__init__)r[cCsbt|ttfƒr<xN|D]"}t|tƒr*t|ƒ}|j |¡qWn"|}t|tƒrRt|ƒ}|j |¡dS)N)Ú
isinstancerÚtuplerPrr}rb)r r[Úprrr!rhs


zExpManager.append_protocol_rootcCsp|j ¡g}x\|jD]R}| ¡xD| ¡D]8}| ¡r,|j d¡s,|j d¡r,|j |  ||¡¡q,WqWdS)_z.py)
r~Úclearr}ÚiterdirÚis_filer$Ú
startswithÚendswithÚextendÚ_load_protocol)r Úlocal_module_listÚdr†rrr!Úreload_protocolys
  zExpManager.reload_protocolT)r*rcCs |j|g|d}|j |¡|S)N)Úsuppress_warning)r~r)r r*rÚretrrr!Ú
load_protocol‡s zExpManager.load_protocol)r*rrc
slttdœfdd dttttftttftttdœfdd
}ˆ d ˆ¡ˆ ¡}| ¡}WdQRXd
ˆ  ¡i}||d
d <yt
t |tˆƒd ƒ|ƒWn<t k
}zˆsÒt
rÊt|ƒntˆƒgSd}~XYn†Xg} xz| ¡D]n}
t|
tƒròt|
tƒrò|
tk ròt|
d
ƒròˆ td tƒ|
 ¡tdtƒ|
jtdtƒˆ¡tˆƒ|
_|  t|
ƒ¡qòW| SdS)N)r$rcs:|tkr dS|tkrdS|ˆjkr&dS|ˆkr2dSdSdS)NTF)Ú_IMPORT_WHITE_LIST_Ú_IMPORT_BLACK_LIST_rƒ)r$)rr rr!Ú_module”s
z*ExpManager._load_protocol.<locals>._module.r)r$ÚglobalsÚlocalsÚfromlistÚlevelcsvˆs ˆ tdtƒ|tdtƒˆ¡ˆ|ƒsFtr6t|ƒntdt|ƒƒ|dkr`t d||||¡St |||||¡SdS)importÚfromznot allowed module : zbiopro.exp_prozbiopro.exp_pro.protocol)Ú log_verboseÚpcrÚ_RUNTIME_COMPILEÚ ImportErrorÚreprrtrp)r$r˜r™r)r—r*r rrr!Ú_import¡s
z*ExpManager._load_protocol.<locals>._importÚloadÚ __builtins__rprlÚ _exp_nameÚclassr)...r)rPrWÚDictrUrNrRrhÚreadÚ_ExpManager__init_builtinrlrmÚ
BaseExceptionr roÚprint_exceptionÚvaluesr„ÚtypeÚ
issubclassrQÚhasattrÚlog_inforŸÚYELLOWÚexp_namerrGÚ
_exp_filepathrbrO) r r*rrÚcontentÚer“Úvr)r—rr*r rr!s86 
  

 
zExpManager._load_protocol)rcCs|jS)N)r€)r rrr!Ú schedulerÜszExpManager.schedulercCs|j tƒ¡|_dS)N)r{Ú
run_threadÚExpProtocolSchedulerr€)r rrr!ÚsetupàszExpManager.setupcCs6|jdk r|j ¡x|jD]}|js| ¡qWdS)N)r€ÚcloserÚ
is_terminatedÚshutdown)r r†rrr!ãs


 zExpManager.shutdowncCs|jS)N)r})r rrr!r"íszExpManager.protocol_rootcCs
t|jƒS)N)rr~)r rrr!r#ñsz"ExpManager.list_available_protocol)r&rcCs"x|jD]}|j|kr|SqWdS)N)r~)r r&r†rrr!Ú_find_protocolôs 
zExpManager._find_protocol)r$rcCs"| |¡}|dkrtd|ƒ|S)Nzprotocol not found : )Ú RuntimeError)r r$r†rrr!r%ûs
 zExpManager.get_protocol_info)r&r'rcCs\| |¡}|dkrtd|ƒt|jƒ}| ¡}||_t|||j|jj d}|j 
|¡|S)Nzprotocol not found : )r^) rqrÚ new_protocolÚ_exp_idÚUserBindExpApir{r|r^rb)r r&r'ÚinfoÚproÚapirrr!r(s
 

  zExpManager.create_protocolcCsttddtdd|jƒƒƒS)NcSs|jS)N)r*)Úitrrr!Ú<lambda>óz*ExpManager.list_protocol.<locals>.<lambda>cSs|dk S)Nr)rrr!)rÚmapÚfilterr)r rrr!r)s
zExpManager.list_protocolcCs | |¡jS)N)Ú
_get_protocolr*)r r*rrr!r+szExpManager.get_protocolrÅcCsDt|tƒs|j}y
|j|Stk
r.YnXtdt|ƒƒdS)Nzprotocol not found : )r„rRÚpro_idrÚ
IndexErrorÚKeyErrorrP)r r*rrr!!s

zExpManager._get_protocolcCs| |¡ ¡S)N)Ú pro_options)r r*rrr!r,,szExpManager.protocol_optionsN)r*r-r.rcCs*| |¡ |¡}|dk r"| |¡| ¡S)N)Ú
pro_optionÚsetÚget)r r*r-r.Úorrr!r/0s
zExpManager.protocol_option)r*r0cGs&| |¡}|jrtdƒ|j|ŽdS)Nzprotocol has terminated)r¿Ú pro_reset)r r*r0r†rrr!r19s
zExpManager.protocol_reset)Ústatusrcs0|jdkrgttddtfdd|jƒƒƒS)NcSs|jS)N))r†rrr!Fz4ExpManager._get_protocol_in_status.<locals>.<lambda>cs|jdk o|jjˆkS)N))r†)rr!G)r€rr)r r)r!Ú_get_protocol_in_statusBs


 z"ExpManager._get_protocol_in_statuscCs
| t¡S)N)Ú STATUS_INIT)r rrr!r2Jsz#ExpManager.get_configuring_protocolcCs | tt¡S)N)Ú STATUS_SETUPÚ STATUS_READY)r rrr!r3MszExpManager.get_pending_protocolcCs
| t¡S)N)Ú STATUS_START)r rrr!r4PszExpManager.get_running_protocolcCs
| t¡S)N)ÚSTATUS_SUSPEND)r rrr!Úget_suspend_protocolSszExpManager.get_suspend_protocolcCs
| t¡S)N)ÚSTATUS_COMPLETE)r rrr!r5Vsz!ExpManager.get_completed_protocolcCs
| t¡S)N)ÚSTATUS_INTERRUPTED)r rrr!r6Ysz#ExpManager.get_interrupted_protocolFcCs |r| t¡S| ttt¡SdS)N)Ú STATUS_ERRORrá)r r7rrr!r8\s
z"ExpManager.get_terminated_protocol)r*rcGs"| |¡j}|dkrdS|j|kS)NF))r r*Úsrrr!Ú_is_protocol_in_statusbs z!ExpManager._is_protocol_in_statuscCs | |t¡S)N))r r*rrr!r9jsz"ExpManager.is_protocol_configuringcCs| |tt¡S)N))r r*rrr!r:mszExpManager.is_protocol_pendingcCs | |t¡S)N))r r*rrr!r;pszExpManager.is_protocol_runningcCs | |t¡S)N))r r*rrr!r<sszExpManager.is_protocol_suspendcCs | |t¡S)N))r r*rrr!r=vsz ExpManager.is_protocol_completedcCs | |t¡S)N))r r*rrr!r>ysz"ExpManager.is_protocol_interruptedcCs | |¡jS)N))r r*rrr!r?|szExpManager.protocol_statuscCs"| |¡}|j}|dkrtS|jS)N)ÚSTATUS_UNKNOWN)r r*r†rrr!r@s
zExpManager.protocol_status_codecCs | |¡}|jrtdƒ| ¡S)Nzprotocol has terminated)r¿Ú
pro_ensure)r r*r†rrr!rAs
zExpManager.ensure_protocol)r*cCsV|jdkrtdƒ| |¡}|jr*tdƒ|jr8tdƒ|j |j|¡}| |¡dS)Nzscheduler not initzprotocol has terminatedzprotocol has submitted)r€r¿Úis_setuprBr*)r r*r†rrr!rBs

zExpManager.submit_protocolcCsJ|jdkrtdƒ| |¡}|jr*tdƒ|js8tdƒ|j |j¡dS)Nzscheduler not initzprotocol has terminatedzprotocol has not submitted)r€r¿rCr*)r r*r†rrr!rC s

zExpManager.interrupt_protocolcCsJ|jdkrtdƒ| |¡}|jr*tdƒ|js8tdƒ|j |j¡dS)Nzscheduler not initzprotocol has terminatedzprotocol has not submitted)r€r¿rDr*)r r*r†rrr!rD°s

zExpManager.suspend_protocolcCsJ|jdkrtdƒ| |¡}|jr*tdƒ|js8tdƒ|j |j¡dS)Nzscheduler not initzprotocol has terminatedzprotocol has not submitted)r€r¿rEr*)r r*r†rrr!rEÀs

zExpManager.resume_protocolcCs|jdk r|j ¡dS)N)r€rF)r rrr!rFÐs
zExpManager.interrupt_all)T)T)N)F)DrGrHrIrrruÚ classmethodrªr rZr_rrSrPrrNrrrOr”rKrVrr"r#r%rrQr(r)rRr+rTr,rUr/r1r2r3r4r5r6r8rWr9r:r;r<r=r>ÚExpProtocolStater?r@rArBrCrDrErFrrrr!rg4s†
& J   rgc@seZdZedœddZdS)ÚDeviceFileInfo)ÚfilepathcCs||_d|_dS)N)Ú export_path)r rrr!r_ÖszDeviceFileInfo.__init__N)rGrHrIrr_rrrr!Õsc@eZdZdZdedœddZeeedœddƒZ ee
dœd d
ƒZ ee dœd d ƒZ
eedœd
dƒZee
dœddƒZee
dœddƒZeedœddƒZeeedœddƒZeeedœddƒZeee
dœddƒZddZedœddZedœd d!„Ze
ed"œd#d$„Ze
eed%œd&d'„Ze
eed%œd(d)„Ze
ed*œd+d,„Z e!d-œd.d/„Z"e
d0œd1d2„Z#ee$dœd3d4„Z%e$d5œd6d7„Z&ee$dœd8d9„Z'ee(e)dœd:d;„ƒZ*d<d=„Z+d>d?„Z,d@S)AÚUserBindDeviceInfo)Ú__userÚ
__protocolZ__deviceÚ
__filepathrÅ)ÚdevicecCs$|j|_|jj|_||_dg|_dS)N)ÚuserÚ_UserBindDeviceInfo__userr*Úpro_nameÚ_UserBindDeviceInfo__protocolÚ_UserBindDeviceInfo__deviceÚ_UserBindDeviceInfo__filepath)r rrr!r_Þs
zUserBindDeviceInfo.__init__)rcCs|jjS)N)Ú device_id)r rrr!äszUserBindDeviceInfo.device_idcCs|jjS)N)Ú device_name)r rrr!èszUserBindDeviceInfo.device_namecCs|jjS)N)Ú
serial_number)r rrr!ìsz UserBindDeviceInfo.serial_numbercCs|jjS)N)Ú mac_address)r rrr!ðszUserBindDeviceInfo.mac_addresscCs|jjS)N)Ú library_name)r rrr!ôszUserBindDeviceInfo.library_namecCs|jjS)N)Úlibrary_version)r rrr!øsz"UserBindDeviceInfo.library_versioncCs|jS)N))r rrr!üszUserBindDeviceInfo.devicecCs|jjS)N)Úbattery)r rrr!rÿszUserBindDeviceInfo.batterycCs|jjS)N)Úparent)r rrr!rszUserBindDeviceInfo.parentcCs|jjS)N)Úrecording_file_name)r rrr!rsz&UserBindDeviceInfo.recording_file_namecCs&|jjjtj|j|jds"tdƒdS)N)r'Ú experimentalzdevice un-locked)ÚlockÚvalidater ÚLOCK_EXPERIMENTALrô)r rrr!r s 
zUserBindDeviceInfo.validatecCs|jjj|j|jdS)N)r'r)rÚreleaserô)r rrr!rszUserBindDeviceInfo.release)cCs | |j¡S)N)Úmatchr÷)r rrr!rszUserBindDeviceInfo.match)Ú parameterrcCs |j |¡S)N)Ú
get_parameter)r rrrr!r sz UserBindDeviceInfo.get_parameter)rr.rcCs|jjj |||jj¡S)N)ÚlibraryÚparameter_tableÚ get_valueÚcontext)r rr.rrr!Úto_valueszUserBindDeviceInfo.to_valuecCs|jjj |||jj¡S)N)r
r Ú
cast_valuer
)r rr.rrr!Ú to_parameter"szUserBindDeviceInfo.to_parameter)rr.cCs| ¡|j ||¡S)N)rÚ
set_parameter)r rr.rrr!r%sz UserBindDeviceInfo.set_parameter)Ú
configurationcCs|jj |¡dS)N)rÚ overwrite)r rrrr!Úset_configuration)sz$UserBindDeviceInfo.set_configuration)Ú instructioncCs| ¡|j |¡S)N)rÚcall_instruction)r rrrr!r,sz#UserBindDeviceInfo.call_instructioncCs |jd}|dkrdS|jSdS)Néÿÿÿÿ))r r†rrr!Ú filepath_use0s
zUserBindDeviceInfo.filepath_use)cCs2|jddkrt|ƒ|jd<n|j t|ƒ¡dS)Nr)rb)r rrr!Ú filepath_set8szUserBindDeviceInfo.filepath_setcCs,|jd}|dk r$|j d¡|jSdSdS)Nr)rb)r r“rrr!Úfilepath_unset>s

 z!UserBindDeviceInfo.filepath_unsetcCstdd|jƒS)NcSs|dk S)Nr)rrr!Hz-UserBindDeviceInfo.filepath.<locals>.<lambda>))r rrr!FszUserBindDeviceInfo.filepathcCs
d|jS)NzDeviceInfo[%d]))r rrr!Ú__str__JszUserBindDeviceInfo.__str__cCst|ƒS)N)rP)r rrr!Ú__repr__MszUserBindDeviceInfo.__repr__N)-rGrHrIrJrr_rKrVrRrPrÚADDRESSrürÿÚdictrrrrWrÚ
DeviceInforrUr rrrrrrrrrrrrrrrrr!ÛsLcs&eZdZdyeeedœfdd
ZeedœddƒZeedœdd „ƒZ eedœd
d ƒZ
e e ee
fed œd
dƒZeedœddƒZeedœddƒZddZedœddZedœddZeedœddZeedœddZedœd d!„Zd"d#„Zeedœd$d%„ƒZeeedœd&d'„ƒZedœd(d)„Z e!j!dœd*d+„Z"e e e#e!j!fd,œd-d.„ƒZ$e e e#e!j%fd/œd0d1„ƒZ&e d2d2d3œee ee'fe(d4œd5d6„ƒZ)e ee(dœd7d8„ƒZ*e ee(dœd9d:„ƒZ+e e,dœe(eed;œd<d=„ƒZ-e ee(dœd>d?„ƒZ.e ee(d@œdAdB„ƒZ/e ee(fe0d@œdCdD„Z1e dzeee(dFœdGdH„ƒZ2e(dIœdJdK„Z3e edLœdMdN„ƒZ4e e ee(fee5dOœdPdQ„ƒZ6e e ee(fdRœdSdT„ƒZ7e0edUœdVdW„Z8e e ee(fee5e5dXœdYdZ„ƒZ9e e ee(fee5e5dXœd[d\„ƒZ:e e ee(fed]œd^d_„ƒZ;e e ee(feed@œd`da„ƒZ<e e ee(feedbœdcdd„ƒZ=e e ee(feed@œdedf„ƒZ>e dgdh„ƒZ?e ediœdjdk„ƒZ@e ee ee(feAee ee(fdlœdmdn„ƒZBeee ee(feCee5fdoœdpdq„ZDe d2drœee ee(feeeAedsœdtdu„ƒZEeeeFe ee(fedvœdwdx„ZG‡ZHS){rÅF)r'r*Úcontrolctƒ |jt¡| |¡| d|¡||_||_||_g|_ d|_
d|_ |jj j
|j|_|j ¡sv|jjddn|j ¡sŽtt|jƒƒ|j|_g|_||_|r¬d|_dS)NróFT)Úparentsr)Úsuperr_ÚWHITEÚ user_inforžÚ_UserBindExpApi__protocolÚ_UserBindExpApi__userÚ_UserBindExpApi__serverÚ_UserBindExpApi__deviceÚ_UserBindExpApi__statusÚ_UserBindExpApi__terminatedÚ file_managerÚ storage_rootÚ_root_directoryÚexistsÚmkdirÚis_dirÚNotADirectoryErrorrPÚ_use_directoryZ archive_pathÚ_UserBindExpApi__debugÚ_UserBindExpApi__next_time)r r'r*r r^)Ú __class__rr!r_Vs&
 

zUserBindExpApi.__init__)rcCs|jS)N)r%)r rrr!r*zszUserBindExpApi.protocolcCs
t|jƒS)N)rPr-)r rrr!Úroot_directory~szUserBindExpApi.root_directorycCs
t|jƒS)N)rPr2)r rrr!Ú
use_directoryszUserBindExpApi.use_directory)r[rcCt|tƒr|j|}n6| ¡rBt||jƒr0|}qLtdt|ƒƒn
|j|}| ¡ ¡}t||jƒsttdt|ƒƒ| ¡r˜|  ¡s˜t
t|  |j¡ƒƒ|  d|¡||_
t|ƒS)Nz$path not under the root directory : Zchange)r„rPr-Ú is_absoluter
Ú
ValueErrorÚresolveÚabsoluter.r0r1Ú relative_toržr2)r r[r†rrr!Úchange_directory†s
  
   zUserBindExpApi.change_directorycCs
|jdk S)N)r))r rrr!ŸszUserBindExpApi.is_setupcCs|jS)N)r*)r rrr!r¿£szUserBindExpApi.is_terminatedcCs|jrtdƒdS)Nzprotocol has terminated)r*)r rrr!Ú
_ensure_alive§szUserBindExpApi._ensure_alivecCs|jr tƒ|j |¡S)N)r*r%)r rrr!­szUserBindExpApi.pro_ensure)r0cGs|jr
dS|jj|ŽdS)N)r*r%)r r0rrr!³szUserBindExpApi.pro_resetcCs&|j ¡}|jrdd|DƒS|SdS)NcSsg|] }t|ƒqSr)ÚReadonlyExpOption)Ú.0r×rrr!ú
<listcomp>½sz.UserBindExpApi.pro_options.<locals>.<listcomp>)r%r*)r r“rrr!¹s
zUserBindExpApi.pro_options)r-rcCs"|j |¡}|jrt|ƒS|SdS)N)r%r*r?)r r-r“rrr!Ás zUserBindExpApi.pro_option)cCs| ¡||_dS)N)r>r))r rrr!ËszUserBindExpApi.setupcCs d|_t|jƒdkr| ¡dS)NTr)r*rqr(Úrelease_device)r rrr!ÏszUserBindExpApi.shutdowncCs|jS)N)r&)r rrr!×szUserBindExpApi.usercCs|jS)N)r))r rrr!ÛszUserBindExpApi.statuscCs|jr |jSttƒƒSdS)N)r3r4rRÚtime)r rrr!Úcurrent_timestampßsz UserBindExpApi.current_timestampcCs
tj ¡S)N)ÚdatetimeÚnow)r rrr!Úcurrent_datetimeåszUserBindExpApi.current_datetime)Ú timestampcCs2| ¡|jr.t|ttfƒr.||_| d|¡dS)Nz next time)r>r3r„rRÚfloatr4)r rHrrr!Ú
schedule_timeès
zUserBindExpApi.schedule_time)ÚsleepcCs | ¡dS)N)r>)r rKrrr!Úschedule_sleepñszUserBindExpApi.schedule_sleepN))rcC| ¡|dkr"|dkr"tdƒnb|jjj}d}|dk rF| |j|¡}|dkrd|dk rd| |j|¡}|dk r„| d|¡|j}|j }t
|t ƒrt |ƒ}|dkrÚ|j
rªt}n0|dk r¸|}n|dk rÊt|ƒ}nd}td|ƒt|tj|dS)Nz,both device_name and mac_address are omittedz
find aliasz#neither device_name nor mac_addresszdevice not found : ))r>r'r+Ú user_settingÚ
alias_infor&Údevice_addressr„rPr
r3rrrrÚUNKNOWN)r ÚsettingÚaliasÚmessagerrr!Úmake_device_infoõs6

 

 zUserBindExpApi.make_device_infocCs| ¡|jj ¡S)N)r>r'Údevice_managerÚfound)r rrr!Ú found_deviceszUserBindExpApi.found_devicecCs| ¡|jj ¡S)N)r>r'rUÚ list_device)r rrr!Úconnected_device$szUserBindExpApi.connected_device)Ú device_listrÙrcsnˆ ¡|ttfkr$tdt|ƒƒt|ƒdkr4dSˆj ¡dtt dœfdd }ˆ 
d¡gx`|D]X}||ƒ}|dkr¸|tkrŠd Sˆjj |dd
}|dkr¬t t
|ƒˆj |¡}ˆ |¡qjWˆ 
d ¡ˆjjfd d
}xbˆD]Z}|tkr|jjtjˆjˆdsHd Sqî|jjtjˆjˆdsî|ƒt dt|jƒƒqîWˆ 
d¡fddˆDƒˆ_dS)Nzillegal status : rTr)Ú _requiredrcs xˆD]}| |¡r|SqWdS)N)r)r[r)Ú connectedrr!Ú_get5s

z*UserBindExpApi.ensure_device.<locals>._getzconnect deviceF)Úscanzgain experimental lockcs$xˆD]}|jjˆjˆdqWdS)N)r'r)rrr&)Ú_device)rr Ú used_devicerr!Ú_releaseUs
z.UserBindExpApi.ensure_device.<locals>._release)r'rzcannot gain lock for device : zregister devicecsg|]}tˆ|ƒqSr))r@r)r rr!rAhsz0UserBindExpApi.ensure_device.<locals>.<listcomp>)r>r9ÚExpProtocolStatusrqr'Úget_device_info_allrVrÚhardware_device_foundrÂÚDEVICE_NOT_FOUNDÚhardware_device_connectrbr%rrr rr&Ú
gain_priorityrr()r rZr]ÚrequiredròÚresponserar)r\rr r`r!Ú
ensure_device)sH