Commit bee7acba authored by Sriram Karra's avatar Sriram Karra

Clean up unwanted state.py helpers related to exgid

We put in a lot of code for exchange store profile management that
was copid from the outlook code. In particualr the use of the olgid
profile state flag was replicate. However we now do not need to use
that methodology at all. Recall that the olgid was used to create
a custom named integer extended property for each profile involving
outlook. In Exchange store we just put all of the sync tags as
part of a separate custom property that is a named string identified
extended property.

We could have done something similar for Outlook as well, but I did
not have this understanding of MAPI / Outlook at that time. Also the
human readnable XML base protocol has clarified many things and hence
this enlightnment.
parent bf4c0e44
......@@ -276,11 +276,7 @@ class Config:
raise AsynkConfigError('Profile %s not found in state.json'
% profile)
try:
self.state['state']['profiles'][profile].update({key : val})
except KeyError, e:
raise AsynkConfigError(('Property %s not found in profile %s'
% (key, profile)))
self.state['state']['profiles'][profile].update({key : val})
if self.sync_through and sync:
self.save_state()
......@@ -356,15 +352,6 @@ class Config:
def get_ex_guid (self):
return self.get_db_config('ex')['guid']
def get_ex_gid_base (self, which=None):
dbc = self.get_db_config('ex')
gid = dbc['gid_base']
if not which:
return gid
return gid[which]
def get_ex_cus_pid (self):
return self.get_db_config('ex')['cus_pid']
......@@ -529,12 +516,6 @@ class Config:
def set_ol_gid (self, profile, val, sync=True):
return self._set_profile_prop(profile, 'olgid', val, sync)
def get_ex_gid (self, profile):
return self._get_profile_prop(profile, 'exgid')
def set_ex_gid (self, profile, val, sync=True):
return self._set_profile_prop(profile, 'exgid', val, sync)
def get_itemids (self, pname):
"""Returns a dictionary of itemid mappsing from coll_1 to coll_2 as of
the last successful sync """
......@@ -551,6 +532,18 @@ class Config:
self._set_profile_prop(pname, 'items', itemids, sync)
return itemids
def get_ex_sync_state (self, pname):
return self._get_profile_prop(pname, 'sync_state')
## Throws an exception if the profile name does not support the sync_state
## flag, IOW - it if it is not an exchange profile.
## On success retuns sync_state input parameter
def set_ex_sync_state (self, pname, sync_state, sync=True):
## Fetch the old one to force an exception if the prop is not there
old = self.get_ex_sync_state(pname)
self._set_profile_prop(pname, 'sync_state', sync_state, sync)
return sync_state
##
## Finally the two save routines.
##
......@@ -615,13 +608,6 @@ class Config:
return self._get_gid_lists('ol', get_fn=self.get_ol_gid)
def _get_ex_gid_lists (self):
"""Returns all the exgids used in the existing profiles. The returned
value is organized as a dictionary, with the destination dbid as the
key, and an array of exgids as the value."""
return self._get_gid_lists('ex', get_fn=self.get_ex_gid)
def _get_next_gid (self, destid, base_fn, gid_lists_fn):
base = base_fn(destid)
try:
......@@ -632,14 +618,12 @@ class Config:
cnt = len(gid_list)
gid_c = base + cnt
i = 0
print 'base: ', base
print 'cnt : ', cnt
while gid_c in gid_list:
gid_c += 1
i +=1
if i > 5000:
logging.info('state:get_ol_next_gid: more than 5000 iters!')
logging.info('state:get_next_gid: more than 5000 iters!')
return gid_c
......@@ -647,10 +631,6 @@ class Config:
return self._get_next_gid(destid=destid, base_fn=self.get_ol_gid_base,
gid_lists_fn=self._get_ol_gid_lists)
def get_ex_next_gid (self, destid):
return self._get_next_gid(destid=destid, base_fn=self.get_ex_gid_base,
gid_lists_fn=self._get_ex_gid_lists)
def make_sync_label (self, profile, dbid):
"""A sync label that is used in GC and BB to store the remote ID of a
synched item."""
......
// -*- javascript -*-
// Last Modified : Tue Apr 29 13:30:48 IST 2014
// Last Modified : Thu May 01 09:15:52 IST 2014
//
// Copyright (C) 2011, 2012, 2013, 2014 Sriram Karra <karra.etc@gmail.com>
//
......@@ -337,13 +337,14 @@
// You definitely don't want to change these values.
// Note this guy is missing braces
'guid' : 'c950b7d3-ca13-43cd-9e78-be65bbdeaf37',
'gid_base' : {'bb' : 0x8001,
'gc' : 0x9001,
'cd' : 0xA001,
'ol' : 0xC001,
},
// 'gid_base' : {'bb' : 0x8001,
// 'gc' : 0x9001,
// 'cd' : 0xA001,
// 'ol' : 0xC001,
// },
'cus_pid' : 0x6501,
'stags_pname' : 'sync_tags',
'sync_state' : null, // base64 encoded EWS sync_state ID
// You can customize what follows
"email_domains" : {
......
......@@ -95,5 +95,33 @@
// used to store the sync tag.
'olgid' : null,
}, // profiles['defgcbb']
'defgcex' : {
"coll_1" : {
"dbid" : "gc",
"stid" : null,
"foid" : null,
},
"coll_2" : {
"dbid" : "ex",
"stid" : "https://outlook.office365.com/EWS/Exchange.asmx",
"foid" : "default",
},
'last_sync_start' : "1980-01-01T00:00:00.00+00:00",
'last_sync_stop' : "1980-01-01T00:00:00.00+00:00",
// Default direction in which to perform Sync. Values can
// be one of ['SYNC1WAY' or 'SYCN2WAY'].
'sync_dir' : "SYNC2WAY",
// Direction in which to resolve conflicts if the same
// entry is modified both locally and in the google
// cloud. Value should be one of the two dbids (in this
// instance, either 'gc' or 'ex')
'conflict_resolve' : 'gc',
'sync_state' : null,
}, // profiles['defgcex']
}, // 'profiles'
}
......@@ -132,10 +132,6 @@ class TestStateFunctions(unittest.TestCase):
val = self.config.get_ex_guid()
self.assertTrue(val == 'c950b7d3-ca13-43cd-9e78-be65bbdeaf37')
def test_read_ex_gid_base (self):
val = self.config.get_ex_gid_base('ol')
self.assertTrue(val == 0xC001)
def test_read_ex_cus_pid (self):
val = self.config.get_ex_cus_pid()
self.assertTrue(val == 0x6501)
......@@ -163,7 +159,7 @@ class TestStateFunctions(unittest.TestCase):
def test_read_profile_names_cnt (self):
ps = self.config.get_profile_names()
self.assertEqual(len(ps), 2)
self.assertEqual(len(ps), 3)
def test_read_profile_names_vals (self):
ps = self.config.get_profile_names()
......@@ -235,21 +231,23 @@ class TestStateFunctions(unittest.TestCase):
val = self.config.get_ol_next_gid('ex')
self.assertTrue(val == 0xb001)
def test_get_ex_gid_next_gc (self):
val = self.config.get_ex_next_gid('gc')
self.assertTrue(val == 0x9001)
def test_read_ex_sync_state (self):
val = self.config.get_ex_sync_state('defgcex')
def test_get_ex_gid_next_bb (self):
val = self.config.get_ex_next_gid('bb')
self.assertTrue(val == 0x8001)
def test_read_ex_sync_state_err (self):
with self.assertRaises(AsynkConfigError):
val = self.config.get_ex_sync_state('defgcbb')
def test_get_ex_gid_next_cd (self):
val = self.config.get_ex_next_gid('cd')
self.assertTrue(val == 0xa001)
def test_write_ex_sync_state (self):
val = 'abcdefgh'
self.config.set_ex_sync_state('defgcex', val)
out = self.config.get_ex_sync_state('defgcex')
self.assertTrue(val == out)
def test_get_ex_gid_next_ol (self):
val = self.config.get_ex_next_gid('ol')
self.assertTrue(val == 0xc001)
def test_write_ex_sync_state_err (self):
val = 'abcdefgh'
with self.assertRaises(AsynkConfigError):
self.config.set_ex_sync_state('defgcbb', val)
def test_make_sync_label (self):
val = self.config.make_sync_label('goofy', 'gc')
......@@ -307,7 +305,7 @@ class TestStateFunctions(unittest.TestCase):
def test_get_store_pnames_1 (self):
ps = self.config.get_store_pnames('gc')
self.assertEqual(True, not not ps)
self.assertEqual(True, len(ps) == 2)
self.assertEqual(True, len(ps) == 3)
self.assertEqual(True, 'defgcol' in ps and 'defgcbb' in ps)
def test_get_store_pnames_2 (self):
......
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