def CreateClientProtocol(root, mech, edict, preselect=None, internal=0):
    "Initialize a client protocol directory"

    # somehow select a client first?????
    if mech.buttonInhibit:
        return
    if not internal:
        deselect(mech, edict, reset=0)
        mech._set_study_info(root)
        mech.buttonInhibit = 1
        if preselect:
            client = preselect
        else:
            client = clients.SelectClient(root, 0, edict)
        if client == None:
            mech.buttonInhibit = 0
            return
    else:
        client = preselect
    # and a protocol?????
    proto = clients.SelectProtocol(root)
    if proto == None:
        mech.buttonInhibit = 0
        return
    pathing = edict['DATAPATH'] + '\\' + client[
        'client.clientid'] + '\\' + proto
    _copyProtocolFiles(root, mech, edict, client, proto)
Exemple #2
0
def DelActive(root,edict,rpt=0):
    "delete files from active client"
    # select client
    cd = clients.SelectClient(root,0,edict,1)
    if cd == None:
        if rpt:
            print 'No client selected'
        return
    #2. Choose files to delete (some or all of each protocol)
    cpath= edict['DATAPATH']+'\\'+cd['client.clientid']
    lst=simpletree.RawSumFilelist(cpath,None,1)
    flst=simpletree.SelectedFiles(root,cpath,lst)
    if flst == None:
        if rpt:
            print 'No selected files'
        return
    allyes=0
    for item in flst:
        if item[0]:
            continue    # just handle files themselves
        if item[1]:
            delme=0
            if not allyes:
                ans=_ask_about(root,item[2],item[3])
                if ans == 'all':
                    allyes=1
                    delme=1
                elif ans == 'none':
                    break
                elif ans == 'yes':
                    delme=1
            if delme or allyes:
                # here we ACTUALLY delete the file
                #print 'delete ',item[3]
                os.remove(item[3])      
def SelectClient(root,
                 protoflag,
                 mech,
                 edict=None,
                 nonew=0,
                 title='Select client',
                 prevclient=None,
                 prevproto='',
                 pathn=None,
                 shamselect=0,
                 freeze=0):

    client = clients.SelectClient(root,
                                  protoflag,
                                  edict=edict,
                                  nonew=nonew,
                                  title=title,
                                  prevclient=prevclient,
                                  prevproto=prevproto,
                                  pathn=pathn,
                                  shamselect=shamselect,
                                  freeze=freeze,
                                  callback=Command(CreateNewClient,
                                                   root,
                                                   mech,
                                                   edict,
                                                   pathn=pathn,
                                                   internal=1))
    return client
def _get_files(root, edict, rpt=0):
    #1. Select a client from the current (active) client list (I plan on displaying the most recent file activity date)
    while 1:
        cd = clients.SelectClient(root, 0, edict, 1)
        if cd == None:
            if rpt:
                print 'No client selected'
            return ('No client selected', None, None)
        #2. Choose files to archive (some or all of each protocol)
        cpath = edict['DATAPATH'] + '\\' + cd['client.clientid']
        flst = glob.glob(cpath + '\\*.FULL')
        if len(flst) == 0:
            continue

        lst = []
        for fi in flst:
            n = datetime.datetime.fromtimestamp(os.stat(fi)[8])
            name = '%s Full recording (%s)' % (n.ctime(), os.path.basename(fi))
            lst.append([0, 0, name, fi, 0, 0])
        flst = simpletree.SelectedFiles(root, cpath, lst)
        if flst == None:
            if rpt:
                print 'No selected files'
            continue
        return (0, flst, cd)
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 SelectCustomPlan(root, mech, edict, client=None, pro=None):
    # somehow select a client first?????

    if mech.buttonInhibit:
        return
    if client == None:
        clientgui.deselect(nmech, edict)
        mech._set_study_info(root)
        mech.buttonInhibit = 1
        client = clients.SelectClient(root, 0, edict)
        if client == None:
            mech.buttonInhibit = 0
            return
        proto = clients.SelectProtocol(root)
        if proto == None:
            mech.buttonInhibit = 0
            return
        ask = None
    else:
        client = mech.client
        proto = pro
        ask = mech.layout
    pathing = edict['DATAPATH'] + '\\' + client[
        'client.clientid'] + '\\' + proto
    pathn = _selectcustom(root, client, proto, pathing, mech, edict, ask=ask)
    if pathn:
        ####mech.title=stitle
        mech.st_save_path = pathn
        try:
            mech.canvas.itemconfigure(mech.canvlayout,
                                      text=clients.GetLayoutTitle(layout))
        except:
            pass
        mech.set_topwarnings(root)
    mech.buttonInhibit = 0

    # ask - Do you want a specific default plan
    md = Pmw.MessageDialog(
        root,
        message_text='Do you want to load a custom session plan',
        defaultbutton=0,
        title='Option to select a custom session plan',
        buttons=['Yes', 'No'])
    ans = md.activate()
    if ans != None and ans == 'Yes':
        # if yes
        _selectcustom(root, client, proto, pathing, mech, edict)

    clients.NewClientIndexNeeded(root, edict, 1)
    mech.buttonInhibit = 0
    mech._set_study_info(root)
    return proto
