2012-09-12 22:03:46 +02:00
import xbmc
import xbmcgui
2012-09-12 22:30:54 +02:00
import xbmcvfs
2012-09-12 22:34:13 +02:00
import utils as utils
2012-11-05 18:13:48 +01:00
import os . path
2012-09-12 22:03:46 +02:00
import time
2012-11-04 21:39:17 +01:00
from vfs import XBMCFileSystem , DropboxFileSystem
2012-10-22 22:02:30 +02:00
2012-09-12 22:03:46 +02:00
class XbmcBackup :
2012-09-05 21:28:43 +02:00
#constants for initiating a back or restore
Backup = 0
Restore = 1
2012-11-02 21:59:40 +01:00
#remote file system
2013-01-28 22:44:22 +01:00
xbmc_vfs = None
2012-11-04 21:39:17 +01:00
remote_vfs = None
2012-09-12 22:03:46 +02:00
restoreFile = None
2013-03-04 18:41:07 +01:00
remote_base_path = None
2012-09-12 22:03:46 +02:00
#for the progress bar
progressBar = None
filesLeft = 0
filesTotal = 1
fileManager = None
2012-11-28 17:19:03 +01:00
restore_point = None
2013-05-09 21:24:10 +02:00
skip_advanced = False #if we should check for the existance of advancedsettings in the restore
2012-09-05 21:28:43 +02:00
def __init__ ( self ) :
2013-01-28 22:44:22 +01:00
self . xbmc_vfs = XBMCFileSystem ( xbmc . translatePath ( ' special://home ' ) )
2012-11-02 21:59:40 +01:00
2013-01-28 22:44:22 +01:00
self . configureRemote ( )
2012-11-02 21:59:40 +01:00
utils . log ( utils . getString ( 30046 ) )
2013-01-28 22:44:22 +01:00
def configureRemote ( self ) :
2012-11-02 21:59:40 +01:00
if ( utils . getSetting ( ' remote_selection ' ) == ' 1 ' ) :
2013-03-04 18:41:07 +01:00
self . remote_base_path = utils . getSetting ( ' remote_path_2 ' ) ;
2013-01-28 22:44:22 +01:00
self . remote_vfs = XBMCFileSystem ( utils . getSetting ( ' remote_path_2 ' ) )
2012-09-05 21:28:43 +02:00
utils . setSetting ( " remote_path " , " " )
elif ( utils . getSetting ( ' remote_selection ' ) == ' 0 ' ) :
2013-03-04 18:41:07 +01:00
self . remote_base_path = utils . getSetting ( ' remote_path ' ) ;
2013-01-28 22:44:22 +01:00
self . remote_vfs = XBMCFileSystem ( utils . getSetting ( " remote_path " ) )
2012-11-02 21:59:40 +01:00
elif ( utils . getSetting ( ' remote_selection ' ) == ' 2 ' ) :
2013-03-04 18:41:07 +01:00
self . remote_base_path = " / "
2013-01-28 22:44:22 +01:00
self . remote_vfs = DropboxFileSystem ( " / " )
2012-09-05 21:28:43 +02:00
2012-11-28 17:19:03 +01:00
def listBackups ( self ) :
2013-03-04 18:41:07 +01:00
result = [ ]
2012-11-28 17:19:03 +01:00
#get all the folders in the current root path
2013-03-04 18:41:07 +01:00
dirs , files = self . remote_vfs . listdir ( self . remote_base_path )
2012-11-28 17:19:03 +01:00
for aDir in dirs :
2013-03-04 18:41:07 +01:00
if ( self . remote_vfs . exists ( self . remote_base_path + aDir + " /xbmcbackup.val " ) ) :
result . append ( aDir )
2012-11-28 17:19:03 +01:00
return result
def selectRestore ( self , restore_point ) :
self . restore_point = restore_point
2013-05-09 21:24:10 +02:00
def skipAdvanced ( self ) :
self . skip_advanced = True
2012-09-06 22:28:41 +02:00
def run ( self , mode = - 1 , runSilent = False ) :
2012-09-05 21:28:43 +02:00
#append backup folder name
2012-11-28 16:37:37 +01:00
progressBarTitle = utils . getString ( 30010 ) + " - "
2012-11-04 21:39:17 +01:00
if ( mode == self . Backup and self . remote_vfs . root_path != ' ' ) :
2013-03-04 18:41:07 +01:00
self . remote_vfs . set_root ( self . remote_vfs . root_path + time . strftime ( " % Y % m %d " ) + " / " )
2012-11-28 16:37:37 +01:00
progressBarTitle = progressBarTitle + utils . getString ( 30016 )
2012-11-28 17:19:03 +01:00
elif ( mode == self . Restore and self . restore_point != None and self . remote_vfs . root_path != ' ' ) :
self . remote_vfs . set_root ( self . remote_vfs . root_path + self . restore_point + " / " )
2012-11-28 16:37:37 +01:00
progressBarTitle = progressBarTitle + utils . getString ( 30017 )
2012-09-12 22:03:46 +02:00
else :
2012-11-28 17:19:03 +01:00
#kill the program here
2012-11-04 21:39:17 +01:00
self . remote_vfs = None
2012-11-28 17:19:03 +01:00
return
2012-09-12 22:03:46 +02:00
2013-01-28 22:44:22 +01:00
utils . log ( utils . getString ( 30047 ) + " : " + self . xbmc_vfs . root_path )
2012-11-04 21:39:17 +01:00
utils . log ( utils . getString ( 30048 ) + " : " + self . remote_vfs . root_path )
2012-11-02 21:59:40 +01:00
2012-11-28 16:37:37 +01:00
#check if we should use the progress bar
if ( utils . getSetting ( ' run_silent ' ) == ' false ' and not runSilent ) :
self . progressBar = xbmcgui . DialogProgress ( )
self . progressBar . create ( progressBarTitle , utils . getString ( 30049 ) + " ...... " )
2012-09-05 21:28:43 +02:00
if ( mode == self . Backup ) :
utils . log ( utils . getString ( 30023 ) + " - " + utils . getString ( 30016 ) )
2013-01-29 17:34:48 +01:00
#check if remote path exists
2012-11-04 21:39:17 +01:00
if ( self . remote_vfs . exists ( self . remote_vfs . root_path ) ) :
2013-01-29 17:34:48 +01:00
#may be data in here already
2012-09-05 21:28:43 +02:00
utils . log ( utils . getString ( 30050 ) )
2012-09-12 22:03:46 +02:00
else :
2013-01-28 22:44:22 +01:00
#make the remote directory
self . remote_vfs . mkdir ( self . remote_vfs . root_path )
2013-03-04 18:41:07 +01:00
#create a validation file for backup rotation
self . _createValidationFile ( )
2013-01-28 22:44:22 +01:00
utils . log ( utils . getString ( 30051 ) )
2013-01-29 17:34:48 +01:00
allFiles = [ ]
2013-01-28 22:44:22 +01:00
fileManager = FileManager ( self . xbmc_vfs )
#go through each of the user selected items and write them to the backup store
if ( utils . getSetting ( ' backup_addons ' ) == ' true ' ) :
self . remote_vfs . mkdir ( self . remote_vfs . root_path + " addons " )
fileManager . walkTree ( xbmc . translatePath ( ' special://home/addons ' ) )
self . remote_vfs . mkdir ( self . remote_vfs . root_path + " userdata " )
if ( utils . getSetting ( ' backup_addon_data ' ) == ' true ' ) :
self . remote_vfs . mkdir ( self . remote_vfs . root_path + " userdata/addon_data " )
fileManager . walkTree ( xbmc . translatePath ( ' special://home/userdata/addon_data ' ) )
if ( utils . getSetting ( ' backup_database ' ) == ' true ' ) :
self . remote_vfs . mkdir ( self . remote_vfs . root_path + " userdata/Database " )
fileManager . walkTree ( xbmc . translatePath ( ' special://home/userdata/Database ' ) )
2012-09-12 22:03:46 +02:00
2013-01-28 22:44:22 +01:00
if ( utils . getSetting ( " backup_playlists " ) == ' true ' ) :
self . remote_vfs . mkdir ( self . remote_vfs . root_path + " userdata/playlists " )
fileManager . walkTree ( xbmc . translatePath ( ' special://home/userdata/playlists ' ) )
if ( utils . getSetting ( " backup_thumbnails " ) == " true " ) :
self . remote_vfs . mkdir ( self . remote_vfs . root_path + " userdata/Thumbnails " )
fileManager . walkTree ( xbmc . translatePath ( ' special://home/userdata/Thumbnails ' ) )
if ( utils . getSetting ( " backup_config " ) == " true " ) :
self . remote_vfs . mkdir ( self . remote_vfs . root_path + " userdata/keymaps " )
fileManager . walkTree ( xbmc . translatePath ( ' special://home/userdata/keymaps ' ) )
self . remote_vfs . mkdir ( self . remote_vfs . root_path + " userdata/peripheral_data " )
fileManager . walkTree ( xbmc . translatePath ( ' special://home/userdata/peripheral_data ' ) )
#this part is an oddity
dirs , configFiles = self . xbmc_vfs . listdir ( xbmc . translatePath ( ' special://home/userdata/ ' ) )
for aFile in configFiles :
if ( aFile . endswith ( " .xml " ) ) :
fileManager . addFile ( xbmc . translatePath ( ' special://home/userdata/ ' ) + aFile )
2013-01-29 17:34:48 +01:00
#add to array
self . filesTotal = fileManager . size ( )
allFiles . append ( { " source " : self . xbmc_vfs . root_path , " dest " : self . remote_vfs . root_path , " files " : fileManager . getFiles ( ) } )
2013-01-28 22:44:22 +01:00
#check if there are custom directories
2013-03-04 18:03:25 +01:00
if ( utils . getSetting ( ' custom_dir_1_enable ' ) == ' true ' and utils . getSetting ( ' backup_custom_dir_1 ' ) != ' ' ) :
2013-01-28 22:44:22 +01:00
#create a special remote path with hash
2013-03-04 18:03:25 +01:00
self . xbmc_vfs . set_root ( utils . getSetting ( ' backup_custom_dir_1 ' ) )
self . remote_vfs . mkdir ( self . remote_vfs . root_path + " custom_ " + self . _createCRC ( self . xbmc_vfs . root_path ) )
2013-01-28 22:44:22 +01:00
2013-03-04 18:03:25 +01:00
#walk the directory
2013-01-28 22:44:22 +01:00
fileManager . walkTree ( self . xbmc_vfs . root_path )
2013-01-29 17:34:48 +01:00
self . filesTotal = self . filesTotal + fileManager . size ( )
2013-03-04 18:03:25 +01:00
allFiles . append ( { " source " : self . xbmc_vfs . root_path , " dest " : self . remote_vfs . root_path + " custom_ " + self . _createCRC ( self . xbmc_vfs . root_path ) , " files " : fileManager . getFiles ( ) } )
if ( utils . getSetting ( ' custom_dir_2_enable ' ) == ' true ' and utils . getSetting ( ' backup_custom_dir_2 ' ) != ' ' ) :
#create a special remote path with hash
self . xbmc_vfs . set_root ( utils . getSetting ( ' backup_custom_dir_2 ' ) )
self . remote_vfs . mkdir ( self . remote_vfs . root_path + " custom_ " + self . _createCRC ( self . xbmc_vfs . root_path ) )
#walk the directory
fileManager . walkTree ( self . xbmc_vfs . root_path )
self . filesTotal = self . filesTotal + fileManager . size ( )
allFiles . append ( { " source " : self . xbmc_vfs . root_path , " dest " : self . remote_vfs . root_path + " custom_ " + self . _createCRC ( self . xbmc_vfs . root_path ) , " files " : fileManager . getFiles ( ) } )
2013-01-29 17:34:48 +01:00
#backup all the files
self . filesLeft = self . filesTotal
for fileGroup in allFiles :
self . xbmc_vfs . set_root ( fileGroup [ ' source ' ] )
self . remote_vfs . set_root ( fileGroup [ ' dest ' ] )
self . backupFiles ( fileGroup [ ' files ' ] , self . xbmc_vfs , self . remote_vfs )
#remove old backups
2013-03-04 18:41:07 +01:00
self . _rotateBackups ( )
2012-09-12 22:03:46 +02:00
2013-01-29 18:00:16 +01:00
elif ( mode == self . Restore ) :
utils . log ( utils . getString ( 30023 ) + " - " + utils . getString ( 30017 ) )
#for restores remote path must exist
if ( not self . remote_vfs . exists ( self . remote_vfs . root_path ) ) :
xbmcgui . Dialog ( ) . ok ( utils . getString ( 30010 ) , utils . getString ( 30045 ) , self . remote_vfs . root_path )
return
utils . log ( utils . getString ( 30051 ) )
allFiles = [ ]
fileManager = FileManager ( self . remote_vfs )
#go through each of the user selected items and write them to the backup store
2013-05-09 21:24:10 +02:00
if ( utils . getSetting ( " backup_config " ) == " true " ) :
#check for the existance of an advancedsettings file
if ( self . remote_vfs . exists ( self . remote_vfs . root_path + " userdata/advancedsettings.xml " ) and not self . skip_advanced ) :
#let the user know there is an advanced settings file present
restartXbmc = xbmcgui . Dialog ( ) . yesno ( " Advanced Settings Detected " , " The advancedsettings file should be restored first " , " Select Yes to restore this file and restart XBMC " , " Select No to continue " )
if ( restartXbmc ) :
#add only this file to the file list
fileManager . addFile ( self . remote_vfs . root_path + " userdata/advancedsettings.xml " )
self . backupFiles ( fileManager . getFiles ( ) , self . remote_vfs , self . xbmc_vfs )
#let the service know to resume this backup on startup
self . _createResumeBackupFile ( )
#do not continue running
xbmcgui . Dialog ( ) . ok ( " Restart XBMC " , " You should restart XBMC to continue " )
return
self . xbmc_vfs . mkdir ( xbmc . translatePath ( ' special://home/userdata/keymaps ' ) )
fileManager . walkTree ( self . remote_vfs . root_path + " userdata/keymaps " )
self . xbmc_vfs . mkdir ( xbmc . translatePath ( ' special://home/userdata/peripheral_data ' ) )
fileManager . walkTree ( self . remote_vfs . root_path + " userdata/peripheral_data " )
#this part is an oddity
dirs , configFiles = self . remote_vfs . listdir ( self . remote_vfs . root_path + " userdata/ " )
for aFile in configFiles :
if ( aFile . endswith ( " .xml " ) ) :
fileManager . addFile ( self . remote_vfs . root_path + " userdata/ " + aFile )
2013-01-29 18:00:16 +01:00
if ( utils . getSetting ( ' backup_addons ' ) == ' true ' ) :
self . xbmc_vfs . mkdir ( xbmc . translatePath ( ' special://home/addons ' ) )
fileManager . walkTree ( self . remote_vfs . root_path + " addons " )
self . xbmc_vfs . mkdir ( xbmc . translatePath ( ' special://home/userdata ' ) )
if ( utils . getSetting ( ' backup_addon_data ' ) == ' true ' ) :
self . xbmc_vfs . mkdir ( xbmc . translatePath ( ' special://home/userdata/addon_data ' ) )
fileManager . walkTree ( self . remote_vfs . root_path + " userdata/addon_data " )
if ( utils . getSetting ( ' backup_database ' ) == ' true ' ) :
self . xbmc_vfs . mkdir ( xbmc . translatePath ( ' special://home/userdata/Database ' ) )
fileManager . walkTree ( self . remote_vfs . root_path + " userdata/Database " )
if ( utils . getSetting ( " backup_playlists " ) == ' true ' ) :
self . xbmc_vfs . mkdir ( xbmc . translatePath ( ' special://home/userdata/playlists ' ) )
fileManager . walkTree ( self . remote_vfs . root_path + " userdata/playlists " )
if ( utils . getSetting ( " backup_thumbnails " ) == " true " ) :
self . xbmc_vfs . mkdir ( xbmc . translatePath ( ' special://home/userdata/Thumbnails ' ) )
fileManager . walkTree ( self . remote_vfs . root_path + " userdata/Thumbnails " )
#add to array
self . filesTotal = fileManager . size ( )
allFiles . append ( { " source " : self . remote_vfs . root_path , " dest " : self . xbmc_vfs . root_path , " files " : fileManager . getFiles ( ) } )
#check if there are custom directories
2013-03-04 18:03:25 +01:00
if ( utils . getSetting ( ' custom_dir_1_enable ' ) == ' true ' and utils . getSetting ( ' backup_custom_dir_1 ' ) != ' ' ) :
2013-01-29 18:00:16 +01:00
2013-03-04 18:03:25 +01:00
self . xbmc_vfs . set_root ( utils . getSetting ( ' backup_custom_dir_1 ' ) )
if ( self . remote_vfs . exists ( self . remote_vfs . root_path + " custom_ " + self . _createCRC ( self . xbmc_vfs . root_path ) ) ) :
2013-01-29 18:00:16 +01:00
#index files to restore
2013-03-04 18:03:25 +01:00
fileManager . walkTree ( self . remote_vfs . root_path + " custom_ " + self . _createCRC ( self . xbmc_vfs . root_path ) )
self . filesTotal = self . filesTotal + fileManager . size ( )
allFiles . append ( { " source " : self . remote_vfs . root_path + " custom_ " + self . _createCRC ( self . xbmc_vfs . root_path ) , " dest " : self . xbmc_vfs . root_path , " files " : fileManager . getFiles ( ) } )
else :
xbmcgui . Dialog ( ) . ok ( utils . getString ( 30010 ) , utils . getString ( 30045 ) , self . remote_vfs . root_path + " custom_ " + self . _createCRC ( utils . getSetting ( ' backup_custom_dir_1 ' ) ) )
2013-01-29 18:00:16 +01:00
2013-03-04 18:03:25 +01:00
if ( utils . getSetting ( ' custom_dir_2_enable ' ) == ' true ' and utils . getSetting ( ' backup_custom_dir_2 ' ) != ' ' ) :
self . xbmc_vfs . set_root ( utils . getSetting ( ' backup_custom_dir_2 ' ) )
if ( self . remote_vfs . exists ( self . remote_vfs . root_path + " custom_ " + self . _createCRC ( self . xbmc_vfs . root_path ) ) ) :
#index files to restore
fileManager . walkTree ( self . remote_vfs . root_path + " custom_ " + self . _createCRC ( self . xbmc_vfs . root_path ) )
2013-01-29 18:00:16 +01:00
self . filesTotal = self . filesTotal + fileManager . size ( )
2013-03-04 18:03:25 +01:00
allFiles . append ( { " source " : self . remote_vfs . root_path + " custom_ " + self . _createCRC ( self . xbmc_vfs . root_path ) , " dest " : self . xbmc_vfs . root_path , " files " : fileManager . getFiles ( ) } )
2013-01-29 18:00:16 +01:00
else :
2013-03-04 18:03:25 +01:00
xbmcgui . Dialog ( ) . ok ( utils . getString ( 30010 ) , utils . getString ( 30045 ) , self . remote_vfs . root_path + " custom_ " + self . _createCRC ( utils . getSetting ( ' backup_custom_dir_2 ' ) ) )
2013-01-29 18:00:16 +01:00
#restore all the files
self . filesLeft = self . filesTotal
for fileGroup in allFiles :
self . remote_vfs . set_root ( fileGroup [ ' source ' ] )
self . xbmc_vfs . set_root ( fileGroup [ ' dest ' ] )
self . backupFiles ( fileGroup [ ' files ' ] , self . remote_vfs , self . xbmc_vfs )
2013-01-29 18:32:47 +01:00
#call update addons to refresh everything
xbmc . executebuiltin ( ' UpdateLocalAddons ' )
2013-01-29 18:00:16 +01:00
if ( utils . getSetting ( ' run_silent ' ) == ' false ' and not runSilent ) :
self . progressBar . close ( )
2013-01-28 22:44:22 +01:00
def backupFiles ( self , fileList , source , dest ) :
2012-11-04 21:39:17 +01:00
utils . log ( " Writing files to: " + dest . root_path )
2013-01-29 17:34:48 +01:00
utils . log ( " Source: " + source . root_path )
2012-09-12 22:03:46 +02:00
for aFile in fileList :
2013-01-28 22:44:22 +01:00
if ( not self . _checkCancel ( ) ) :
utils . log ( ' Writing file: ' + aFile , xbmc . LOGDEBUG )
self . _updateProgress ( aFile )
if ( aFile . startswith ( " - " ) ) :
dest . mkdir ( dest . root_path + aFile [ len ( source . root_path ) + 1 : ] )
2012-09-12 22:03:46 +02:00
else :
2012-11-06 18:37:39 +01:00
if ( isinstance ( source , DropboxFileSystem ) ) :
#if copying from dropbox we need the file handle, use get_file
2013-01-28 22:44:22 +01:00
source . get_file ( aFile , dest . root_path + aFile [ len ( source . root_path ) : ] )
2012-11-06 18:37:39 +01:00
else :
#copy using normal method
2013-01-28 22:44:22 +01:00
dest . put ( aFile , dest . root_path + aFile [ len ( source . root_path ) : ] )
def _createCRC ( self , string ) :
#create hash from string
string = string . lower ( )
bytes = bytearray ( string . encode ( ) )
crc = 0xffffffff ;
for b in bytes :
crc = crc ^ ( b << 24 )
for i in range ( 8 ) :
if ( crc & 0x80000000 ) :
crc = ( crc << 1 ) ^ 0x04C11DB7
else :
crc = crc << 1 ;
crc = crc & 0xFFFFFFFF
return ' %08x ' % crc
def _updateProgress ( self , message = ' ' ) :
2012-09-12 22:03:46 +02:00
self . filesLeft = self . filesLeft - 1
#update the progress bar
if ( self . progressBar != None ) :
self . progressBar . update ( int ( ( float ( self . filesTotal - self . filesLeft ) / float ( self . filesTotal ) ) * 100 ) , message )
2013-01-28 22:44:22 +01:00
def _checkCancel ( self ) :
2012-09-12 22:03:46 +02:00
result = False
if ( self . progressBar != None ) :
result = self . progressBar . iscanceled ( )
return result
2013-01-29 17:34:48 +01:00
2013-03-04 18:41:07 +01:00
def _rotateBackups ( self ) :
total_backups = int ( utils . getSetting ( ' backup_rotation ' ) )
if ( total_backups > 0 ) :
#get a list of valid backup folders
dirs = self . listBackups ( )
if ( len ( dirs ) > total_backups ) :
#remove backups to equal total wanted
dirs . sort ( )
remove_num = len ( dirs ) - total_backups - 1
self . filesTotal = self . filesTotal + remove_num + 1
#update the progress bar if it is available
while ( remove_num > = 0 and not self . _checkCancel ( ) ) :
self . _updateProgress ( utils . getString ( 30054 ) + " " + dirs [ remove_num ] )
utils . log ( " Removing backup " + dirs [ remove_num ] )
self . remote_vfs . rmdir ( self . remote_base_path + dirs [ remove_num ] + " / " )
remove_num = remove_num - 1
def _createValidationFile ( self ) :
vFile = xbmcvfs . File ( xbmc . translatePath ( utils . data_dir ( ) + " xbmcbackup.val " ) , ' w ' )
2013-05-09 21:24:10 +02:00
vFile . write ( " XBMC Backup Validation File " )
2013-03-04 18:41:07 +01:00
vFile . close ( )
self . remote_vfs . put ( xbmc . translatePath ( utils . data_dir ( ) + " xbmcbackup.val " ) , self . remote_vfs . root_path + " xbmcbackup.val " )
2013-05-09 21:24:10 +02:00
def _createResumeBackupFile ( self ) :
rFile = xbmcvfs . File ( xbmc . translatePath ( utils . data_dir ( ) + " resume.txt " ) , ' w ' )
rFile . write ( self . restore_point )
rFile . close ( )
2013-01-29 17:34:48 +01:00
class FileManager :
fileArray = [ ]
not_dir = [ ' .zip ' , ' .xsp ' , ' .rar ' ]
vfs = None
def __init__ ( self , vfs ) :
self . vfs = vfs
def walkTree ( self , directory ) :
dirs , files = self . vfs . listdir ( directory )
#create all the subdirs first
for aDir in dirs :
dirPath = xbmc . translatePath ( directory + " / " + aDir )
file_ext = aDir . split ( ' . ' ) [ - 1 ]
self . addFile ( " - " + dirPath )
#catch for "non directory" type files
if ( not any ( file_ext in s for s in self . not_dir ) ) :
self . walkTree ( dirPath )
#copy all the files
for aFile in files :
filePath = xbmc . translatePath ( directory + " / " + aFile )
self . addFile ( filePath )
def addFile ( self , filename ) :
try :
filename = filename . decode ( ' UTF-8 ' )
except UnicodeDecodeError :
filename = filename . decode ( ' ISO-8859-2 ' )
#write the full remote path name of this file
utils . log ( " Add File: " + filename , xbmc . LOGDEBUG )
self . fileArray . append ( filename )
def getFiles ( self ) :
result = self . fileArray
self . fileArray = [ ]
return result
def size ( self ) :
return len ( self . fileArray )