ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/ns_dev/Python/learning/Log_file_manip.py
Revision: 8
Committed: Sat May 5 04:21:19 2012 UTC (13 years, 10 months ago) by ninoborges
Content type: text/x-python
Original Path: Python/NinoCode/learning/Log_file_manip.py
File size: 1913 byte(s)
Log Message:
Initial Import

File Contents

# User Rev Content
1 ninoborges 8 ## Log_File Manipulation
2     ## EBorges
3    
4     ## Function: determinLogFile
5     ## Purpose: This function will determin the location and the name of the log file.
6     ## Arguments: fileName - The name of the log file.
7     ## userSpecific - Set to 1 if log file stored in the user's netchk dir, 0 if stored globally
8     ## echo - set to 1 to also echo the logEntry string to stdout
9     ## Returns: Log file object. Its path and name.
10     def determineLogFile(fileName,userSpecific=0,echo=0):
11     if userSpecific == 1:
12     # Since user specific, pull user's log directory from the registry
13     # ...
14     hkey = OpenKey( HKEY_CURRENT_USER, 'Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders' )
15     AppData = QueryValueEx( hkey, 'Local AppData' )
16     logDir = AppData[0] + '\\McGuireWoods LLP\\NetChk'
17     else:
18     # Since not user specific, use the global log directory
19     WinDir = os.environ['SystemDrive']
20     logDir = WinDir + '\\NetChk'
21     logFileName = logDir + '\\' + fileName
22     return logFileName
23    
24     ## Function: addToLogFile
25     ## Purpose: This function will add one entry to the log file stating that the reminder was run and log the date.
26     ## This way checkLastRun will look to this file to determin if a remind routine should be run.
27     def addToLogFile(self, logFile, logEntry, echo=0 ):
28     """This function will add one entry to the log file stating that the reminder was run and log the date.
29     This way checkLastRun will look to this file to determin if a remind routine should be run."""
30     try:
31     logFile = open( logFileName, 'a' )
32     except IOError:
33     os.makedirs(logDir)
34     logFile = open( logFileName, 'a' )
35     logFile.write( time.strftime('%d/%m/%Y\t%H:%M:%S -\t',time.localtime()) + logEntry + '\n' )
36     if echo == 1: print logEntry
37     logFile.close()