Package FlightReportManager :: Module FileStorageController
[hide private]
[frames] | no frames]

Source Code for Module FlightReportManager.FileStorageController

 1  ''' 
 2  Created on 06.09.2016 
 3   
 4  @author: johanneskinzig 
 5  ''' 
 6  import appdirs 
 7  import os 
 8  from shutil import copyfile 
 9   
10 -class FileStorageController():
11 ''' 12 This class holds the information for storing the files on the local drives 13 '''
14 - def __init__(self, application_name, application_author, application_version):
15 ''' 16 Constructor 17 ''' 18 ################################################ 19 # Files and folders prefix # 20 ################################################ 21 self.data_directory = appdirs.user_data_dir(application_name, application_author) 22 self.sqlit_db_location = self.data_directory + "/FlightReportManager_DB.db" 23 self.drone_logfile_prefix = self.data_directory + "/puds/" 24 25 ## create data_directory if non exisiting 26 if not os.path.exists(self.data_directory): 27 os.makedirs(self.data_directory) 28 29 ## create drone logfile folder if non existing 30 if not os.path.exists(self.drone_logfile_prefix): 31 os.makedirs(self.drone_logfile_prefix)
32
33 - def getDBLocation(self):
34 ''' 35 Return DB location 36 ''' 37 return self.sqlit_db_location
38
39 - def getPudfileDataDirectory(self):
40 ''' 41 Return user and system specfic data directory 42 ''' 43 return self.drone_logfile_prefix
44
45 - def getDataDirectory(self):
46 ''' 47 Return the main DataDirectory used by the application 48 ''' 49 return self.data_directory
50
51 - def copyFileTo(self, source, destination):
52 """Copy the selected file to the puds folder""" 53 copyfile(source, destination) 54 print("Copied file to " + destination)
55
56 - def deleteFile(self, filepath):
57 """Delete pud file""" 58 os.remove(filepath) 59 print("Removed file: " + str(filepath))
60 61 62 if __name__ == '__main__': 63 myStorage = FileStorageController("FlightReportManager", "kinzig", "0.1.alpha") 64 print myStorage.getDataDirectory() 65 print myStorage.getDBLocation() 66