| 1 |  |  | # | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | # Copyright (c) 2015 SUSE Linux GmbH | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | # | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | # This program is free software; you can redistribute it and/or | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | # modify it under the terms of version 3 of the GNU General Public License as | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | # published by the Free Software Foundation. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | # | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | # This program is distributed in the hope that it will be useful, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | # but WITHOUT ANY WARRANTY; without even the implied warranty of | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | # GNU General Public License for more details. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | # | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | # You should have received a copy of the GNU General Public License | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | # along with this program; if not, contact SUSE LLC. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | # | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | # To contact SUSE about this file by physical or electronic mail, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | # you may find current contact information at www.suse.com | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | import datetime | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | import os.path | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | class FileUtil(object): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | 	def __init__(self, filename): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | 		# set the default variables | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | 		self.filename = filename | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  | 	def get_mtime(self, with_ms=False): | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  | 		"""Returns the last modify time | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  | 		:param bool with_ms: With or without milliseconds | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  | 		:return mixed(float|int): The last modify time | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  | 		""" | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  | 		if with_ms: | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  | 			return int(os.path.getmtime(self.filename)) | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  | 		return os.path.getmtime(self.filename) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | 	def get_mtime_format(self, formatstr): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 		"""Returns the last modify time as a string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 		:param str formatstr: Format string like: %Y-%m-%d %H:%M:%S | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 		:return str: Formatted string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 		""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 		# read the last modify time | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 		mtime = self.get_mtime() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 		return datetime.datetime.fromtimestamp( \ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 					mtime \ | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 49 |  |  | 				).strftime(formatstr) | 
            
                                                        
            
                                    
            
            
                | 50 |  |  |  |