Windows 7 Forums

Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: Python script not processing files

06 Dec 2014   #11
Pyprohly

Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
 
 

Quote   Quote: Originally Posted by MilesAhead View Post
I should have posted a link to get you started:
https://www.python.org/about/help/
If you ever plan to program, I do highly recommend Python.


Quote   Quote: Originally Posted by Docfxit View Post
Error: [Errno 2] No such file or directory: 'C:\\Programs\\CommuniGate Files\\Sy
stemLogs2014-12-05.log'
Error message; excellant.
I did actually get the same error myself. I was waiting for you to replicate this error, so I know you're on track.

Quote   Quote: Originally Posted by Docfxit View Post
There should be a backslash between the "s" and the "2". Since it is not a good practice to have a trailing backslash it would be great if you could please help me by suggesting how to code that backslash in the script.
Correct, there should be a backslash between those characters and it is not your fault that is doesn't. It's the programmers.

In line 1170, paths are joined (and quite terribly too, I will add). It lazily squashes two strings together when it should really join the two strings as a path. This is why backslashes are missing. A very sloppy mistake if you ask me.

Code:
fnamewithpath = logdir + fname
Your mission: locate the above line (at 1170) and replace it with the following:
Code:
fnamewithpath = join( logdir, fname )
(Note: This join function is an attribute of os.path, which was imported at the beginning of the script with: from os.path import *)
(Important Note: Indentation is compulsory/necessary in Python. So make sure any whitespace to the left of a line is preserved or you will have problems)


Also, about your batch file again, the cd command is very optional. There is no use in it if all the paths you are working with are already written in the Python script.


My System SpecsSystem Spec
.
06 Dec 2014   #12
Docfxit

Win 7 Ultimate x32, x64, Win 7 Pro x32, x64 Win 7 Home x64, XP Pro sp3
 
 

That is really really nice of you to help me get the coding correct.

I feel much better now that it follows the standard way of supplying a path.

I have applied your suggestion and removed the double backslash at the end of the path.

It runs without errors.

Now If I only knew why it isn't outputting data in the email correctly it would be great.

I have uploaded a test file just in case you would like to take it for a spin.

Thank you,

Docfxit

PS: Currently the test file below needs to be in a folder called:
logdir = "C:\Programs\CommuniGate Files\SystemLogs"

Of course you could change that line in the script to any folder you like.


Attached Files
File Type: log 2014-12-05Test.log (632.9 KB, 1 views)
My System SpecsSystem Spec
07 Dec 2014   #13
Pyprohly

Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
 
 

I'd be happy to take the script 'for a spin' for you, but with backslashes missing all over the version I have of your script, I can't be sure if the output I'm getting is right.

Please remove any personal information-al inclusions you've made to your script and repost the Python script here in a zip file, It'll help me better debug the script for you.


Also, if you would like to lightly explain what the script is actually meant to do, it'll save myself a bit of reading.


Meanwhile, another path related problem resides on line 1191, similar a problem to which line 1170 had with joining paths.
The corrected code for 1191 should be:
Code:
outfilename = join( submitdir, "ls" + str(time.time()) + "-" + str(os.getpid()) )
Assuming the output file name is supposed to look something like
ls1417926446.033319-7848.sub
.
My System SpecsSystem Spec
.

07 Dec 2014   #14
MilesAhead

Windows 7 32 bit
 
 

Quote   Quote: Originally Posted by Pyprohly View Post
If you ever plan to program, I do highly recommend Python.
I've been programming, mostly as an avocation, since 1986. Lately I've been doing mostly hotkey utilities in AHK. I dabbled in Python for a bit in the past. I downloaded the ActivePython 3.x installer in case I decide to brush up.

The only C++ program I've written in a long time is MD5Hash. It's just too much work to do it for fun unless there's some reason to use it(such as a fast MD5Sum routine I found in that case.) Plus I had to try the Lamda Expressions just for grins.
My System SpecsSystem Spec
07 Dec 2014   #15
Docfxit

Win 7 Ultimate x32, x64, Win 7 Pro x32, x64 Win 7 Home x64, XP Pro sp3
 
 

Quote   Quote: Originally Posted by Pyprohly View Post
I'd be happy to take the script 'for a spin' for you, but with backslashes missing all over the version I have of your script, I can't be sure if the output I'm getting is right.
I'd be happy to attach the zip file.

Quote   Quote: Originally Posted by Pyprohly View Post
Please remove any personal information-al inclusions you've made to your script and repost the Python script here in a zip file, It'll help me better debug the script for you.


Also, if you would like to lightly explain what the script is actually meant to do, it'll save myself a bit of reading.
The script reads the log files from the day before the script runs. It summarizes what has happened in the log files. And sends an email with the summary. An example of what the summary looks like is in the file EmailExample.zip

Quote   Quote: Originally Posted by Pyprohly View Post

Meanwhile, another path related problem resides on line 1191, similar a problem to which line 1170 had with joining paths.
The corrected code for 1191 should be:
Code:
outfilename = join( submitdir, "ls" + str(time.time()) + "-" + str(os.getpid()) )
Assuming the output file name is supposed to look something like
ls1417926446.033319-7848.sub
.

The input file is called logsummarytest.zip

Thank you very much for taking a look at it,

Docfxit


Attached Files
File Type: zip LogSummaryTest.zip (9.3 KB, 3 views)
File Type: zip EmailExample.zip (1.2 KB, 1 views)
My System SpecsSystem Spec
08 Dec 2014   #16
Pyprohly

Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
 
 

Quote   Quote: Originally Posted by Docfxit
And sends an email with the summary.
If you are under the impression that this Python script sends an Email, it attempts nothing of the sort.

The only output this script yields is a text file. Is this not the sort of output are you are after?


If the test log file you attached in post 12 is fed to the script as input, what should the output file look like? To me it looks nothing like what EmailExample.sum is, which I'm guessing it should.

It appears a function named "generateReport" (in the "CGPLogReporter" class) always returns an empty string which should instead (as the function name implies) contain the generated report summary.

I'll examine further and see if I can't find out why.
My System SpecsSystem Spec
08 Dec 2014   #17
Docfxit

Win 7 Ultimate x32, x64, Win 7 Pro x32, x64 Win 7 Home x64, XP Pro sp3
 
 

Quote   Quote: Originally Posted by Pyprohly View Post
Quote   Quote: Originally Posted by Docfxit
And sends an email with the summary.
If you are under the impression that this Python script sends an Email, it attempts nothing of the sort.

The only output this script yields is a text file. Is this not the sort of output are you are after?
After getting your post I looked into how this could be possible. I found that when a text file is put into the submitdir the server automatically sends it out as an email.

