def ChgAmp(root, interface): cl = clients.SelectClient(root, None, edict, title='Select Live Client') if not cl: return opath = edict['DATAPATH'] + '\\' + cl['client.clientid'] clo = IniAid.LoadConfig(opath + '\\CLIENT.') dev = _GetDeviceSelection(root, interface) if dev == None: dev = '' clo['client.acqamp'] = dev clients.WriteClientFile(clo, edict)
def MakeNormal(root, interface): cl = clients.SelectClient(root, None, edict, shamselect=1) # make selection list from these if not cl: return #get GUID fpath = edict['DATAPATH'] + '\\' + cl['client.xguid'] # mark that folder as normal _SetAttributes(fpath, 0) opath = edict['DATAPATH'] + '\\' + cl['client.clientid'] clo = IniAid.LoadConfig(opath + '\\CLIENT.') clo['client.stdyclient'] = 0 try: clo['client.shamclient'] = 0 except: pass clients.WriteClientFile(clo, edict) clients.NewClientIndexNeeded(root, edict, 0)
def MarkStudyClient(root, interface): cl = clients.SelectClient(root, None, edict) if not cl: return opath = edict['DATAPATH'] + '\\' + cl['client.clientid'] clo = IniAid.LoadConfig(opath + '\\CLIENT.') try: issham = int(clo['client.stdyclient']) except: issham = 0 if issham: tkMessageBox.showerror('Study Client', 'This is already a sham client') return clo['client.stdyclient'] = 0 dev = _GetDeviceSelection(root, interface) if dev == None: dev = '' clo['client.acqamp'] = dev clients.WriteClientFile(clo, edict)
def _comnRU(root, edict, update, eegoperator=None, prt=None): global _sd, _ans, _val if eegoperator == None: eegoperator = '' # verify T system (dongle) if edict['SETTINGS']['LICENSEKIND'][0] != 'C': return 'Not Therapist Dongle and license' # choose client (no proto) cldict = clients.SelectClient(root, 0, edict, nonew=1) if not cldict: return 'Cancel' if not update: drive = ChooseRUDrive(root, edict) if not drive: return 'Cancel' #### # if there is DATA on this drive, get it back!!!!!! extrawarn = '' ans = removable.checksd(drive) if type(ans) == type(1): if ans < 0: #HERE if its a valid drive with conceivably some data on it if tkMessageBox.askyesno( 'Return data', 'Should I retrieve any data already stored on this drive?' ): if removable.copyback(drive, edict): return 'Failed copying data back' #### else: # here for EXTRA check on fixed internal drives if removable.isfixed(drive): extrawarn = '\nNote that this reports as a FIXED disk! Are you SURE?' # Verify Erase OK ms = 'Is it OK to COMPLETELY PERMANENTLY erase drive ' + drive + ' ???' + extrawarn if not tkMessageBox.askokcancel('Erase drive ', ms): return 'Not OK to erase' # Create SD if removable.cleandrive(drive): return 'Failed to completely erase drive' if removable.makedrive(drive, cldict['client.clientid'], edict): return 'Failed creating SD format' # now to generate the stuff chosen = 0 while 1: # Select protocol class or DONE if chosen: key = 'Finish' else: key = 'Abort' ans = clients.SelectProtocol(root, 'Select protocol class for this client', canx=key) if not ans: if not chosen: return 'Aborted' break # Select layout lay = clients.GetLayoutSelection(root, ans, edict, canx='Cancel') if not lay: continue #-->if no stages file for layout ==>nono spath = edict['DATAPATH'] + '/' + cldict[ 'client.clientid'] + '/' + ans + '/stages.' + lay if not os.path.exists(spath): tkMessageBox.showerror( 'Invalid layout', 'This layout does not exist for this client') continue # enter expiration date and # sessions and client dongle (stored/writen to client file on hard drive) exp, sess, dong, disallow = _get_params(root, cldict, edict) if not dong: continue # create proto directory on SD(and copy in HD stages file) # build expiry file on SD (using HD stages file for specified layout) pathp = edict['DATAPATH'] + '\\' + cldict[ 'client.clientid'] + '\\' + ans + '\\' spath = '%s\\PREFERENCES\\%s\\presets.%s' % (edict['PROGRAMPATH'], ans, lay) try: pdict = IniAid.LoadConfig(spath) except: pdict = {} pathn = pathp + 'STAGES.' + lay st, d, title = stages.load_stages_from_file(pathn, edict, pdict) idict = {} idict['SETTINGS'] = edict['SETTINGS'] idict['EDICT'] = edict idict['easystages'] = stages.easystages(st) #easy-to-parse-in-c idict['easylength'] = len(idict['easystages']) idict['CLIENT'] = cldict if update: # here we must specify the filename to write to if removable.ru_update(ans, lay, cldict['client.clientid'], idict, exp, sess, dong, disallow): if prt: print 'Failed building expiry file' #print idict else: return 'Failed building expiry' logremote('Update', edict, lay, cldict['client.clientid'], idict, exp, sess, dong, disallow, eegoperator) else: rcode = removable.protocol([ (ans, lay), ], drive, cldict['client.clientid'], idict, exp, sess, dong, disallow) if rcode: if prt: print 'Failed copying a protocol class to SD' #print idict else: return 'Failed copying a protocol class to SD : %d' % rcode logremote('Create', edict, lay, cldict['client.clientid'], idict, exp, sess, dong, disallow, eegoperator) # update stored dongle number cldict['dongle.dongle'] = str(dong) clients.WriteClientFile(cldict, edict) chosen = 1 return None
def RenameClient(root,edict,rpt=0): # select source client (all protos) cdold = clients.SelectClient(root,0,edict,1,'Old client name') if cdold == None: return # never mind # Create new client cd=clients.CreateNewClient(root,edict,title='Creating new client name ',oldclient=cdold) if cd == None: return # again, never mind # but use XGUID from old client!!!! cd['client.xguid']=cdold['client.xguid'] clients.WriteClientFile(cd,edict) oldsrcroot=edict['DATAPATH']+ '\\'+cdold['client.clientid']+'\\' newroot=edict['DATAPATH']+ '\\'+cd['client.clientid']+'\\' # move old edit file efile=oldsrcroot+cdold['client.clientid']+'.txt' if os.path.exists(efile): shutil.copy2(efile,newroot+cd['client.clientid']+'.txt') # for all classes sdlst=glob.glob(oldsrcroot+'*') # move all contents errors=0 for each in sdlst: if os.path.isdir(each): # here on subdirs dest_proto=os.path.basename(each) spath=each dpath=newroot+dest_proto os.mkdir(dpath) stgsx=['lastset.*','stages.*','lastlayout.ini'] stgs=[] for x in stgsx: stgs.extend(glob.glob(spath+'/'+x)) for fnx in stgs: fn=os.path.basename(fnx) filename=spath+'\\'+fn newname=dpath+'\\'+fn if os.path.exists(filename): # must change internal names matching the OLD name to the NEW name if _renameinside(filename,newname,cd,cdold): # if failed or no change needed, use bulk copier shutil.copy(filename,dpath) shutil.copystat(filename,dpath+'\\'+fn) ##print oldsrcroot,dest_proto flst=simpletree.RawSumFilelist(oldsrcroot[:-1],dest_proto) ##print flst for entry in flst: # each file if entry[0]: continue f=entry[3] destfilename=dpath+'\\'+cd['client.clientid']+os.path.basename(f)[-10:] while 1: if not os.path.exists(destfilename): break num=int(destfilename[-6:-4]) num = num+1 if num >= 100: _dialoghelper('File rename failure','Too many files for one day',root=root) destfilename=None errors += 1 break destfilename='%s%02d%s' %(destfilename[:-6],num,destfilename[-4:]) if destfilename == None: continue # no place for this guy srcfilename=spath+'\\'+os.path.basename(f) shutil.copy(srcfilename,destfilename) # must know if RAW or SUM since headers differ!!!! if destfilename.upper()[-4:] == '.RAW': # update raw header rawlist.writeheader(destfilename,cd['client.clientid'],cd['client.fullname'],dest_proto) else: # update sum header sumfile.writeheader(destfilename,cd['client.clientid'],cd['client.fullname'],dest_proto) shutil.copystat(srcfilename,destfilename) # move date os.remove(srcfilename) # remove old client if no errors if errors == 0: shutil.rmtree(oldsrcroot[:-1],1) clients.NewClientIndexNeeded(root,edict,0) try: gc.collect() except: pass
def MakeSham(root, interface): # select active client cl = clients.SelectClient(root, None, edict) if not cl: return poolname = _GetPoolName(root, interface) if not poolname: return randm = _GetRandomizeOption(root, interface) spl = _MakeShamPoolList(poolname, 'SMR', randomize=randm) apl = _MakeShamPoolList(poolname, 'AT', randomize=randm) epl = _MakeShamPoolList(poolname, 'EXP', randomize=randm) if len(spl) == 0: tkMessageBox.showerror('Pool Files', 'There are no pool files defined') return if len(apl) == 0: apl = spl if len(epl) == 0: epl = spl # retrieve the GUID and make path opath = edict['DATAPATH'] + '\\' + cl['client.clientid'] fpath = edict['DATAPATH'] + '\\' + cl['client.xguid'] # iff no such folder, create it and all the subsidiary ones if not os.path.exists(fpath): os.mkdir(fpath) # and copy basic files over clx = cl.copy() clx['study.smrseq'] = 0 clx['study.smrfiles'] = spl[:] clx['study.atseq'] = 0 clx['study.atfiles'] = apl[:] clx['study.expseq'] = 0 clx['study.expfiles'] = epl[:] clx['study.random'] = randm fd = open(fpath + '\\CLIENT.', 'w') IniAid.WriteConfigFD(fd, clx, 1) fd.close() # copy SMR,EXP,AT iff exist and all stages files for subf in ['SMR', 'AT', 'EXP']: osubpath = opath + '\\' + subf flst = glob.glob(osubpath + '\\stages.*') if len(flst): nsubpath = fpath + '\\' + subf try: os.mkdir(nsubpath) except: pass for f in flst: shutil.copy2(osubpath + '\\' + os.path.basename(f), nsubpath + '\\' + os.path.basename(f)) # mark folder as hidden+system _SetAttributes(fpath, 1) cl['client.stdyclientid'] = cl['client.xguid'] cl['client.stdyclient'] = 1 cl['client.shamoptions'] = 3 dev = _GetDeviceSelection(root, interface) if dev == None: dev = '' cl['client.acqamp'] = dev clients.WriteClientFile(cl, edict)