Exemple #7
0
def _get_files(root, edict, rpt=0, exclude='RAW'):
    #1. Select a client from the current (active) client list (I plan on displaying the most recent file activity date)
    cd = clients.SelectClient(root, 0, edict, 1)
    if cd == None:
        if rpt:
            print 'No client selected'
        return ('No client selected', None, None)
    #2. Choose files to archive (some or all of each protocol)
    cpath = edict['DATAPATH'] + '\\' + cd['client.clientid']
    lst = simpletree.RawSumFilelist(cpath, exclusion=exclude)
    flst = simpletree.SelectedFiles(root, cpath, lst)
    if flst == None:
        if rpt:
            print 'No selected files'
        return ('No selected files', None, None)
    return (0, flst, cd)
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)
Exemple #10
0
def DeleteEntireClient(root,edict,rpt=0):
    # first, get confirmation!!!
    ans = tkMessageBox.askyesno('Delete Client???','Do you REALLY want to permanently and forever delete a client???')
    if not ans:
        return
    # select client (all protos)
    cd = clients.SelectClient(root,0,edict,1,'Old client name')
    if cd == None:
        return      # never mind
    # get 2nd confirmation
    ans=tkMessageBox.askyesno('Delete Client???','Do you REALLY want to permanently and forever delete '+cd['client.clientid']+'???')
    if not ans:
        return
    # now remove the entire tree
    shutil.rmtree(edict['DATAPATH']+ '\\'+cd['client.clientid'],1)
    
    clients.NewClientIndexNeeded(root,edict,0)
    try:
        gc.collect()
    except:
        pass
def _choose_file(root, fclass='SMR'):
    "locate client raw files in specified type"

    while 1:
        # choose client
        cl = clients.SelectClient(root, 1, edict)
        if not cl:
            return (None, )
        # choose file

        pathn = edict['RAWPATH'] + '\\' + cl['client.clientid']
        fullpathn, start_t, end_t, modif = seselect.SelectFile(
            root,
            'raw',
            edict,
            pathn,
            pcode=cl['pcode'],
            title='Select file to add',
            freeze=1)
        if fullpathn == None:
            continue
        return (fullpathn, start_t, end_t, modif)
