Log In
New Account
  
Home My Page Project Cloud Code Snippets Project Openings Hermes
Summary Lists News SCM
authorAndrew Flegg <andrew@bleb.org>
Thu, 10 Jun 2010 09:42:43 +0000 (10:42 +0100)
committerAndrew Flegg <andrew@bleb.org>
Thu, 10 Jun 2010 09:42:43 +0000 (10:42 +0100)
package/Makefile
package/debian/changelog
package/src/hermes.py [deleted file]
package/src/main.py

index 7a26939..a66a590 100644 (file)
@@ -11,14 +11,16 @@ compile:
 
 install:
        mkdir -p ${DESTDIR}/opt/hermes/lib ${DESTDIR}/opt/hermes/bin ${DESTDIR}/opt/hermes/share
-       ln -s ../lib/gui.py ${DESTDIR}/opt/hermes/bin/hermes
+       ln -s ../lib/main.py ${DESTDIR}/opt/hermes/bin/hermes
+       cp -r src/* ${DESTDIR}/opt/hermes/lib/
+       chown -R root:root ${DESTDIR}/opt/hermes/lib/
        install -D -m 0644 -o root -g root src/*.py* ${DESTDIR}/opt/hermes/lib/
        install -D -m 0644 -o root -g root share/account-*.png share/background.png ${DESTDIR}/opt/hermes/share/
        install -D -m 0644 -o root -g root share/hermes-64.png ${DESTDIR}/usr/share/icons/hicolor/scalable/hildon/hermes.png
        install -D -m 0644 -o root -g root share/hermes-48.png ${DESTDIR}/usr/share/icons/hicolor/48x48/hildon/hermes.png
        install -D -m 0644 -o root -g root share/hermes.desktop ${DESTDIR}/usr/share/applications/hildon/hermes.desktop
        install -D -m 0644 -o root -g root share/hermes.service ${DESTDIR}/usr/share/dbus-1/services/hermes.service
-       chmod 755 ${DESTDIR}/opt/hermes/lib/gui.py
+       chmod 755 ${DESTDIR}/opt/hermes/lib/main.py
        cd po && $(MAKE) install 
 
 clean:
index d8fff12..03620db 100644 (file)
@@ -1,3 +1,11 @@
+hermes (0.8.0) unstable; urgency=low
+
+  * Enormous refactor to support additional services, with Gravatar
+    and LinkedIn in this version; with enormous contribution by
+    Fredrik Wendt.
+
+ -- Andrew Flegg <andrew@bleb.org>  Thu, 10 Jun 2010 08:55:05 +0100
+
 hermes (0.2.3) unstable; urgency=low
 
   * Include i18n mechanism (requested by Tomasz Dominikowski, provided by
diff --git a/package/src/hermes.py b/package/src/hermes.py
deleted file mode 100644 (file)
index 411ca56..0000000
+++ /dev/null
@@ -1,273 +0,0 @@
-import os.path
-import evolution
-from facebook import Facebook, FacebookError
-import twitter
-import trans
-import gnome.gconf
-from contacts import ContactStore
-import names
-
-class Hermes:
-    """Encapsulate the process of syncing Facebook friends' information with the
-       Evolution contacts' database. This should be used as follows:
-       
-         * Initialise, passing in a callback (methods: need_auth(),
-           block_for_auth(), use_twitter(), use_facebook()).
-         * Call load_friends().
-         * Call sync_contacts().
-         * Retrieve information on changes effected.
-         
-       This requires two gconf paths to contain Facebook application keys:
-           /apps/maemo/hermes/key_app
-           /apps/maemo/hermes/key_secret
-         
-       Copyright (c) Andrew Flegg <andrew@bleb.org> 2009.
-       Released under the Artistic Licence."""
-    
-    
-    # -----------------------------------------------------------------------
-    def __init__(self, callback, twitter = None, facebook = False, empty = False):
-        """Constructor. Passed a callback which must implement three informational
-           methods:
-           
-             need_auth() - called to indicate a login is about to occur. The user
-                           should be informed.
-                           
-             block_for_auth() - prompt the user to take some action once they have
-                                successfully logged in to Facebook.
-                              
-             progress(i, j) - the application is currently processing friend 'i' of
-                              'j'. Should be used to provide the user a progress bar.
-                              
-          Other parameters:
-             twitter - a username/password tuple or None if Twitter should not be
-                       used. Defaults to None.
-                       
-             facebook - boolean indicating if Facebook should be used. Defaults to
-                        False.
-        
-             empty - boolean indicating if 'empty' contacts consisting of a profile
-                     URL and birthday should be created.
-                              """
-        
-        self.gc       = gnome.gconf.client_get_default()
-        self.callback = callback
-        self.twitter  = twitter
-        self.facebook = facebook
-        self.create_empty = empty
-        
-        # -- Check the environment is going to work...
-        #
-        if (self.gc.get_string('/desktop/gnome/url-handlers/http/command') == 'epiphany %s'):
-            raise Exception('Browser in gconf invalid (see NB#136012). Installation error.')
-        
-        # -- Get private keys for this app...
-        #
-        key_app    = self.gc.get_string('/apps/maemo/hermes/key_app')
-        key_secret = self.gc.get_string('/apps/maemo/hermes/key_secret')
-        if key_app is None or key_secret is None:
-            raise Exception('No Facebook application keys found. Installation error.')
-        
-        self.fb = Facebook(key_app, key_secret)
-        self.fb.desktop = True
-    
-    
-    # -----------------------------------------------------------------------
-    def do_fb_login(self):
-        """Perform authentication against Facebook and store the result in gconf
-             for later use. Uses the 'need_auth' and 'block_for_auth' methods on
-             the callback class. The former allows a message to warn the user
-             about what is about to happen to be shown; the second is to wait
-             for the user to confirm they have logged in."""
-        self.fb.session_key = None
-        self.fb.secret = None
-        self.fb.uid = None
-        
-        self.callback.need_auth()
-        self.fb.auth.createToken()
-        self.fb.login()
-        self.callback.block_for_auth()
-        session = self.fb.auth.getSession()
-        
-        self.gc.set_string('/apps/maemo/hermes/session_key', session['session_key'])
-        self.gc.set_string('/apps/maemo/hermes/secret_key', session['secret'])
-        self.gc.set_string('/apps/maemo/hermes/uid', str(session['uid']))
-    
-    
-    # -----------------------------------------------------------------------
-    def load_friends(self):
-        """Load information on the authenticated user's friends. If no user is
-           currently authenticated, prompts for a login."""
-        
-        self.friends = {}
-        self.blocked_pictures = []
-        self.callback.progress(0, 0)
-        self.friends_by_url = {}
-        
-        # -- Get a user session and retrieve Facebook friends...
-        #
-        if self.facebook:
-            print "+++ Opening Facebook..."
-            if self.fb.session_key is None:
-                self.fb.session_key = self.gc.get_string('/apps/maemo/hermes/session_key')
-                self.fb.secret = self.gc.get_string('/apps/maemo/hermes/secret_key')
-                self.fb.uid = self.gc.get_string('/apps/maemo/hermes/uid')
-            
-            # Check the available session is still valid...
-            while True:
-                try:
-                    if self.fb.users.getLoggedInUser() and self.fb.session_key:
-                        break
-                except FacebookError:
-                    pass
-                self.do_fb_login()
-            
-            # Get the list of friends...
-            attrs = ['uid', 'name', 'pic_big', 'birthday_date', 'profile_url', 'first_name', 'last_name', 'website']
-            for friend in self.fb.users.getInfo(self.fb.friends.get(), attrs):
-                key = unicode(friend['name']).encode('trans')
-                self.friends[key] = friend
-            
-                if 'profile_url' not in friend:
-                    friend['profile_url'] = "http://www.facebook.com/profile.php?id=" + str(friend ['uid'])
-            
-                self.friends_by_url[friend['profile_url']] = friend
-                friend['pic']  = friend[attrs[2]]
-                friend['account'] = 'facebook'
-            
-                if 'website' in friend and friend['website']:
-                    friend['homepage'] = friend['website']
-            
-                if 'pic' not in friend or not friend['pic']:
-                    self.blocked_pictures.append(friend)
-              
-              
-        # -- Retrieve following information from Twitter...
-        #
-        if self.twitter is not None:
-            print "+++ Opening Twitter..."
-            (user, passwd) = self.twitter
-            api = twitter.Api(username=user, password=passwd)
-            users = api.GetFriends()
-            for tweeter in api.GetFriends():
-                key    = unicode(tweeter.name).encode('trans')
-                url    = 'http://twitter.com/%s' % (tweeter.screen_name)
-                friend = {'name':          tweeter.name, 'pic': tweeter.profile_image_url,
-                          'birthday_date': None,         'twitter_url': url,
-                          'homepage':      tweeter.url,  'account': 'twitter'}
-                if friend['pic'].find('/default_profile') > -1:
-                    friend['pic'] = None
-              
-                self.friends[key] = friend
-                self.friends_by_url[url] = friend
-        
-        # TODO What if the user has *no* contacts?
-    
-    
-    # -----------------------------------------------------------------------
-    def sync_contacts(self, resync = False):
-        """Synchronise Facebook profiles to contact database. If resync is false,
-           no existing information will be overwritten."""
-        
-        # -- Find addresses...
-        #
-        print "+++ Syncing contacts..."
-        self.addresses = evolution.ebook.open_addressbook('default')
-        print "+++ Addressbook opened..."
-        self.store = ContactStore(self.addresses)
-        print "+++ Contact store created..."
-        self.updated = []
-        self.unmatched = []
-        self.matched = []
-        contacts = self.addresses.get_all_contacts()
-        contacts.sort(key=lambda obj: obj.get_name())
-        current = 0
-        maximum = len(contacts)
-        for contact in contacts:
-            current += 1
-            self.callback.progress(current, maximum)
-            found = False
-            updated = False
-            
-            # Try match on existing URL...
-            for url in self.store.get_urls(contact):
-                if url in self.friends_by_url:
-                    updated = self.update_contact(contact, self.friends_by_url[url], resync)
-                    found = True
-                    if updated:
-                        break
-            
-            # Fallback to names...
-            if not found:
-                for name in names.variants(contact.get_name()):
-                    if name in self.friends:
-                        updated = self.update_contact(contact, self.friends[name], resync)
-                        found = True
-                        if updated:
-                            break
-            
-            # Keep track of updated stuff...
-            if updated:
-                self.updated.append(contact)
-                self.addresses.commit_contact(contact)
-                print "Saved changes to [%s]" % (contact.get_name())
-            
-            if found:
-                self.matched.append(contact)
-            else:
-                self.unmatched.append(contact)
-        
-        # -- Create 'empty' contacts with birthdays...
-        #
-        if self.create_empty:
-            for name in self.friends:
-                friend = self.friends[name]
-                if 'contact' in friend or 'birthday_date' not in friend or not friend['birthday_date']:
-                    continue
-                
-                contact = evolution.ebook.EContact()
-                contact.props.full_name = friend['name']
-                contact.props.given_name = friend['first_name']
-                contact.props.family_name = friend['last_name']
-                
-                self.update_contact(contact, friend)
-                
-                self.addresses.add_contact(contact)
-                self.updated.append(contact)
-                self.addresses.commit_contact(contact)
-                
-                print "Created [%s]" % (contact.get_name())
-                self.matched.append(contact)
-        
-        self.store.close()
-    
-    
-    # -----------------------------------------------------------------------
-    def update_contact(self, contact, friend, resync = False):
-        """Update the given contact with information from the 'friend'
-           dictionary."""
-        
-        updated = False
-        friend['contact'] = contact
-          
-        if 'pic' in friend and friend['pic'] and (resync or contact.get_property('photo') is None):
-            updated = self.store.set_photo(contact, friend['pic']) or updated
-            
-        if 'birthday_date' in friend and friend['birthday_date'] and (resync or contact.get_property('birth-date') is None):
-            date_str = friend['birthday_date'].split('/')
-            date_str.append('0')
-            updated = self.store.set_birthday(contact, int(date_str[1]),
-                                                       int(date_str[0]),
-                                                       int(date_str[2])) or updated
-        
-        if 'profile_url' in friend and friend['profile_url']:
-            updated = self.store.add_url(contact, friend['profile_url'], unique='facebook.com') or updated
-                
-        if 'twitter_url' in friend and friend['twitter_url']:
-            updated = self.store.add_url(contact, friend['twitter_url'], unique='twitter.com') or updated
-                
-        if 'homepage' in friend and friend['homepage']:
-            updated = self.store.add_url(contact, friend['homepage']) or updated
-        
-        return updated 
-
index 016b14e..38bf6a9 100644 (file)
@@ -16,8 +16,8 @@ if gnome.gconf.client_get_default().get_string('/desktop/gnome/url-handlers/http
 #
 gui = HermesGUI(providers = [
                  org.maemo.hermes.engine.facebook.provider.Provider(),
-                 org.maemo.hermes.engine.twitter.provider.Provider(),
                  org.maemo.hermes.engine.linkedin.provider.Provider(),
+                 org.maemo.hermes.engine.twitter.provider.Provider(),
                  org.maemo.hermes.engine.gravatar.provider.Provider(),
              ])
 gui.run()

Terms of Use    Privacy Policy    Contribution Guidelines    Feedback

Powered By GForge Collaborative Development Environment