def __init__(self, r, qii, qoi): """ Constructor od the class \param self Pointer on class \param r Pointer on Tkinker window \param qii Input queue \param qoi Output queue """ ## Pointer on TK window self.root = r self.root.title("Media DBase") self.root.geometry(("%dx%d") % (460, 320)) self.root.wm_iconbitmap('@./gnusk.xbm') self.root.protocol("WM_DELETE_WINDOW", self.qquit) self.root.resizable(0, 0) ## Input quee self.qi = qii ## Output quee self.qo = qoi ## Mounting sys class self.sysm = SysMnt() ## DB handle self.db = DBHand() ## New device detection activation self.lo = False ## Prename from file self.pname = Prename() ## Name of currently loading devices self.name = self.pname.getPrename()
def genNewInput(self, name, flP, mnt, qo=None): """ Inputs new line in DBase \param name Name of media given by user \param flP Path to sample \param mnt Mounted fs \param qo Output queue \param self Pointer on class """ # line in db: # heellhs;hash;date;./lists/helllhs.txt # name;hash;date;path to file list if qo != None: qo.put("Preparing...;0") # generating line to db ind = Indx() if qo != None: qo.put("Generating name;5") nm = ind.makeName(name, self) if qo != None: qo.put("Name ready;15") qo.put("Generating sample;20") s = SysMnt() s.ddSam(flP) if qo != None: qo.put("Sample done;25") qo.put("Generating hash;30") hs = ind.hashFile("./cache/check.bin") if qo != None: qo.put("Hash ready;40") qo.put("Testing if in DB;40") res = self.getByHash(hs) if res != None: if qo != None: qo.put("Already in DBase;100") return if qo != None: qo.put("Generating date;50") dt = ind.getTime() if qo != None: qo.put("Date ready;75") qo.put("Generating DB input;75") lst = ind.lstFiles(mnt) # Writting line in db if qo != None: qo.put("DB ready;85") fl = open(self.dbs, "a") fl.write("\n" + nm + ";" + hs + ";" + dt + ";" + self.lsts + "/" + nm + ".txt") fl.close() # Writting list of medium fl = open(self.lsts + "/" + nm + ".txt", "w") fl.write(lst) fl.close() if qo != None: qo.put("Generating booklet;90") it = self.getByName(nm) self.genBookl(it) if qo != None: qo.put(nm + " done;100")
def genNewInput(self,name,flP,mnt,qo=None): """ Inputs new line in DBase \param name Name of media given by user \param flP Path to sample \param mnt Mounted fs \param qo Output queue \param self Pointer on class """ # line in db: # heellhs;hash;date;./lists/helllhs.txt # name;hash;date;path to file list if qo != None: qo.put("Preparing...;0") # generating line to db ind=Indx() if qo != None: qo.put("Generating name;5") nm=ind.makeName(name,self) if qo != None: qo.put("Name ready;15") qo.put("Generating sample;20") s=SysMnt() s.ddSam(flP) if qo != None: qo.put("Sample done;25") qo.put("Generating hash;30") hs=ind.hashFile("./cache/check.bin") if qo != None: qo.put("Hash ready;40") qo.put("Testing if in DB;40") res=self.getByHash(hs) if res != None: if qo != None: qo.put("Already in DBase;100") return if qo != None: qo.put("Generating date;50") dt=ind.getTime() if qo != None: qo.put("Date ready;75") qo.put("Generating DB input;75") lst=ind.lstFiles(mnt) # Writting line in db if qo != None: qo.put("DB ready;85") fl=open(self.dbs,"a") fl.write("\n" + nm + ";" + hs + ";" + dt + ";" + self.lsts + "/" + nm + ".txt") fl.close() # Writting list of medium fl=open(self.lsts + "/" + nm + ".txt","w") fl.write(lst) fl.close() if qo != None: qo.put("Generating booklet;90") it=self.getByName(nm) self.genBookl(it) if qo != None: qo.put(nm + " done;100")
def __init__(self,r,qii,qoi): """ Constructor od the class \param self Pointer on class \param r Pointer on Tkinker window \param qii Input queue \param qoi Output queue """ ## Pointer on TK window self.root=r self.root.title("Media DBase") self.root.geometry(("%dx%d")%(460,320)) self.root.wm_iconbitmap('@./gnusk.xbm') self.root.protocol("WM_DELETE_WINDOW",self.qquit) self.root.resizable(0,0) ## Input quee self.qi=qii ## Output quee self.qo=qoi ## Mounting sys class self.sysm=SysMnt() ## DB handle self.db=DBHand() ## New device detection activation self.lo=False ## Prename from file self.pname=Prename() ## Name of currently loading devices self.name=self.pname.getPrename()
def genOut(qi,qo): """ Funkce vlákna \param qi Vstupní fronta \param qo Vstupní fronta """ while True: stri = "" try: stri=qi.get(True) except Empty: pass finally: if stri == "XXX": break elif stri.split(";")[0] == "DO": sysm=SysMnt() if sysm.tstMount(stri.split(";")[1]): db=DBHand() db.genNewInput(stri.split(";")[2],stri.split(";")[1],"./mnt/",qo) sysm.uMnt()
def genOut(qi, qo): """ Funkce vlákna \param qi Vstupní fronta \param qo Vstupní fronta """ while True: stri = "" try: stri = qi.get(True) except Empty: pass finally: if stri == "XXX": break elif stri.split(";")[0] == "DO": sysm = SysMnt() if sysm.tstMount(stri.split(";")[1]): db = DBHand() db.genNewInput( stri.split(";")[2], stri.split(";")[1], "./mnt/", qo) sysm.uMnt()
class App(object): """ \brief Class containing gui """ def __init__(self, r, qii, qoi): """ Constructor od the class \param self Pointer on class \param r Pointer on Tkinker window \param qii Input queue \param qoi Output queue """ ## Pointer on TK window self.root = r self.root.title("Media DBase") self.root.geometry(("%dx%d") % (460, 320)) self.root.wm_iconbitmap('@./gnusk.xbm') self.root.protocol("WM_DELETE_WINDOW", self.qquit) self.root.resizable(0, 0) ## Input quee self.qi = qii ## Output quee self.qo = qoi ## Mounting sys class self.sysm = SysMnt() ## DB handle self.db = DBHand() ## New device detection activation self.lo = False ## Prename from file self.pname = Prename() ## Name of currently loading devices self.name = self.pname.getPrename() def startListen(self): """ Method for starting listening to new media \param self Pointer on class """ if self.lo == False: ## list of dbs lines self.dvs = self.sysm.getList() self.beg.configure(text="Stop") self.lo = True else: self.beg.configure(text="Start") self.lo = False def listRes(self, reg="*"): """Method for listing the dbase into window \param self Pointer on class \param reg Regular expresion """ print reg w = self.v.get() self.tl.delete(0, END) ls = self.db.getList() for i in ls: if w == 1: try: m = re.search(reg, i['name'], re.IGNORECASE) except: m = "A" if m != "": self.tl.insert('end', i['name']) elif w == 2: if os.path.isfile(i['path']): f = open(i['path'], "r") cn = f.read() f.close() for lf in cn.split("\n"): ins = lf.replace("-", "") try: m = re.search(reg, ins, re.IGNORECASE) except: m = "A" if m != None: self.tl.insert('end', ins) elif w == 3: try: m = re.search(reg, i['date'], re.IGNORECASE) except: m = "A" if m != None: self.tl.insert('end', i['date']) def keyEn(self, evt): """Method for enter in entry box for name \param self Pointer on class \param evt Sended event """ if self.ew.get() == "": return self.listRes(self.ew.get()) def getList(self): """Method for generating a list and calling txt reader from OS to show user \param self Pointer on class """ self.db.buildListTxt("./list.txt") c = ["xdg-open", "list.txt"] proc = subprocess.Popen(c) def keyNm(self, evt): """Method for enter in entry box for name \param self Pointer on class \param evt Sended event """ if self.en.get() == "": return self.name = self.en.get() self.pname.setPrename(self.en.get()) print self.name def OnDub(self, event): """Method for getting event from listbox \param self Pointer on class \param event Sended event """ widget = event.widget selection = widget.curselection() value = widget.get(selection[0]) w = self.v.get() if w == 1: it = self.db.getByName(value) elif w == 2: it = self.db.getByContFls(value) elif w == 3: it = self.db.getByDate(value) itw = Tk() pw = mnItem(itw, it, self) pw.paintLayout() itw.mainloop() def paintLayout(self): """ Method painting main window \param self Pointer on class """ gpMan = LabelFrame(self.root, text="Service stop/start", padx=5, pady=5) gpMan.place(relx=0.01, rely=0.01) ## Beggining button self.beg = Button(gpMan, height=1, width=19, text="Start", command=self.startListen) self.beg.pack() gpMo = LabelFrame(self.root, text="List by", padx=2, pady=1) gpMo.place(relx=0.01, rely=0.22) ## Var telling what to choose self.v = IntVar() self.v.set(1) languages = [("Names", 1), ("Files", 2), ("Date", 3)] for txt, val in languages: Radiobutton(gpMo, text=txt, padx=0.5, variable=self.v, value=val, command=self.listRes).pack(side=LEFT) gpLst = LabelFrame(self.root, text="DBase listing", padx=5, pady=5) gpLst.place(relx=0.01, rely=0.38) ## Name of finded item self.ew = StringVar() self.ew.set("*") en = Entry(gpLst, width=21, textvariable=self.ew) en.pack(side=TOP) en.bind("<KeyPress>", self.keyEn) scrol = Scrollbar(gpLst) ## List of DB items self.tl = Listbox(gpLst, height=9, width=21, bd=0, yscrollcommand=scrol.set) self.tl.pack(side=LEFT) scrol.pack(side=RIGHT, fill=Y) scrol.config(command=self.tl.yview) self.tl.bind("<Double-Button-1>", self.OnDub) self.listRes() Button(self.root, height=1, width=23, text="Get a list", command=self.getList).place(relx=0.5, rely=0.07) ## Name of new media self.en = StringVar() self.en.set(self.name) nn = Entry(self.root, width=15, textvariable=self.en) nn.place(relx=0.68, rely=0.2) nn.bind("<KeyPress>", self.keyNm) Label(self.root, height=1, text="Prename:").place(relx=0.48, rely=0.2) # Notices to user gpTh = LabelFrame(self.root, text="Just done:", padx=5, pady=5) gpTh.place(relx=0.48, rely=0.3) scrollbar = Scrollbar(gpTh) ## List for user notification self.to = Listbox(gpTh, height=8, width=24, bd=0, yscrollcommand=scrollbar.set) self.to.pack(side=LEFT) self.to.insert('end', "Nothing so far...") scrollbar.pack(side=RIGHT, fill=Y) scrollbar.config(command=self.to.yview) # Progress Label(self.root, height=1, width=21, text="Medium indexing:").place(relx=0.42, rely=0.82) ## Pointer on current progress self.progressbar = ttk.Progressbar(orient=HORIZONTAL, length=200, mode='determinate') self.progressbar.place(relx=0.5, rely=0.91) self.progressbar["value"] = 0 self.progressbar["maximum"] = 100 self.loadProgs(self.qo) def loadProgs(self, qc): """ Method for progressbar changes and messages passing to user \param self Ukazatel na objekt \param qc Výstupní fronta """ try: if self.lo == True: # finding new devices, if found, send to index nw = self.sysm.getList() if self.dvs != nw: for it in nw: if it not in self.dvs: qi.put("DO;" + it + ";" + self.name) self.dvs = nw # progress bar and notices to user st = qc.get(0) mes = st.split(";")[0] loa = int(st.split(";")[1]) self.to.insert('end', mes) self.to.select_clear(self.to.size() - 2) self.to.yview(END) self.progressbar["value"] = loa if loa == 100: self.listRes() except Empty: pass finally: self.root.after(1000, self.loadProgs, qc) def qquit(self): """ Metoda pro ukončení okna Je nutné vypnout vlákno, které vykonává příkazy na pozadí okna \param self Ukazatel na objekt """ self.qi.put("XXX") self.root.destroy()
class App(object): """ \brief Class containing gui """ def __init__(self,r,qii,qoi): """ Constructor od the class \param self Pointer on class \param r Pointer on Tkinker window \param qii Input queue \param qoi Output queue """ ## Pointer on TK window self.root=r self.root.title("Media DBase") self.root.geometry(("%dx%d")%(460,320)) self.root.wm_iconbitmap('@./gnusk.xbm') self.root.protocol("WM_DELETE_WINDOW",self.qquit) self.root.resizable(0,0) ## Input quee self.qi=qii ## Output quee self.qo=qoi ## Mounting sys class self.sysm=SysMnt() ## DB handle self.db=DBHand() ## New device detection activation self.lo=False ## Prename from file self.pname=Prename() ## Name of currently loading devices self.name=self.pname.getPrename() def startListen(self): """ Method for starting listening to new media \param self Pointer on class """ if self.lo == False: ## list of dbs lines self.dvs=self.sysm.getList() self.beg.configure(text="Stop") self.lo=True else: self.beg.configure(text="Start") self.lo=False def listRes(self,reg="*"): """Method for listing the dbase into window \param self Pointer on class \param reg Regular expresion """ print reg w=self.v.get() self.tl.delete(0, END) ls=self.db.getList() for i in ls: if w == 1: try: m = re.search(reg,i['name'],re.IGNORECASE) except: m = "A" if m != "": self.tl.insert('end', i['name']) elif w == 2: if os.path.isfile(i['path']): f=open(i['path'],"r") cn=f.read() f.close() for lf in cn.split("\n"): ins=lf.replace("-","") try: m = re.search(reg,ins,re.IGNORECASE) except: m = "A" if m != None: self.tl.insert('end', ins) elif w == 3: try: m = re.search(reg,i['date'],re.IGNORECASE) except: m = "A" if m != None: self.tl.insert('end', i['date']) def keyEn(self,evt): """Method for enter in entry box for name \param self Pointer on class \param evt Sended event """ if self.ew.get() == "": return self.listRes(self.ew.get()) def getList(self): """Method for generating a list and calling txt reader from OS to show user \param self Pointer on class """ self.db.buildListTxt("./list.txt") c=["xdg-open","list.txt"] proc = subprocess.Popen(c) def keyNm(self,evt): """Method for enter in entry box for name \param self Pointer on class \param evt Sended event """ if self.en.get() == "": return self.name=self.en.get() self.pname.setPrename(self.en.get()) print self.name def OnDub(self,event): """Method for getting event from listbox \param self Pointer on class \param event Sended event """ widget = event.widget selection=widget.curselection() value = widget.get(selection[0]) w=self.v.get() if w == 1: it=self.db.getByName(value) elif w == 2: it=self.db.getByContFls(value) elif w == 3: it=self.db.getByDate(value) itw = Tk() pw = mnItem(itw,it,self) pw.paintLayout() itw.mainloop() def paintLayout(self): """ Method painting main window \param self Pointer on class """ gpMan = LabelFrame(self.root, text="Service stop/start", padx=5, pady=5) gpMan.place(relx=0.01, rely=0.01) ## Beggining button self.beg=Button(gpMan,height=1, width=19,text="Start",command=self.startListen) self.beg.pack() gpMo = LabelFrame(self.root, text="List by", padx=2, pady=1) gpMo.place(relx=0.01, rely=0.22) ## Var telling what to choose self.v = IntVar() self.v.set(1) languages = [ ("Names",1), ("Files",2), ("Date",3) ] for txt, val in languages: Radiobutton(gpMo, text=txt, padx = 0.5, variable=self.v, value=val,command=self.listRes).pack(side=LEFT) gpLst = LabelFrame(self.root, text="DBase listing", padx=5, pady=5) gpLst.place(relx=0.01, rely=0.38) ## Name of finded item self.ew=StringVar() self.ew.set("*") en=Entry(gpLst,width=21,textvariable=self.ew) en.pack(side=TOP) en.bind("<KeyPress>", self.keyEn) scrol= Scrollbar(gpLst) ## List of DB items self.tl = Listbox(gpLst,height=9, width=21, bd=0, yscrollcommand=scrol.set) self.tl.pack(side=LEFT) scrol.pack(side=RIGHT, fill=Y) scrol.config(command=self.tl.yview) self.tl.bind("<Double-Button-1>", self.OnDub) self.listRes() Button(self.root,height=1, width=23,text="Get a list",command=self.getList).place(relx=0.5, rely=0.07) ## Name of new media self.en=StringVar() self.en.set(self.name) nn=Entry(self.root,width=15,textvariable=self.en) nn.place(relx=0.68, rely=0.2) nn.bind("<KeyPress>", self.keyNm) Label(self.root,height=1,text="Prename:").place(relx=0.48, rely=0.2) # Notices to user gpTh = LabelFrame(self.root, text="Just done:", padx=5, pady=5) gpTh.place(relx=0.48, rely=0.3) scrollbar = Scrollbar(gpTh) ## List for user notification self.to = Listbox(gpTh,height=8, width=24, bd=0, yscrollcommand=scrollbar.set) self.to.pack(side=LEFT) self.to.insert('end', "Nothing so far...") scrollbar.pack(side=RIGHT, fill=Y) scrollbar.config(command=self.to.yview) # Progress Label(self.root,height=1, width=21,text="Medium indexing:").place(relx=0.42, rely=0.82) ## Pointer on current progress self.progressbar = ttk.Progressbar(orient=HORIZONTAL, length=200, mode='determinate') self.progressbar.place(relx=0.5, rely=0.91) self.progressbar["value"]=0 self.progressbar["maximum"]=100 self.loadProgs(self.qo) def loadProgs(self,qc): """ Method for progressbar changes and messages passing to user \param self Ukazatel na objekt \param qc Výstupní fronta """ try: if self.lo == True: # finding new devices, if found, send to index nw=self.sysm.getList() if self.dvs != nw: for it in nw: if it not in self.dvs: qi.put("DO;" + it + ";" + self.name) self.dvs=nw # progress bar and notices to user st=qc.get(0) mes=st.split(";")[0] loa=int(st.split(";")[1]) self.to.insert('end',mes) self.to.select_clear(self.to.size()-2) self.to.yview(END) self.progressbar["value"]=loa if loa == 100: self.listRes() except Empty: pass finally: self.root.after(1000,self.loadProgs,qc) def qquit(self): """ Metoda pro ukončení okna Je nutné vypnout vlákno, které vykonává příkazy na pozadí okna \param self Ukazatel na objekt """ self.qi.put("XXX") self.root.destroy()