Exemple #12
0
def MoveFiles(root,edict,rpt=0):
    "move files from one client/protocol to another"
    cd = clients.SelectClient(root,1,edict,1,'Source client')
    if cd == None:
        if rpt:
            print 'No client selected'
        return
    cpath= edict['DATAPATH']+'\\'+cd['client.clientid']
    lst=simpletree.RawSumFilelist(cpath,cd['pcode'])
    flst=simpletree.SelectedFiles(root,cpath,lst)
    try:
        gc.collect()
    except:
        pass
    if flst == None:
        if rpt:
            print 'No selected files'
        return
    cd2=clients.SelectClient(root,0,edict,1,'Destination client')
    if cd2 == None:
        return
    dest_proto=clients.SelectProtocol(root,'Select class for destination')
    if dest_proto == None:
        return
    if cd['client.clientid'] == cd2['client.clientid'] and cd['pcode'] == dest_proto:
        _dialoghelper('Invalid operation','Sorry, you cannot move to the source class',root=root)
        return
    # things to consider
    #   if I have to create the destination protocol directory
    #       must also copy across lastset.ini and stages.ini
    #   copy file with new 'name' after checking for no conflict 
    #   update header data for protocol and client names
    #   make new file have 'old' date
    spath=edict['DATAPATH']+ '\\'+cd['client.clientid']+'\\'+ cd['pcode']
    dpath=edict['DATAPATH']+'\\'+cd2['client.clientid']+'\\'+dest_proto

    allyes=0
    for item in flst:
        if item[0]:
            continue    # just handle files themselves
        if item[1]:
            delme=0
            if not allyes:
                ans=_ask_about(root,item[2],item[3],dpath)
                if ans == 'all':
                    allyes=1
                    delme=1
                elif ans == 'none':
                    break
                elif ans == 'yes':
                    delme=1
            if delme or allyes:
                # here we ACTUALLY move the file
                if not os.path.exists(dpath):
                    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,cd2):
                                # if failed or no change needed, use bulk copier
                                shutil.copy(filename,dpath)
                                shutil.copystat(filename,dpath+'\\'+fn)
                destfilename=dpath+'\\'+cd2['client.clientid']+os.path.basename(item[3])[-10:]
                while 1:
                    if not os.path.exists(destfilename):
                        break
                    num=int(destfilename[-6:-4])
                    num = num+1
                    if num >= 100:
                        _dialoghelper('File move failure','Too many files for one day',root=root)
                        destfilename=None
                        break
                    destfilename='%s%02d%s' %(destfilename[:-6],num,destfilename[-4:])
                if destfilename == None:
                    continue    # no place for this guy
                srcfilename=spath+'\\'+os.path.basename(item[3])
                shutil.copy(srcfilename,destfilename)
                # must know if RAW or SUM since headers differ!!!!
                if destfilename.upper()[-4:] == '.RAW':
                    # update raw header
                    rawlist.writeheader(destfilename,cd2['client.clientid'],cd2['client.fullname'],dest_proto)
                else:
                    # update sum header
                    sumfile.writeheader(destfilename,cd2['client.clientid'],cd2['client.fullname'],dest_proto)
                shutil.copystat(srcfilename,destfilename) # move date
                os.remove(srcfilename)
    clients.NewClientIndexNeeded(root,edict,0)
    try:
        gc.collect()
    except:
        pass
