2323CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2424'''
2525
26- from os import path , makedirs , scandir
26+ from os import path , makedirs
2727from sys import argv
2828from shutil import copy , copytree , ignore_patterns
2929from errno import ENOTDIR
30- import utils
30+ from . import utils
3131
3232
3333class Backup ():
3434 '''
3535 Main class of the backup system
3636 '''
37+
3738 def __init__ (self , verbose = False ):
3839
3940 # Initial attributes
@@ -43,15 +44,15 @@ def __init__(self, verbose=False):
4344 self .backup_list = []
4445
4546 except BaseException as e :
46- self .log .UpdateLog (e )
47+ self .log .update_log (e )
4748 raise BaseException (e )
4849
4950 # Check if settings.py is properly configured and import it
5051 try :
5152 from settings import backup_items , sub_folder_name , target_folder , ignore_extensions , now , mailing_list , send_mail , mail_body , mail_subject , mail_settings
5253
5354 except ImportError as e :
54- self .log .UpdateLog ( e )
55+ self .log .update_log ( 'Settings file or attributes not found' )
5556 raise ImportError (e )
5657
5758 else :
@@ -70,10 +71,10 @@ def __init__(self, verbose=False):
7071
7172 # Check mailing list
7273 if len (self .mail .excludedMails ) > 0 :
73- self .log .UpdateLog ('Invalid mail addresses detected: %s' % self .mail .excludedMails , 'INFO' )
74+ self .log .update_log ('Invalid mail addresses detected: %s' % self .mail .excludedMails , 'INFO' )
7475
7576
76- def CleanList (self ):
77+ def clean_list (self ):
7778 '''
7879 Manage the list of items
7980 to backup
@@ -82,18 +83,18 @@ def CleanList(self):
8283 # Case <backupItems> is empty
8384 if self .backupItems == []:
8485 self .backup_list .append (path .abspath (path .dirname (argv [0 ])))
85-
86+
8687 return None
8788
8889 # Add items
8990 for item in self .backupItems :
9091 if path .isfile (path .abspath (item )) or path .isdir (path .abspath (item )):
9192 self .backup_list .append (path .abspath (item ))
9293 else :
93- log .UpdateLog ("Invalid item. It'll be wiped from backup list: <%s>" % item , 'INFO' )
94+ log .update_log ("Invalid item. It'll be wiped from backup list: <%s>" % item , 'INFO' )
9495
9596
96- def ProcessItem (self , source , destination ):
97+ def process_item (self , source , destination ):
9798 '''
9899 Backup a single item
99100 '''
@@ -106,16 +107,16 @@ def ProcessItem(self, source, destination):
106107 copy (source , destination )
107108
108109 except :
109- log .UpdateLog ("Error processing file <%s>: <%s>" % (source , e ))
110+ log .update_log ("Error processing file <%s>: <%s>" % (source , e ))
110111
111112 else :
112- self .log .UpdateLog ("Source <%s> could not be copied to <%s>: <%s>" % (source , destination , e ))
113+ self .log .update_log ("Source <%s> could not be copied to <%s>: <%s>" % (source , destination , e ))
113114
114115 except BaseException as e :
115- self .log .UpdateLog ("Unkown error copying <%s>: <%s>" % (source , e ))
116+ self .log .update_log ("Unkown error copying <%s>: <%s>" % (source , e ))
116117
117118
118- def ProcessList (self ):
119+ def process_list (self ):
119120 '''
120121 Process every item from a <backup_list>
121122 '''
@@ -125,33 +126,25 @@ def ProcessList(self):
125126 if path .isdir (item ):
126127 folder = path .abspath (item ).split ('\\ ' )[- 1 ]
127128 dest = path .join (default_dest , folder )
128- self .log .UpdateLog ('Processing directory: %s' % item , 'INFO' )
129- self .ProcessItem (path .abspath (item ), dest )
129+ self .log .update_log ('Processing directory: %s' % item , 'INFO' )
130+ self .process_item (path .abspath (item ), dest )
130131
131132 else :
132- self .log .UpdateLog ('Processing file: %s' % item , 'INFO' )
133- self .ProcessItem (path .abspath (item ), default_dest )
133+ self .log .update_log ('Processing file: %s' % item , 'INFO' )
134+ self .process_item (path .abspath (item ), default_dest )
134135
135136
136- def Run (self ):
137+ def run (self ):
137138 '''
138139 Run backup routine
139140 '''
140- self .CleanList ()
141- self .ProcessList ()
141+ self .clean_list ()
142+ self .process_list ()
142143
143144 # Send email if configured to do so
144145 if self .sendMail :
145146
146147 subject = self .mailSubject .format (self .now )
147148 body = self .mailBody .format (self .now , self .backupItems , self .targetFolder )
148149
149- self .mail .Send (subject , body )
150-
151-
152-
153- # Debug purpose
154- if __name__ == "__main__" :
155-
156- Bkp = Backup (verbose = True )
157- Bkp .Run ()
150+ self .mail .send (subject , body )
0 commit comments