|
From: Stas Z <sta...@gm...> - 2005-06-03 15:32:36
|
I was hacking gmailagent to add a 'save contacts when something goes
wrong' function.
It occurs to me that libgmail2 does very little to save the contacts
in case or errors.
I just paste the stuff I come up with for gmailagent.
(It can be found in Gmail.py)
Stas
def save_contacts(contacts):
"""Save the contact in case of an error. This is an attempt to prevent
data loss in case of an error when interacting with Gmail contacts."""
try:
f =3D open(os.path.expanduser('~/.GmailContacts.pickle'),'w')
pickle.dump(contacts,f)
## XXX TODO: some way to load the pickled object and restore it
except Exception,info:
text =3D "Attempt to pickle the contacts %s" % str(info)
logging.critical(text)
f.close()
try:
f =3Dopen(os.path.expanduser('~/.GmailContacts.txt'),'w')
text =3D "#An error occured in GmailAgent and these contacts are
saved\n"+\
"#to this file in an attempt to save them\n"+\
"#A contact is saved as follows:\n"+\
"#GmailID Name email notes\n"
f.write(text)
for con in contacts:
name,email,notes,id =3D
con.getName(),con.getEmail(),con.getNotes(),con.getId()
f.write("%s %s %s %s\n" % (con.getId(),\
con.getName(),\
con.getEmail(),\
con.getNotes()))
f.close()
except Exception,info:
logging.critical(str(info))
return str(info)
=20
--=20
"Everything that is really great and inspiring is created by the individual
who can labor in freedom."
-Albert Einstein
|
|
From: Waseem S. D. <wd...@MI...> - 2005-06-03 15:57:10
|
Interesting approach.
I probably don't understand where you're going with this though, because
I wonder why you'd want to save state internally at all? Whatever lives
in Gmail should be the definitive version of the contacts, right? So why
would we ever need to read from them locally?
Though I guess it can't hurt.
- W
On Fri, 2005-06-03 at 17:32 +0200, Stas Z wrote:
> I was hacking gmailagent to add a 'save contacts when something goes
> wrong' function.
> It occurs to me that libgmail2 does very little to save the contacts
> in case or errors.
>
> I just paste the stuff I come up with for gmailagent.
> (It can be found in Gmail.py)
>
> Stas
>
> def save_contacts(contacts):
> """Save the contact in case of an error. This is an attempt to prevent
> data loss in case of an error when interacting with Gmail contacts."""
> try:
> f = open(os.path.expanduser('~/.GmailContacts.pickle'),'w')
> pickle.dump(contacts,f)
> ## XXX TODO: some way to load the pickled object and restore it
> except Exception,info:
> text = "Attempt to pickle the contacts %s" % str(info)
> logging.critical(text)
> f.close()
> try:
> f =open(os.path.expanduser('~/.GmailContacts.txt'),'w')
> text = "#An error occured in GmailAgent and these contacts are
> saved\n"+\
> "#to this file in an attempt to save them\n"+\
> "#A contact is saved as follows:\n"+\
> "#GmailID Name email notes\n"
> f.write(text)
> for con in contacts:
> name,email,notes,id =
> con.getName(),con.getEmail(),con.getNotes(),con.getId()
> f.write("%s %s %s %s\n" % (con.getId(),\
> con.getName(),\
> con.getEmail(),\
> con.getNotes()))
> f.close()
> except Exception,info:
> logging.critical(str(info))
> return str(info)
>
>
|
|
From: Stas Z <sta...@gm...> - 2005-06-03 17:09:02
|
On 6/3/05, Waseem S. Daher <wd...@mi...> wrote:
> Interesting approach.
> I probably don't understand where you're going with this though, because
> I wonder why you'd want to save state internally at all?
Well the function is called from here:
try:
contacts =3D ga.getContacts().getAllContacts()
# Just to test save_contacts without having to raise an exception
save_contacts(contacts)
for contact in contacts:
if GM_DEBUG: logging.debug("Removing contact", contact)
ga.removeContact(contact)
except Exception,info:
logging.critical(str(info))
if contacts:
save_contacts(contacts)
The potential problem arises when an exception is raised after the
contacts are removed but
before the new ones are added. (More arguments below)
> Whatever lives
> in Gmail should be the definitive version of the contacts, right? So why
> would we ever need to read from them locally?
In GmailAgent I keep a local address file in the users home dir which
is a copy of the Gmail
contacts online.
GA uses this local address file to prevent logins into Gmail when it's
not really needed.
My idea was that GA should use this local file and when ever the user
changes something
it would be added/changed in the local file. Then when the 'editor' is
closed or opened the user is asked if he wants to import/export a
'fresh' contacts list from Gmail.
When importing/exporting the online list is merged with the online version.
The Gmail contacts is cleared and updated again with all the contacts
from the local file.
I hope this makes any sense, I'm in the middle of implementing it, so
I myself don't know how
the finished contacts framework will look like :-)
You could checkout GA-main and start GmailAgent.py from a xterm and
hit a few address
related buttons, it would be clear what's happening.
> Though I guess it can't hurt.
The thing that keeps bothering me about the whole contacts issue is
that there's a potential
problem with removing/adding contacts. What happens when the
application crashes in the
middle of a libgmail2 action?
You could end up with a (partly) cleared contacts list online, a
contacts list in memory
(contacts =3D ga.getContacts().getAllContacts()) and a application
that's crashed.
What can you do to save the users data?=20
write them to disk before the Python VM exits.=20
I really love apps that saves my work when crashing.
I don't mind an app that screws up but I hate a developer that doesn't save=
s my
data on a screw up. :-/
The (almost) worst thing I can imagine is a email from a GA user that tells=
me:
" GA erased my contacts list, and now I hate you forever!!"
It would be nice to reply:
"You stupid MS lover, your contacts are save and sound on your disk"
:-)
Stas
--=20
"Everything that is really great and inspiring is created by the individual
who can labor in freedom."
-Albert Einstein
|
|
From: Waseem S. D. <wd...@MI...> - 2005-06-04 03:09:33
|
On Fri, 2005-06-03 at 19:08 +0200, Stas Z wrote: > The thing that keeps bothering me about the whole contacts issue is > that there's a potential > problem with removing/adding contacts. What happens when the > application crashes in the > middle of a libgmail2 action? > You could end up with a (partly) cleared contacts list online, a > contacts list in memory > (contacts = ga.getContacts().getAllContacts()) and a application > that's crashed. Yeah, there's no way to guarantee the atomicity of our actions on your gmail account, so this is definitely a valid point. > What can you do to save the users data? > write them to disk before the Python VM exits. > > I really love apps that saves my work when crashing. > I don't mind an app that screws up but I hate a developer that doesn't saves my > data on a screw up. :-/ > > The (almost) worst thing I can imagine is a email from a GA user that tells me: > " GA erased my contacts list, and now I hate you forever!!" > > It would be nice to reply: > "You stupid MS lover, your contacts are save and sound on your disk" > :-) Better safe than sorry. You've convinced me :). Now deciding *when* to save the contacts is another story, but that's something that each application will probably have to figure out. - W |
|
From: Stas Z <sta...@gm...> - 2005-06-04 14:32:53
|
On 6/4/05, Waseem S. Daher <wd...@mi...> wrote: > > > The (almost) worst thing I can imagine is a email from a GA user that t= ells me: > > " GA erased my contacts list, and now I hate you forever!!" > > > > It would be nice to reply: > > "You stupid MS lover, your contacts are save and sound on your disk" > > :-) >=20 > Better safe than sorry. You've convinced me :). Now deciding *when* to > save the contacts is another story, but that's something that each > application will probably have to figure out. Indeed. I'm thinking at which level we could implement some sort of emergency backu= p ideally it would be in libgmail2, hold on don't flame me, It's just a random thought I have :-) For now I will let GA take care of it. Stas --=20 "Everything that is really great and inspiring is created by the individual who can labor in freedom." -Albert Einstein |
|
From: Waseem S. D. <wd...@MI...> - 2005-06-04 16:05:14
|
On Sat, 2005-06-04 at 16:31 +0200, Stas Z wrote: > Indeed. > I'm thinking at which level we could implement some sort of emergency backup > ideally it would be in libgmail2, hold on don't flame me, It's just a > random thought I have :-) > > For now I will let GA take care of it. :-) It really could go either way. My only concern about putting it in libgmail2 is that some applications just don't need it. Imagine I am writing a program that is just going to download your gmail address book and add the entries into Evolution (or something like this). I don't need emergency recovery because I don't delete any contacts -- so why waste my time and space doing it? Though... it's true that some applications will probably want it, and for that reason maybe we want to make a flag in libgmail2 that is like "do emergency backups" or whatever. I'm willing to say it's a feature if we get to it, but I think it should probably be lower on the priority list than adding more functionality. - W |