Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMorgan Collett <morgan.collett@gmail.com>2007-07-09 18:40:10 (GMT)
committer Morgan Collett <morgan.collett@gmail.com>2007-07-09 18:40:10 (GMT)
commit1b065d8d7112a63d5ab86d5b266c297179b4b61d (patch)
treec61233692bd8634801d17b059d5ca4a304e20e54
parentae18c6f3897ee10a2136b36061dab14d465198b1 (diff)
parent136d4e420f67d50f71c96fd97ac9a73b6cdc98c4 (diff)
Merge branch 'master' of git+ssh://dev.laptop.org/git/projects/presence-service
-rw-r--r--NEWS8
-rwxr-xr-xmaint-helper.py221
-rw-r--r--src/activity.py73
-rw-r--r--src/buddy.py24
4 files changed, 315 insertions, 11 deletions
diff --git a/NEWS b/NEWS
new file mode 100644
index 0000000..94b9be7
--- /dev/null
+++ b/NEWS
@@ -0,0 +1,8 @@
+Snapshot e26e3c0294
+
+* Better backoffs with connection retries to avoid hogging the CPU (smcv)
+* Cope with CMs with no presence interface (smcv)
+* Warn if dbus-python is older than 0.82.0 (smcv)
+* Implement PS calls to leave a shared activity (morgs)
+* Fix buddy-left signals (morgs)
+* Fixed regressions from adding salut (smcv, morgs)
diff --git a/maint-helper.py b/maint-helper.py
new file mode 100755
index 0000000..8c64ca2
--- /dev/null
+++ b/maint-helper.py
@@ -0,0 +1,221 @@
+#!/usr/bin/env python
+
+# Copyright (C) 2007, Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+import os
+import sys
+import re
+import datetime
+import subprocess
+
+source_exts = [ '.py', '.c', '.h', '.cpp' ]
+
+def is_source(path):
+ for ext in source_exts:
+ if path.endswith(ext):
+ return True
+
+def get_name_and_version():
+ f = open('configure.ac', 'r')
+ config = f.read()
+ f.close()
+
+ exp = 'AC_INIT\(\[[^\]]+\],\[([^\]]+)\],\[\],\[([^\]]+)\]'
+ match = re.search(exp, config)
+ if not match:
+ print 'Cannot find the package name and version.'
+ sys.exit(0)
+
+ return [ match.group(2), match.group(1) ]
+
+def cmd_help():
+ print 'Usage: \n\
+maint-helper.py build-snapshot - build a source snapshot \n\
+maint-helper.py fix-copyright [path] - fix the copyright year \n\
+maint-helper.py check-licenses - check licenses in the source'
+
+def cmd_build_snapshot():
+ [ name, version ] = get_name_and_version()
+
+ print 'Update git...'
+
+ retcode = subprocess.call(['git', 'pull'])
+ if retcode:
+ print 'ERROR - cannot pull from git'
+
+ cmd = 'git-show-ref --hash=10 refs/heads/master'
+ alphatag = os.popen(cmd).readline().strip()
+
+ tarball = '%s-%s-git%s.tar.bz2' % (name, version, alphatag)
+
+ print 'Build %s...' % tarball
+
+ os.spawnlp(os.P_WAIT, 'make', 'make', 'distcheck')
+
+ os.rename('%s-%s.tar.bz2' % (name, version), tarball)
+
+ print 'Update NEWS.sugar...'
+
+ if os.environ.has_key('SUGAR_NEWS'):
+ sugar_news_path = os.environ['SUGAR_NEWS']
+ if os.path.isfile(sugar_news_path):
+ f = open(sugar_news_path, 'r')
+ sugar_news = f.read()
+ f.close()
+ else:
+ sugar_news = ''
+
+ [ name, version ] = get_name_and_version()
+ sugar_news += '%s - %s - %s\n\n' % (name, version, alphatag)
+
+ f = open('NEWS', 'r')
+ for line in f.readlines():
+ if len(line.strip()) > 0:
+ sugar_news += line
+ else:
+ break
+ f.close()
+
+ f = open(sugar_news_path, 'w')
+ f.write(sugar_news)
+ f.close()
+
+ print 'Update NEWS...'
+
+ f = open('NEWS', 'r')
+ news = f.read()
+ f.close()
+
+ news = 'Snapshot %s\n\n' % alphatag + news
+
+ f = open('NEWS', 'w')
+ f.write(news)
+ f.close()
+
+ print 'Committing to git...'
+
+ changelog = 'Snapshot %s.' % alphatag
+ retcode = subprocess.call(['git', 'commit', '-a', '-m % s' % changelog])
+ if retcode:
+ print 'ERROR - cannot commit to git'
+
+ retcode = subprocess.call(['git', 'push'])
+ if retcode:
+ print 'ERROR - cannot push to git'
+
+ print 'Done.'
+
+def check_licenses(path, license, missing):
+ matchers = { 'LGPL' : 'GNU Lesser General Public',
+ 'GPL' : 'GNU General Public License' }
+
+ license_file = os.path.join(path, '.license')
+ if os.path.isfile(license_file):
+ f = open(license_file, 'r')
+ license = f.readline().strip()
+ f.close()
+
+ for item in os.listdir(path):
+ full_path = os.path.join(path, item)
+
+ if os.path.isdir(full_path):
+ check_licenses(full_path, license, missing)
+ else:
+ check_source = is_source(item)
+
+ # Special cases.
+ if item.find('marshal') > 0 or \
+ item.startswith('egg') > 0:
+ check_source = False
+
+ if check_source:
+ f = open(full_path, 'r')
+ source = f.read()
+ f.close()
+
+ miss_license = True
+ if source.find(matchers[license]) > 0:
+ miss_license = False
+
+ # Special cases.
+ if source.find('THIS FILE IS GENERATED') > 0:
+ miss_license = False
+
+ if miss_license:
+ if not missing.has_key(license):
+ missing[license] = []
+ missing[license].append(full_path)
+
+def cmd_check_licenses():
+ missing = {}
+ check_licenses(os.getcwd(), 'GPL', missing)
+
+ for item in missing.keys():
+ print '%s:\n' % item
+ for path in missing[item]:
+ print path
+ print '\n'
+
+COPYRIGHT = 'Copyright (C) '
+
+def fix_copyright(path):
+ for item in os.listdir(path):
+ full_path = os.path.join(path, item)
+
+ if os.path.isdir(full_path):
+ fix_copyright(full_path)
+ elif is_source(item):
+ f = open(full_path, 'r')
+ source = f.read()
+ f.close()
+
+ year_start = -1
+ year_end = -1
+
+ i1 = source.find(COPYRIGHT)
+ if i1 != -1:
+ i1 += len(COPYRIGHT)
+ i2 = i1 + source[i1:].find(' ')
+ if i1 > 0:
+ try:
+ year_start = int(source[i1:i1 + 4])
+ year_end = int(source[i1 + 6: i1 + 10])
+ except ValueError:
+ pass
+
+ if year_start > 0 and year_end < 0:
+ year_end = year_start
+
+ year = datetime.date.today().year
+ if year_end < year:
+ result = '%s%d-%d%s' % (source[:i1], year_start,
+ year, source[i2:])
+ f = open(full_path, 'w')
+ f.write(result)
+ f.close()
+
+def cmd_fix_copyright(path):
+ fix_copyright(path)
+
+if len(sys.argv) < 2:
+ cmd_help()
+elif sys.argv[1] == 'build-snapshot':
+ cmd_build_snapshot()
+elif sys.argv[1] == 'check-licenses':
+ cmd_check_licenses()
+elif sys.argv[1] == 'fix-copyright' and len(sys.argv) > 2:
+ cmd_fix_copyright(sys.argv[2])
diff --git a/src/activity.py b/src/activity.py
index cc3cf7c..019ac65 100644
--- a/src/activity.py
+++ b/src/activity.py
@@ -137,6 +137,8 @@ class Activity(ExportedGObject):
self._join_cb = None
self._join_err_cb = None
self._join_is_sharing = False
+ self._leave_cb = None
+ self._leave_err_cb = None
# the telepathy client
self._tp = tp
@@ -347,7 +349,7 @@ class Activity(ExportedGObject):
in_signature="", out_signature="",
async_callbacks=('async_cb', 'async_err_cb'))
def Join(self, async_cb, async_err_cb):
- """DBUS method to for the local user to attempt to join the activity
+ """DBUS method for the local user to attempt to join the activity
async_cb -- Callback method to be called if join attempt is successful
async_err_cb -- Callback method to be called if join attempt is
@@ -357,6 +359,19 @@ class Activity(ExportedGObject):
self.join(async_cb, async_err_cb, False)
@dbus.service.method(_ACTIVITY_INTERFACE,
+ in_signature="", out_signature="",
+ async_callbacks=('async_cb', 'async_err_cb'))
+ def Leave(self, async_cb, async_err_cb):
+ """DBUS method to for the local user to leave the shared activity
+
+ async_cb -- Callback method to be called if join attempt is successful
+ async_err_cb -- Callback method to be called if join attempt is
+ unsuccessful
+
+ """
+ self.leave(async_cb, async_err_cb)
+
+ @dbus.service.method(_ACTIVITY_INTERFACE,
in_signature="", out_signature="ao")
def GetJoinedBuddies(self):
"""DBUS method to return a list of valid buddies who are joined in
@@ -461,6 +476,7 @@ class Activity(ExportedGObject):
def _remove_buddies(self, buddies):
buddies = set(buddies)
+ _logger.debug("Removing buddies: %r", buddies)
# disregard any who are not already there
buddies &= self._buddies
@@ -490,6 +506,9 @@ class Activity(ExportedGObject):
"""
if not self._joined:
self._remove_buddies((buddy,))
+ else:
+ # XXX Buddy-left starts working partially at least, if we do this anyway:
+ self._remove_buddies((buddy,))
def _text_channel_group_flags_changed_cb(self, added, removed):
self._text_channel_group_flags |= added
@@ -682,14 +701,56 @@ class Activity(ExportedGObject):
return (str(conn.service_name), conn.object_path,
[self._text_channel.object_path])
- def leave(self):
- """Local method called when the user wants to leave the activity.
+ def leave(self, async_cb, async_err_cb):
+ """Local method for the local user to leave the shared activity.
- (XXX - doesn't appear to be called anywhere!)
+ async_cb -- Callback method to be called with no parameters
+ if join attempt is successful
+ async_err_cb -- Callback method to be called with an Exception
+ parameter if join attempt is unsuccessful
+ The two callbacks are passed to the server_plugin ("tp") object,
+ which in turn passes them back as parameters in a callback to the
+ _left_cb method; this callback is set up within this method.
"""
- if self._joined:
- self._text_channel[CHANNEL_INTERFACE].Close()
+ _logger.debug("Leaving shared activity %s", self._id)
+
+ if not self._joined:
+ _logger.debug("Error: Had not joined activity %s" % self._id)
+ async_err_cb(RuntimeError("Had not joined activity %s"
+ % self._id))
+ return
+
+ if self._leave_cb is not None: # XXX overkill?
+ # FIXME: or should we trigger all the attempts?
+ async_err_cb(RuntimeError('Already trying to leave activity %s'
+ % self._id))
+ return
+
+ self._leave_cb = async_cb
+ self._leave_err_cb = async_err_cb
+
+ self._ps.owner.remove_owner_activity(self._tp, self._id)
+
+ # This also sets self._joined = False:
+ self._text_channel[CHANNEL_INTERFACE].Close() # XXX does this close the whole thing?
+
+ try:
+ #self._ps.owner.remove_activity(self)
+ self._remove_buddies([self._ps.owner]) # XXX XXX XXX FIXME
+ except Exception, e:
+ _logger.debug("XXX Failed to remove you from %s: %s" % (self._id, e))
+ try:
+ self._leave_cb()
+ _logger.debug("Leaving of activity %s succeeded" % self._id)
+ except Exception, e:
+ _logger.debug("Leaving of activity %s failed: %s" % (self._id, e))
+ self._leave_err_cb(e)
+
+ self._leave_cb = None
+ self._leave_err_cb = None
+
+ _logger.debug("triggered leaving on activity %s", self._id)
def _text_channel_members_changed_cb(self, message, added, removed,
local_pending, remote_pending,
diff --git a/src/buddy.py b/src/buddy.py
index 1ec05ff..9e8887e 100644
--- a/src/buddy.py
+++ b/src/buddy.py
@@ -214,6 +214,9 @@ class Buddy(ExportedGObject):
self._icon = str(icon_data)
self.IconChanged(self._icon)
+ def __repr__(self):
+ return '<ps.buddy.Buddy %s>' % self._nick
+
def do_get_property(self, pspec):
"""Retrieve current value for the given property specifier
@@ -633,6 +636,15 @@ class GenericOwner(Buddy):
self._set_self_activities(tp)
+ def remove_owner_activity(self, tp, activity_id):
+ # FIXME: this probably duplicates something else (_activities?)
+ # but for now I'll keep the same duplication as before.
+ # Equivalent code used to be in ServerPlugin.
+ id_to_act = self._activities_by_connection.setdefault(tp, {})
+ del id_to_act[activity_id]
+
+ self._set_self_activities(tp)
+
def _set_self_activities(self, tp):
"""Forward set of joined activities to network
@@ -642,7 +654,7 @@ class GenericOwner(Buddy):
if CONN_INTERFACE_BUDDY_INFO not in conn:
_logger.warning('%s does not support BuddyInfo - unable to '
- 'set activities')
+ 'set activities' % conn.object_path)
return
conn[CONN_INTERFACE_BUDDY_INFO].SetActivities(
@@ -675,7 +687,7 @@ class GenericOwner(Buddy):
if CONN_INTERFACE_BUDDY_INFO not in conn:
_logger.warning('%s does not support BuddyInfo - unable to '
- 'set current activity')
+ 'set current activity' % conn.object_path)
return
conn[CONN_INTERFACE_BUDDY_INFO].SetCurrentActivity(cur_activity,
@@ -690,7 +702,7 @@ class GenericOwner(Buddy):
if CONN_INTERFACE_ALIASING not in conn:
_logger.warning('%s does not support aliasing - unable to '
- 'set my own alias')
+ 'set my own alias' % conn.object_path)
return False
conn[CONN_INTERFACE_ALIASING].SetAliases({self_handle: self._nick},
@@ -721,7 +733,8 @@ class GenericOwner(Buddy):
if connected:
if CONN_INTERFACE_BUDDY_INFO not in conn:
_logger.warning('%s does not support BuddyInfo - unable to '
- 'set my own buddy properties')
+ 'set my own buddy properties' %
+ conn.object_path)
return False
conn[CONN_INTERFACE_BUDDY_INFO].SetProperties(props,
@@ -777,7 +790,8 @@ class GenericOwner(Buddy):
if CONN_INTERFACE_AVATARS not in conn:
_logger.warning('%s does not support Avatars - unable to '
- 'set my own avatar on this connection')
+ 'set my own avatar on this connection' %
+ conn.object_path)
return
m = new_md5()