3 ###########################################################################
5 # ConfigParser.h Copyright (C) 2008 by J Rumble #
7 # j.w.rumble@reading.ac.uk #
10 # This file is part of dotbuddy, #
12 # dotbuddy 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 2 of the License, or #
15 # (at your option) any later version. #
18 # dotbuddy is distributed in the hope that it will be useful, #
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
21 # GNU General Public License for more details. #
23 # You should have received a copy of the GNU General Public License #
24 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
25 ###########################################################################
39 'archive_type' : 'bz2',
40 'confdir' : '.dotbuddy/',
41 'confile' : 'dotbuddy.conf',
42 'create_archive' : True,
43 'create_audit_report' : False,
44 'filelist' : 'filelist',
46 'override_perms' : False,
47 'silent_override' : True,
54 def create_conf_files():
56 If a config file is not supplied, or we can't find one at the default
57 location, this will attempt to create one using the default config
60 cparser
= ConfigParser
.ConfigParser()
61 npath
= os
.path
.join(os
.path
.expanduser('~'),settings
['confdir'])
63 if os
.access(npath
, os
.F_OK
) is not True:
65 #Create Path and config file...
67 file = open(os
.path
.join(npath
,'dotbuddy.conf'),'w')
69 print "Can't create config file !!"
72 cparser
.readfp(file,os
.path
.join(npath
,'dotbuddy.conf'))
73 cparser
.add_section('Options')
75 for option
, value
in settings
.iteritems():
76 cparser
.set('Options',option
,value
)
80 print cparser
.items('Options')
87 user_home_path
= os
.path
.expanduser("~")
89 os
.chdir(user_home_path
)
90 if os
.access(settings
['confdir'],os
.R_OK
) is False:
95 print "Can't create files.. Exiting !!"
101 Reads Options from config file, and creates one with defaults if it
104 session_cfg
= ConfigParser
.ConfigParser()
105 session_cfg
= cfg
.read('dotbuddy.conf')
107 def create_filelist():
108 infile
= open(os
.path
.join(settings
['confdir'],settings
['filelist']))
110 if line
.startswith('#'):
112 elif line
.startswith('\n'):
115 file_list_names
.append(line
.rstrip())
117 if settings
['create_audit_report'] is True:
119 if settings
['create_archive'] is True:
137 date
= time
.strftime("%d-%b-%y",time
.localtime())
138 arc_name
= "HOME-Backup-" + date
+ ".tar.bz2"
139 archive
= tarfile
.open(arc_name
,"w:bz2")
141 for tfile
in file_list_names
:
143 print "Backing up: %s.." % tfile
146 print "Error backing up file, skipping.."
150 finally: archive
.close()
153 for tfile
in file_list_names
:
154 fdata
= open(tfile
,'r').read()
155 md5sig
= md5
.md5(fdata
).hexdigest()
156 print "Name: %s MD5 Sig: %s" % (tfile
,md5sig
)
160 if __name__
== '__main__':