Commits

Nathan Durnan committed 559c6ba

Begin implementing options code.
Display (no arguments) is working.

  • Participants
  • Parent commits 5fa4370
  • Branches development

Comments (0)

Files changed (1)

 # Import Modules
 #------------------------------------------------------------------------------
 import os	#required for filesystem access methods
+import time	#required for time functions
 
 #_ end of imported modules_____________________________________________________
 
 # begin command/function help text	
 	'''Save or restore file modification times.'''
 # end help text
-	ui.debug("executing timestamp_mod function\n")
+	ui.note("executing timestamp_mod function\n")
 	
 	#Access timestamp record file.
 	file_TimeStampRecords=''
-	ui.debug('accessing .hgtimestamp file...\n')
+	ui.note('accessing .hgtimestamp file...\n')
 	try:
 		file_TimeStampRecords = file(repo.root+'/.hgtimestamp', 'r')
 	except:
-		ui.warn('Error: Could not find/read .hgtimestamp file!\n')
+		ui.warn('Error accessing .hgtimestamp file!\n')
 		return
 	
 	#initialize data objects.
-	l_TimeStamp_dict = dict()
-	l_TimeStamp_list = list()
+	TimeStamp_dict = dict()
+	TimeStamp_list = list()
 	for line in file_TimeStampRecords.readlines():
 		#read the data from the line. (CSV format: [FileName],[ModificationTime])
 		try:
-			ls_file_Name, ls_file_ModTime = line.strip().split(',')
+			fileName, fileModTime = line.strip().split(',')
 		except:
 			#split failed, so check for an entry w/o a timestamp.
 			if (len(line)>0):
 				#data present, but missing timestamp?
-				ls_file_Name = line.strip()
-				ls_file_ModTime = str(-1)
+				fileName = line.strip()
+				fileModTime = str(-1)
 			#end of check line length non-zero.
 			
-		if (len(ls_file_Name)>0):		
-			l_TimeStamp_dict[ls_file_Name] = float(ls_file_ModTime)
-			l_TimeStamp_list.append(ls_file_Name)
-			ui.debug('fileName: '+ls_file_Name+'\t file_ModTime: '+ls_file_ModTime+'\n')
+		if (len(fileName)>0):		
+			TimeStamp_dict[fileName] = float(fileModTime)
+			TimeStamp_list.append(fileName)
+			ui.debug('fileName: '+fileName+'\t fileModTime: '+fileModTime+'\n')
 		#end of check file name length non-zero.
 	
 	#end of readlines from record file.
 	
-	
-	
-	
+	#Check for command optional argument
+	if opts['save']:
+		#Save
+		ui.note('saving timestamps...\n')
+	elif opts['restore']:
+		#Restore
+		ui.note('restoring timestamps...\n')
+	else:
+		#no options, just display data in output status
+		ui.note('displaying timestamps...\n')
+        for fileName in TimeStamp_list:
+			#retrieve recorded time and make sure it is in the right datatype
+            fileModTime=float(TimeStamp_dict[fileName])
+			#check for valid timestamp
+            if (fileModTime>=0):
+				#valid timestamp detected!
+				#display timestamp using local time adjustment.
+                ui.status(time.strftime("%Y.%m.%d %H:%M:%S", time.localtime(fileModTime)), " \t", fileName, "\n")
+            else:
+				#no valid timestamp recorded, skip this file.
+                ui.debug(fileName, ' skipped\n')
+			#end of check for valid timestamp
+			
+		#end of filenames in list
+		
+	#end of check command optional argument
 	
 	file_TimeStampRecords.close()