473,394 Members | 1,778 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Logfile for my App not "rewriting"

Hello,

I have a small app I am creating to crawl a directory and check that
if it is moved to another a location it's path will not break a
character limit. Usually the Windows path limit.

Now the script is working but every time I want to scan again I have
to restart for the log files to be written. I want to just be able to
change the parameter as I please and click scan without having to
restart the app for the log file to change.
(I am new to programming so the code could be untidy for want of a
better word.)

Here's the code:

###Code###

#file/path finder
#indentation value 4
import os,glob
import Tkinter as tk
# Class to create the Application and UI
class Theapp:
def __init__(self):
# Create GUI parts. Will allign later with grid
self.mainWindow = tk.Tk()
self.mainWindow.geometry("%dx%d%+d%+d" % (700, 400, 0, 0)) #
(width,height, x, y)
self.labAll = tk.Label(self.mainWindow, text="All Files/
Folders:")
self.labVi = tk.Label(self.mainWindow, text="Violating Files/
Folders:")

#Create a sub-frame containing textbox and scrollbar for All
files scanned display
self.allTxtf = tk.Frame(self.mainWindow, width=700,
height=164)
self.scrlr1 = tk.Scrollbar(self.allTxtf)
self.txtBoxall = tk.Text(self.allTxtf, wrap=tk.CHAR,
yscrollcommand=self.scrlr1.set, width=700, height=164)
self.scrlr1.config(command = self.txtBoxall.yview)

#Create another sub-frame containing textbox and scrollbar for
the Violating files display
self.viTxtf = tk.Frame(self.mainWindow, width=700, height=164)
self.scrlr2 = tk.Scrollbar(self.viTxtf)
self. txtBoxvi = tk.Text(self.viTxtf, wrap=tk.CHAR,
yscrollcommand=self.scrlr2.set, width=700, height=164)
self.scrlr2.config(command = self.txtBoxvi.yview)

#Create another sub-frame to contain the controls
self.ctrlFrame = tk.Frame(self.mainWindow, width=700,
height=72)
self.labDir = tk.Label(self.ctrlFrame, text="Dir:")
self.entDir = tk.Entry(self.ctrlFrame)
self.labTardir = tk.Label(self.ctrlFrame, text="Target Dir:")
self.entTardir = tk.Entry(self.ctrlFrame)
self.labChar = tk.Label(self.ctrlFrame, text="Char. Limit:")
self.entChar = tk.Entry(self.ctrlFrame)
self.labVi2 = tk.Label(self.ctrlFrame, text="Violations: ")
self.btFind = tk.Button(self.ctrlFrame, text="Scan", command =
self.fillboxes)
self.btExit = tk.Button(self.ctrlFrame, text="Exit", command =
self.quitEvent)

#Use tkinter's grid geometry manager to allign and display the
GUI
self.mainWindow.grid()

#Change weight to allow resize
self.mainWindow.grid_rowconfigure(1, weight=1)
self.mainWindow.grid_rowconfigure(3, weight=1)
self.mainWindow.grid_columnconfigure(0, weight=1)

self.allTxtf.grid_rowconfigure(0, weight=1)
self.allTxtf.grid_columnconfigure(0, weight=1)
self.allTxtf.grid_columnconfigure(1, weight=0)

self.viTxtf.grid_rowconfigure(0, weight=1)
self.viTxtf.grid_columnconfigure(0, weight=1)
self.viTxtf.grid_columnconfigure(1, weight=0)

self.ctrlFrame.grid_columnconfigure(1, weight=1)
self.ctrlFrame.grid_columnconfigure(3, weight=1)
self.ctrlFrame.grid_columnconfigure(5, weight=1)

#Frist allign the 3 main frames
self.labAll.grid(row=0, column=0)
self.allTxtf.grid(row=1, column=0)
self.labVi.grid(row=2, column=0)
self.viTxtf.grid(row=3, column=0)
self.ctrlFrame.grid(row=4, column=0)
#Now allign the content of allTxtf
self.txtBoxall.grid(row=0, column=0)
self.scrlr1.grid(row=0, column=1, sticky=tk.N + tk.S)
#Now allign the content for viTxtf
self.txtBoxvi.grid(row=0, column=0)
self.scrlr2.grid(row=0, column=1, sticky=tk.N + tk.S)
#Now allign the content for ctrlFrame
self.labDir.grid(row=0, column=0, sticky=tk.E)
self.entDir.grid(row=0, column=1)
self.labTardir.grid(row=0, column=2)
self.entTardir.grid(row=0, column=3)
self.labChar.grid(row=0, column=4, sticky=tk.E)
self.entChar.grid(row=0, column=5)
self.labVi2.grid(row=0, column=6)
self.btFind.grid(row=0, column=7)
self.btExit.grid(row=0, column=8)
self.entChar.insert(0, "254") #Insert default value

def findallfiles(self, base):
self.results = []
for root,dirs,files in os.walk(base):
os.chdir(root)
self.scan = glob.glob("*")
for r in self.scan:
if root[-1] == "\\":
self.results.append(root + r)
else:
self.results.append(root + "\\" + r)
return self.results
def fillboxes(self):
os.remove('viFiles.txt')
print "logfile deleted"
self.txtBoxall.delete(1.0, tk.END)
self.txtBoxvi.delete(1.0, tk.END)
self.logfile = file("viFiles.txt", "w")
print "logfiles created"
self.dispresults = self.findallfiles(self.entDir.get())
index = 0
lenghth = 0
dif = 0
#Debug text input to command prompt
print "Dir: " + self.entDir.get() + "\n" + "Tar: " +
self.entTardir.get() + "\n" + "Char: " + self.entChar.get() + "\n"
for i in self.dispresults:
self.txtBoxall.insert(tk.END, i + "\n")
length = len(i) + len(self.entTardir.get()) -
len(self.entDir.get())
if length int(self.entChar.get()):
index += 1
txt = "Violations: " + str(index)
dif = length - int(self.entChar.get())
self.logfile.write(i + "\n" + "\n" + "Violating File
#: " + str(index) + "\n" + "Shorten by: " + str(dif) + "\n" + "\n" +
"---------------------------------" + "\n")
self.txtBoxvi.insert(tk.END, i + "\n")
self.labVi2.configure(text=txt)
self.logfile.close()

def quitEvent(self):
raise SystemExit
if __name__ == "__main__":
app = Theapp()
app.mainWindow.mainloop()

###End Code###

TIA
Adam

Mar 10 '07 #1
0 1507

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Larry R Harrison Jr | last post by:
I have them working now, courtesy of the link given in the prior thread--the HVMenu over at Dynamic Drive myself. http://www.dynamicdrive.com I have them working as side-bar menus, not...
26
by: Michel Rouzic | last post by:
I have a binary file used to store the values of variables in order to use them again. I easily know whether the file exists or not, but the problem is, in case the program has been earlier...
4
by: Bill Borg | last post by:
Hello, I have a large commerce app, hosted for several hundred companies (i.e. each "company" is a small business selling something through my site, independent of all the others). Each...
17
by: Alan Silver | last post by:
Hello, I have a page which I am converting to use themes. The page has an HTML <input type="image"> element that is used to post to another page. I would like to replace this with a server...
23
by: steve.j.donovan | last post by:
Hi guys, We have the following macro: #define NEXT(type,p) (*((type*)(p))++) It provides a way to poke variable sized data into an array of pcode for a simple VM. e.g,
4
by: mainargv | last post by:
hi How do you rewrite codes with " ... va_list va_start va_etc", so that simple c compiler don't have to deal with them. I have written a simple c->verilog compiler but it can't deal with...
10
by: not_a_commie | last post by:
I've seen studies before showing that it is better to rewrite code when more than 25% (or whatever) of the code needs to be changed. I can't seem to locate any references for that at the moment. Do...
4
by: Klaus Jensen | last post by:
Hi I created code to allow me to rewrite urls from global.asax, so that if the incoming Url is for instance: /Hats/ReallyCoolHat.aspx ....I look up ReallyCoolHat in the products table and...
4
by: k3pp0 | last post by:
Hey. I've got a very basic newbie question, I hope you can understand me. Sorry for asking it, first of all. I see a lot of sites (e.g. communities) with a url-structure like this:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.