1#!/usr/bin/env python 2############################################################################### 3# # 4# fileEntity.py # 5# # 6# Represent a file / folder with path etc # 7# # 8# Copyright (C) Michael Imelfort # 9# # 10############################################################################### 11# # 12# This program is free software: you can redistribute it and/or modify # 13# it under the terms of the GNU General Public License as published by # 14# the Free Software Foundation, either version 3 of the License, or # 15# (at your option) any later version. # 16# # 17# This program is distributed in the hope that it will be useful, # 18# but WITHOUT ANY WARRANTY; without even the implied warranty of # 19# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 20# GNU General Public License for more details. # 21# # 22# You should have received a copy of the GNU General Public License # 23# along with this program. If not, see <http://www.gnu.org/licenses/>. # 24# # 25############################################################################### 26 27__author__ = "Michael Imelfort" 28__copyright__ = "Copyright 2014" 29__credits__ = ["Michael Imelfort"] 30__license__ = "GPLv3" 31__version__ = "0.1.0" 32__maintainer__ = "Michael Imelfort" 33__email__ = "mike@mikeimelfort.com" 34__status__ = "Beta" 35 36############################################################################### 37############################################################################### 38############################################################################### 39############################################################################### 40 41# system includes 42import sys 43import os 44 45# local includes 46 47############################################################################### 48############################################################################### 49############################################################################### 50############################################################################### 51 52class FileEntity(object): 53 """Basic file entity""" 54 def __init__(self, 55 name, # the name of the entity on the file system ( Full path to root dir if id: ROOT) 56 path, # the local path to this entity 57 parent, # the entity (type == 'dir') that contains this. ( None for id: ROOT ) 58 hashd, # hash of the entity if type == 'file' 59 size # size of the file in bytes 60 ): 61 self.name = name 62 self.path=path 63 self.parent = parent 64 self.hashd = hashd 65 self.size = size 66 67 def getFullPath(self): 68 """get the full path to this entity""" 69 if self.parent == None: 70 return "" 71 else: 72 return os.path.join(self.parent.getFullPath(), self.name) 73 74 def checkIntegrity(self): 75 """Check the file for corruption""" 76 if self.type == 'dir': 77 return True 78 else: 79 # check the hashd and compare against the recorded MD5 80 return True 81 82 def __str__(self): 83 if self.parent is not None: 84 return "\t".join([os.path.join(self.path,self.name),self.hashd,str(self.size)]) 85 return "" 86 87#------------------------------------------------------------------------------ 88# Handling IDs 89 90 91 92 93############################################################################### 94############################################################################### 95############################################################################### 96############################################################################### 97 98