Exemple #13
0
def Archive(root,edict,rpt=1):
    " handle archive process"
    #1. Select a client from the current (active) client list (I plan on displaying the most recent file activity date)
    cd = clients.SelectClient(root,0,edict,1)
    if cd == None:
        if rpt:
            print 'No client selected'
        return
    #2. Choose files to archive (some or all of each protocol)
    cpath= edict['DATAPATH']+'\\'+cd['client.clientid']
    lst=simpletree.RawSumFilelist(cpath)
    flst=simpletree.SelectedFiles(root,cpath,lst)
    try:
        gc.collect()
    except:
        pass
    if flst == None:
        if rpt:
            print 'No selected files'
        return
    #3. Create archive client (compressed file) if it doesn't exist
    busy=BusyBox.BusyBox(root,'Archiving '+cd['client.clientid'])
    dpath=edict['ARCHIVES']+'\\'+cd['client.clientid']+'.ZIP'
    tmppath=edict['ARCHIVES']+'\\'+str(os.getpid())+'.ZIP'
    arcpath=cd['client.clientid']+'\\'
    if os.path.exists(dpath):
        zfold=zipfile.ZipFile(dpath,'r',zipfile.ZIP_DEFLATED)
        oldflag=1
        oldlist=zfold.namelist()
        copylist=[]
        upperlist=[]
        for v in oldlist:
            # keep list of sum/raw files already there
            u=v.upper()
            if u.find('.RAW') > 0 or u.find('.SUM') > 0:
                copylist.append(v)
                upperlist.append(os.path.normpath(edict['DATAPATH'].upper()+'\\'+u))
    else:
        oldflag=0
    zf=zipfile.ZipFile(tmppath,'w',zipfile.ZIP_DEFLATED)
    #4. Move selected files there
    #5. Make sure that basic client files exist in the archive
        #   add client file
    s1=cpath+'\\client.'
    if os.path.exists(s1):
        zf.write(s1,arcpath+'client.',zipfile.ZIP_DEFLATED)
    else:
        if rpt:
            print 'could not find ',s1
    s1=cpath+'\\'+cd['client.clientid']+'.txt'
    if os.path.exists(s1):
        zf.write(s1,arcpath+cd['client.clientid']+'.txt',zipfile.ZIP_DEFLATED)
    # loop through selected files
    subpath=''
    nodel=0
    for i in range(len(flst)):
        if flst[i][1]:
            if flst[i][0]:
                continue    # all the work is done by selected files!!!
            # copy lastset.ini and stages.ini if exist
            ap=os.path.split(flst[i][3])
            apath=os.path.split(ap[0])[1]
            if apath != subpath:
                subpath=apath

                gotstages=0
                # make up list of all possible stages in src
                stgsx=['lastset.*','stages.*','lastlayout.ini']
                stgs=[]
                for x  in stgsx:
                    stgs.extend(glob.glob(ap[0]+'/'+x))
                #print ap,flst[i][3],stgs
                for fn in stgs:
                    fn=os.path.basename(fn)     # just the name part
                    tpath=arcpath+apath+'/'+fn
                    s1=cpath+'\\'+apath+'\\'+fn
                    if os.path.exists(s1):
                        if fn[:6].lower() == 'stages':
                            gotstages=1
                        zf.write(s1,tpath,zipfile.ZIP_DEFLATED)
                        busy.newstatus(tpath)
                        if oldflag: # must also remove it from list of files to copy
                            try:
                                k=upperlist.index(os.path.normpath(s1.upper()))
                                del copylist[k]
                                del upperlist[k]
                            except:
                                pass
                if gotstages == 0:
                    oops=Pmw.MessageDialog(root,title="Archive Error",message_text="No stages file found during archive.\nPlease contact Customer Support for assistance")
                    oops.activate()
                    nodel=1
                        
            bname=os.path.basename(flst[i][3])
            tpath=arcpath+apath+'\\'+bname
            zf.write(flst[i][3],tpath,zipfile.ZIP_DEFLATED)
            if oldflag:
                look=flst[i][3].upper()
                looker=os.path.normpath(look)
                try:
                    k=upperlist.index(looker)
                    del copylist[k]
                    del upperlist[k]
                except:
                    pass
    if oldflag:
        if len(copylist):
            for v in copylist:
                #print 'copying',v
                of=zfold.read(v)
                ofinfo=zfold.getinfo(v)
                zf.writestr(ofinfo,of)
                busy.newstatus(of)
        zfold.close()
    zf.close()
    if oldflag:
        os.remove(dpath)
    os.rename(tmppath,dpath)
    try:
        gc.collect()
    except:
        pass
    if nodel:
        busy.destroy()
        return      #don't delete anything if error!
    #6. If all files were selected, delete current client entries after archive
    # loop through selected files
    allsel=1
    for i in range(len(flst)):
        if flst[i][0]:
            # here for special subdir files
            if flst[i][1]:
                # delete entire protocol set
                downem=1
                spath=flst[i][3]+'\\*'
                xtra=glob.glob(spath)
                for fn in xtra:
                    try:
                        os.remove(fn)
                        busy.newstatus('removing '+fn)
                    except:
                        if rpt:
                            print 'unable to delete ',fn
                        downem=0
                        allsel=0
                if downem:
                    try:
                        os.rmdir(flst[i][3])
                        clients.NewClientIndexNeeded(None,edict,0)  # rebuild on next access
                    except:
                        allsel=0
                        if rpt:
                            print 'error removing dir',flst[i][3]
            else:
                allsel=0
        else:
            if flst[i][1]:
                if os.path.exists(flst[i][3]):
                    try:
                        os.remove(flst[i][3])
                        busy.newstatus('removing '+fn)
                    except:
                        allsel=0
                        if rpt:
                            print 'error removing ',flst[i][3]
    if allsel:
        try:
            os.remove(cpath+'\\client.')
        except:
            allsel=0
            if rpt:
                print 'error removing ',cpath+'\\client.'
        if os.path.exists(cpath+'\\'+cd['client.clientid']+'.txt'):
            try:
                os.remove(cpath+'\\'+cd['client.clientid']+'.txt')
            except:
                allsel=0
                if rpt:
                    print 'error removing notes file'
    if allsel:
        try:
            os.rmdir(cpath)
        except:
            pass
    busy.destroy()
Exemple #14
0
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

if __name__ == '__main__':
    import clients
    if 1:
        DebugWin.Take_stdout()
        DebugWin.Take_stderr()
    root, edict = _test()

    if 0:
        showprint = tkMessageBox.askquestion(
            'Choose output destination',
            'Do you want the results sent to a print file?',
            type=tkMessageBox.YESNO)
        while 1:
            cd = clients.SelectClient(root, 1, edict, 1, freeze=1)
            if cd == None:
                root.destroy()
                sys.exit()
            ##print cd
            pcode = cd['pcode']
            basepath = edict['PROGRAMPATH'] + '/Clients/' + cd[
                'client.clientid']
            ans = SelectFile(root,
                             'raw',
                             edict,
                             basepath,
                             pcode,
                             title='Select raw data file',
                             freeze=0)
            if ans[0] and ans[1]:
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)
Exemple #17
0
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