PEATDB/Extfile.py
def importFileset(self, DB, parentframe=None, callback=None):
        """Import a series of external files in a folder to peat"""

        def getdir():
            import tkFileDialog, os
            d=tkFileDialog.askdirectory(initialdir=importdir.get(),title='Select directory files',
                                                mustexist=1,parent=self.parent.master)
            if d:
                importdir.set(d)
                return

        def doimport():
            idir = importdir.get()
            ext = filetype.get()
            if idir == None:
                return
            files = os.listdir(idir)
            okfiles = []
            for f in files:
                pth = os.path.join(idir,f)
                if os.path.isfile(pth):
                    if ext != 'any':
                        if os.path.splitext(pth)[1] not in self.extensions[ext]:
                            continue
                    okfiles.append(pth)
            print 'files to be used:', okfiles
            DB.addField('file', 'File')
            from Dialogs import PEATDialog
            self.pb=PEATDialog(self.parent.master, option='progressbar',
                                          message='Importing files')
            self.pb.update_progress(0)
            total = len(okfiles)
            row=0
            #iterate over filenames in folder and add one rec to DB for each file
            for f in okfiles:
                recname=os.path.basename(f)
                DB.addBlob(recname, 'file', f)
                print 'added %s as %s' %(f,recname)
                row=row+1
                c=float(row)/float(total)*100.0
                self.pb.update_progress(c)
            self.pb.close()
            if callback!=None:
                callback()
            return

        def close():
            win.destroy()
            return

        if parentframe!=None:
            win = Frame(master=parentframe,relief=RAISED)
            win.pack(fill=BOTH)
        else:
            win = Toplevel()
            win.title('Import ext files')

        importdir=StringVar(); importdir.set(os.getcwd())
        Label(win,textvariable=importdir,bg='white',justify=RIGHT).pack(fill=BOTH,side=TOP)
        Button(win,text='Select Directory',command=getdir).pack(fill=BOTH,side=TOP)
        filetype=StringVar(); filetype.set('any')
        optmenu = Pmw.OptionMenu (win,
                labelpos = 'w',
                label_text = 'File Type:',
                menubutton_textvariable = filetype,
                items = self.extensions.keys(),
                menubutton_width = 10 )
        optmenu.pack(fill=BOTH,side=TOP)
        Button(win,text='Import',command=doimport).pack(fill=BOTH,side=TOP)
        Button(win,text='Cancel',command=close).pack(fill=BOTH,side=TOP)

        return
Import a series of external files in a folder to peat
Import a series of external files in a folder to peat
Import a series of external files in a folder to peat
def importFileset(self, DB, parentframe=None, callback=None):
        def getdir():
            import tkFileDialog, os
            d=tkFileDialog.askdirectory(initialdir=importdir.get(),title='Select directory files',
                                                mustexist=1,parent=self.parent.master)
            if d:
                importdir.set(d)
                return
        def doimport():
            idir = importdir.get()
            ext = filetype.get()
            if idir == None:
                return
            files = os.listdir(idir)
            okfiles = []
            for f in files:
                pth = os.path.join(idir,f)
                if os.path.isfile(pth):
                    if ext != 'any':
                        if os.path.splitext(pth)[1] not in self.extensions[ext]:
                            continue
                    okfiles.append(pth)
            print 'files to be used:', okfiles
            DB.addField('file', 'File')
            from Dialogs import PEATDialog
            self.pb=PEATDialog(self.parent.master, option='progressbar',
                                          message='Importing files')
            self.pb.update_progress(0)
            total = len(okfiles)
            row=0
            for f in okfiles:
                recname=os.path.basename(f)
                DB.addBlob(recname, 'file', f)
                print 'added %s as %s' %(f,recname)
                row=row+1
                c=float(row)/float(total)*100.0
                self.pb.update_progress(c)
            self.pb.close()
            if callback!=None:
                callback()
            return
        def close():
            win.destroy()
            return
        if parentframe!=None:
            win = Frame(master=parentframe,relief=RAISED)
            win.pack(fill=BOTH)
        else:
            win = Toplevel()
            win.title('Import ext files')
        importdir=StringVar(); importdir.set(os.getcwd())
        Label(win,textvariable=importdir,bg='white',justify=RIGHT).pack(fill=BOTH,side=TOP)
        Button(win,text='Select Directory',command=getdir).pack(fill=BOTH,side=TOP)
        filetype=StringVar(); filetype.set('any')
        optmenu = Pmw.OptionMenu (win,
                labelpos = 'w',
                label_text = 'File Type:',
                menubutton_textvariable = filetype,
                items = self.extensions.keys(),
                menubutton_width = 10 )
        optmenu.pack(fill=BOTH,side=TOP)
        Button(win,text='Import',command=doimport).pack(fill=BOTH,side=TOP)
        Button(win,text='Cancel',command=close).pack(fill=BOTH,side=TOP)
        return
def importFileset ( self , DB , parentframe = None , callback = None ) : def getdir ( ) : import tkFileDialog , os d = tkFileDialog . askdirectory ( initialdir = importdir . get ( ) , title = 'Select directory files' , mustexist = 1 , parent = self . parent . master ) if d : importdir . set ( d ) return def doimport ( ) : idir = importdir . get ( ) ext = filetype . get ( ) if idir == None : return files = os . listdir ( idir ) okfiles = [ ] for f in files : pth = os . path . join ( idir , f ) if os . path . isfile ( pth ) : if ext != 'any' : if os . path . splitext ( pth ) [ 1 ] not in self . extensions [ ext ] : continue okfiles . append ( pth ) print 'files to be used:' , okfiles DB . addField ( 'file' , 'File' ) from Dialogs import PEATDialog self . pb = PEATDialog ( self . parent . master , option = 'progressbar' , message = 'Importing files' ) self . pb . update_progress ( 0 ) total = len ( okfiles ) row = 0 for f in okfiles : recname = os . path . basename ( f ) DB . addBlob ( recname , 'file' , f ) print 'added %s as %s' % ( f , recname ) row = row + 1 c = float ( row ) / float ( total ) * 100.0 self . pb . update_progress ( c ) self . pb . close ( ) if callback != None : callback ( ) return def close ( ) : win . destroy ( ) return if parentframe != None : win = Frame ( master = parentframe , relief = RAISED ) win . pack ( fill = BOTH ) else : win = Toplevel ( ) win . title ( 'Import ext files' ) importdir = StringVar ( ) ; importdir . set ( os . getcwd ( ) ) Label ( win , textvariable = importdir , bg = 'white' , justify = RIGHT ) . pack ( fill = BOTH , side = TOP ) Button ( win , text = 'Select Directory' , command = getdir ) . pack ( fill = BOTH , side = TOP ) filetype = StringVar ( ) ; filetype . set ( 'any' ) optmenu = Pmw . OptionMenu ( win , labelpos = 'w' , label_text = 'File Type:' , menubutton_textvariable = filetype , items = self . extensions . keys ( ) , menubutton_width = 10 ) optmenu . pack ( fill = BOTH , side = TOP ) Button ( win , text = 'Import' , command = doimport ) . pack ( fill = BOTH , side = TOP ) Button ( win , text = 'Cancel' , command = close ) . pack ( fill = BOTH , side = TOP ) return
Import a series of external files in a folder to peat
Import a series of external files in a folder to peat
"""Import a series of external files in a folder to peat""" #iterate over filenames in folder and add one rec to DB for each file
self
DB
parentframe
callback