Quote   Quote: Originally Posted by Pyprohly View Post
If the test log file you attached in post 12 is fed to the script as input, what should the output file look like? To me it looks nothing like what EmailExample.sum is, which I'm guessing it should.
I'm guessing what you are seeing is a detail of the log. I'm guessing (Maybe in "generateReport" the detail gets sorted and summarized.

Quote   Quote: Originally Posted by Pyprohly View Post

It appears a function named "generateReport" (in the "CGPLogReporter" class) always returns an empty string which should instead (as the function name implies) contain the generated report summary.
I'm guessing that is where the problem is. I think once you know why it returns an empty string you will know why it doesn't produce the output text file.

Quote   Quote: Originally Posted by Pyprohly View Post

I'll examine further and see if I can't find out why.
Thank you very much for looking at it.

Docfxit
My System SpecsSystem Spec
08 Dec 2014   #18
Docfxit

Win 7 Ultimate x32, x64, Win 7 Pro x32, x64 Win 7 Home x64, XP Pro sp3
 
 

I just remembered the script only processes log files from The day before it's run

So if it's run today 12/8/2014 it will process log files from 12/7/2014
I don't know if it uses the file name for the date or the date the file was created.

Docfxit
My System SpecsSystem Spec
09 Dec 2014   #19
Pyprohly

Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
 
 

Quote   Quote: Originally Posted by Docfxit View Post
I just remembered the script only processes log files from The day before it's run
I am aware of this and have had to rename the test log file each day accordingly -- the script checks the file names date rather than checking the file creation date which is odd and annoying.

Also, an argument can be passed to override the days offset. 1 (default) is yesterday, 2 is the day before yesterday, and so on.


I've found out why the generateReport function keeps returning an empty string.

Lines 831 - 837 read:
Code:
        stats = {}
        spammers = []
        unknowns = {}
        blacklists = {}
        spamtraps = {}
        contentRejections = {}
        relayRejections = {}
The above braces (dictionary data type) and brackets (a list data type) are all, as you can see, empty. It seems the genorate report function only acts upon the data that is supposed to be within these braces. But what stumps me is that there is absolutely nothing in these braces and there never will be. Thus the generateReport function always returns an empty string no matter what file the script reads!

I have not a single clue of how EmailExample was created using this script the way it is exactly.

Something should be in at least some of all these pairs of braces and brackets and I'm not sure what, but unless you fill at least some of these braces with god-knows-what, you're left with the only option of contacting the developer of this script and getting support from them instead.
My System SpecsSystem Spec
09 Dec 2014   #20
MilesAhead

Windows 7 32 bit
 
 

Quote   Quote: Originally Posted by Pyprohly View Post
The above braces (dictionary data type) and brackets (a list data type) are all, as you can see, empty. It seems the genorate report function only acts upon the data that is supposed to be within these braces. But what stumps me is that there is absolutely nothing in these braces and there never will be. Thus the generateReport function always returns an empty string no matter what file the script reads!
It looks like the assignments are just placeholders to be filled in later. IOW equivalent to func myfunc { //implement myfunc here } in C++
My System SpecsSystem Spec
Reply

 Python script not processing files




Thread Tools Search this Thread
Search this Thread:

Advanced Search




Similar help and support threads
Thread Forum
VB script: Rename all files in a folder to a specified prefix
Hi, I'm trying to find help in entering paths and prefix's in my vb script. I am of course a newbie to visual basic and don't know where to enter the path and wording for prefix. Any help would be most appreciated. Rich
General Discussion
Excel 2013 - Processor overheats when processing large files
Hello, I have a very rare issue here. I'm trying to convert a normal xlsx file into a csv file. In the xlsx file there are normal columns and rows, nothing strange, nor formatting or something pretty, only colums and rows with products plain information. I've received these files via...
Microsoft Office
Script help - downloading files from multiple computers
Hi all, So i am new to scripting and I am having issues figuring out where to start. Hope someone can help. I have 20+ computers that I connect to and grab .txt files. I would like to create a bat file that will connect to the computers and download the files to my local. This will save me...
General Discussion
How to script a daily copy of files w/dt being name of archive folder
Hello, I need to figure out a Windows 7 script to copy/archive files which are located in a specific folder. It needs to copy daily to an archive folder, with the script creating the archive folder as MM-DD-YY (being that day's date that is being archived) before it archives the files to that...
General Discussion
A script to automate moving files off C: prior to backup?
I back up my files and system image weekly. I move the recorded TV shows (broadcast TV, nothing illegal) before that from my hard drive onto an external drive. Another drive in the same cabinet does the backup. It saves time and I won't want those files after a disc failure anyway. It would be...
General Discussion
looking for cmd script to unhide files
at one point i had a virus on a thumbdrive, it would hide all the files in it and say it was un usable data, if you said view hidden files, they would all appear. i had figured out a dll to run in cmd that would unhide the files that where not meant to be hidden such as windows .trashes etc. i had...
System Security


Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 04:45.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App