Commit 5f9558b2 authored by Sriram Karra's avatar Sriram Karra

Save application root, and use it for bbdb backup dir

parent 5c93484e
##
## Created : Sat Apr 07 18:52:19 IST 2012
## Last Modified : Fri May 04 22:53:39 IST 2012
## Last Modified : Wed May 09 13:32:40 IST 2012
##
## Copyright (C) 2012 by Sriram Karra <karra.etc@gmail.com>
##
......@@ -12,6 +12,7 @@ from pimdb import PIMDB
from folder import Folder
from folder_bb import BBContactsFolder
from contact_bb import BBContact
import utils
## Note: Each BBDB File is a message store and there are one or more folders
## in it.
......@@ -219,6 +220,7 @@ class MessageStore:
if not fn:
fn = self.get_name()
fn = utils.abs_pathname(self.get_config(), fn)
logging.info('Parsing BBDB file %s...', fn)
def_fn = self.get_def_folder_name()
......@@ -275,8 +277,9 @@ class MessageStore:
def save_file (self, fn=None):
if not fn:
fn = self.get_name() + '.out'
fn = self.get_name()
fn = utils.abs_pathname(self.get_config(), fn)
logging.info('Saving BBDB File %s...', fn)
with codecs.open(fn, 'w', encoding='utf-8') as bbf:
......@@ -422,25 +425,26 @@ class BBPIMDB(PIMDB):
## Make a backup of the BBDB store into the backup directory
conf = self.get_config()
db1 = conf.get_profile_db1(pname)
db1 = conf.get_profile_db1(pname)
bdir = utils.abs_pathname(conf, conf.get_backup_dir())
bdir = conf.get_backup_dir()
if not os.path.exists(bdir):
logging.info('Creating backup directory at: %s', bdir)
os.mkdir(bdir)
stamp = string.replace(str(datetime.datetime.now()), ' ', '.')
stamp = string.replace(stamp, ':', '-')
logname = bdir + '/bbdb_backup.' + pname + '.' + stamp
backup_name = os.path.join(bdir, 'bbdb_backup.' + pname + '.' + stamp)
if db1 == dbid:
src = conf.get_stid2(pname)
else:
src = conf.get_stid1(pname)
logging.info('Backedup BBDB Store (%s) to file: %s',
src, logname)
shutil.copy2(src, logname)
src = utils.abs_pathname(conf, src)
logging.info('Backedup BBDB Store (%s) to file: %s', src, backup_name)
shutil.copy2(src, backup_name)
##
## Now the non-abstract methods and internal methods
......
##
## Created : Tue Jul 19 13:54:53 IST 2011
## Last Modified : Thu May 03 19:57:38 IST 2012
## Last Modified : Sat May 05 07:13:05 IST 2012
##
## Copyright (C) 2011, 2012 Sriram Karra <karra.etc@gmail.com>
##
......@@ -57,11 +57,12 @@ class Config:
# del sts['profiles']['sample']
self.state = { 'state' : demjson.decode(sts),
'config' : demjson.decode(stc), }
'config' : demjson.decode(stc), }
confi.close()
statei.close()
self.set_app_root(os.path.abspath(''))
self.sync_through = sync_through
##
......@@ -193,6 +194,12 @@ class Config:
## get-set pairs for sync state parameters in state.json
##
def get_app_root (self):
return self._get_prop('state', 'app_root')
def set_app_root (self, val, sync=False):
return self._set_prop('state', 'app_root', val, sync)
def get_state_file_version (self):
return self._get_prop('state', 'file_version')
......
##
## Created : Tue Jul 26 06:54:41 IST 2011
## Last Modified : Fri Apr 27 15:53:29 IST 2012
## Last Modified : Sat May 05 07:23:11 IST 2012
##
## Copyright (C) 2011, 2012 by Sriram Karra <karra.etc@gmail.com>
##
## Licensed under the GPL v3
##
import re
import os, re
def abs_pathname (config, fname):
"""If fname is an absolute path then it is returned as is. If it appears
to be a relative path, the application root is prepended to the name and
an absolute OS-specific path string is returned."""
app_root = config.get_app_root()
if fname[0] != '/' and fname[1] != ':' and fname[2] != '\\':
return os.path.join(app_root, fname)
return fname
def chompq (s):
"""Remove any leading and trailing quotes from the passed string."""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment