plugin_pack.py
author John Bailey <rekkanoryo@rekkanoryo.org>
Sun Aug 30 20:10:58 2009 -0400 (2009-08-30)
changeset 1046 93089a7ce7f6
parent 966 770d26fae93e
permissions -rwxr-xr-x
Merge
grim@769
     1
#!/usr/bin/python
grim@769
     2
grim@774
     3
# plugin_pack.py - Helper script for obtaining info about the plugin pack
grim@774
     4
# Copyright (C) 2008 Gary Kramlich <grim@reaperworld.com>
grim@774
     5
#
grim@774
     6
# This program is free software; you can redistribute it and/or
grim@774
     7
# modify it under the terms of the GNU General Public License
grim@774
     8
# as published by the Free Software Foundation; either version 2
grim@774
     9
# of the License, or (at your option) any later version.
grim@774
    10
#
grim@774
    11
# This program is distributed in the hope that it will be useful,
grim@774
    12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
grim@774
    13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
grim@774
    14
# GNU General Public License for more details.
grim@774
    15
#
grim@774
    16
# You should have received a copy of the GNU General Public License
grim@774
    17
# along with this program; if not, write to the Free Software
grim@774
    18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301, USA.
grim@774
    19
grim@793
    20
"""Usage: plugin_pack.py [OPTION...] command
grim@774
    21
grim@802
    22
Flags:
grim@802
    23
grim@793
    24
  -a  Load abusive plugins
grim@793
    25
  -d  Load default plugins
grim@953
    26
  -i  Load incomplate plugins
grim@953
    27
grim@793
    28
  -f  Load finch plugins
grim@793
    29
  -p  Load purple plugins
grim@793
    30
  -P  Load pidgin plugins
grim@793
    31
grim@793
    32
Commands:
grim@774
    33
"""
grim@774
    34
grim@769
    35
import ConfigParser
grim@774
    36
import getopt
grim@769
    37
import glob
grim@769
    38
import os.path
grim@774
    39
import string
grim@769
    40
import sys
grim@769
    41
grim@869
    42
webpage = 'http://plugins.guifications.org/'
grim@869
    43
grim@770
    44
def printerr(msg):
grim@770
    45
	print >> sys.stderr, msg
grim@769
    46
grim@769
    47
class Plugin:
grim@769
    48
	name = ''
grim@781
    49
	directory = ''
grim@781
    50
	type = ''
grim@781
    51
	depends = []
grim@770
    52
	provides = ''
grim@769
    53
	summary = ''
grim@769
    54
	description = ''
grim@781
    55
	authors = []
grim@781
    56
	introduced = ''
grim@781
    57
	notes = ''
grim@769
    58
grim@769
    59
	def __init__(self, directory, name, parser):
grim@770
    60
		self.name = name
grim@769
    61
grim@781
    62
		self.directory = directory
grim@781
    63
grim@781
    64
		self.type = parser.get(name, 'type')
grim@781
    65
		self.depends = parser.get(name, 'depends').split()
grim@770
    66
		self.provides = parser.get(name, 'provides')
grim@769
    67
		self.summary = parser.get(name, 'summary')
grim@769
    68
		self.description = parser.get(name, 'description')
grim@781
    69
		self.authors = parser.get(name, 'authors').split(',')
grim@781
    70
		self.introduced = parser.get(name, 'introduced')
grim@781
    71
grim@781
    72
		if parser.has_option(name, 'notes'):
grim@781
    73
			self.notes = parser.get(name, 'notes')
grim@769
    74
grim@770
    75
		if self.type != 'default' and self.type != 'incomplete' and self.type != 'abusive':
grim@770
    76
			printerr('\'%s\' has an unknown type of \'%s\'!' % (self.name, self.type))
grim@770
    77
grim@769
    78
	def __str__(self):
grim@774
    79
		output  = 'name: %s\n' % self.name
grim@793
    80
		output += 'authors: %s\n' % string.join(self.authors, ', ')
grim@774
    81
		output += 'type: %s\n' % self.type
grim@774
    82
		output += 'depends: %s\n' % string.join(self.depends, ' ')
grim@774
    83
		output += 'provides: %s\n' % self.provides
grim@774
    84
		output += 'directory: %s\n' % self.directory
grim@774
    85
		output += 'summary: %s\n' % self.summary
grim@781
    86
		output += 'description: %s\n' % self.description
grim@781
    87
grim@781
    88
		if self.notes:
grim@781
    89
			output += 'notes: %s\n' % self.notes
grim@774
    90
grim@774
    91
		return output
grim@769
    92
grim@770
    93
class PluginPack:
grim@793
    94
	commands = {}
grim@774
    95
	plugins = {}
grim@769
    96
grim@792
    97
	def load_plugins(self, types, depends):
grim@792
    98
		if len(types) == 0:
grim@792
    99
			types = None
grim@792
   100
grim@792
   101
		if len(depends) == 0:
grim@792
   102
			depends = None
grim@792
   103
grim@770
   104
		for file in glob.glob('*/plugins.cfg'):
grim@770
   105
			parser = ConfigParser.ConfigParser()
grim@769
   106
grim@770
   107
			try:
grim@770
   108
				parser.read(file)
grim@770
   109
			except ConfigParser.ParsingError,  msg:
grim@770
   110
				printerr('Failed to parse \'%s\':\n%s' % (file, msg))
grim@769
   111
				continue
grim@769
   112
grim@770
   113
			for plugin in parser.sections():
grim@770
   114
				p = Plugin(os.path.dirname(file), plugin, parser)
grim@769
   115
grim@792
   116
				# this is kind of hacky, but if we have types, we check to see
grim@792
   117
				# if the type is in list of types to load.
grim@810
   118
				if types and not p.type in types:
grim@810
   119
					continue
grim@792
   120
				
grim@792
   121
				# now we check if the give plugins depends match the search
grim@792
   122
				# depends
grim@792
   123
				if depends:
grim@792
   124
					if len(set(depends).intersection(set(p.depends))) == 0:
grim@792
   125
						continue
grim@792
   126
grim@793
   127
				self.plugins[p.provides] = p
grim@770
   128
grim@774
   129
	def list_type(self, type):
grim@770
   130
		list = []
grim@770
   131
grim@774
   132
		for name in self.plugins.keys():
grim@774
   133
			plugin = self.plugins[name]
grim@770
   134
			if plugin.type == type:
grim@770
   135
				list.append(plugin)
grim@770
   136
grim@774
   137
		list.sort()
grim@774
   138
grim@770
   139
		return list
grim@770
   140
grim@801
   141
	def list_dep(self, dep):
grim@801
   142
		list = []
grim@801
   143
grim@801
   144
		for name in self.plugins.keys():
grim@801
   145
			plugin = self.plugins[name]
grim@801
   146
grim@810
   147
			if dep in plugin.depends:
grim@801
   148
				list.append(plugin)
grim@801
   149
grim@801
   150
		list.sort()
grim@801
   151
grim@801
   152
		return list
grim@801
   153
grim@774
   154
	def print_names(self, list):
grim@774
   155
		names = []
grim@811
   156
grim@774
   157
		for plugin in list:
grim@774
   158
			names.append(plugin.name)
grim@770
   159
grim@774
   160
		print string.join(names, ',')
grim@770
   161
grim@774
   162
	def default_plugins(self):
grim@774
   163
		return self.list_type('default')
grim@774
   164
grim@774
   165
	def abusive_plugins(self):
grim@774
   166
		return self.list_type('abusive')
grim@774
   167
grim@774
   168
	def incomplete_plugins(self):
grim@774
   169
		return self.list_type('incomplete')
grim@774
   170
grim@801
   171
	def purple_plugins(self):
grim@801
   172
		return self.list_dep('purple')
grim@801
   173
grim@801
   174
	def finch_plugins(self):
grim@801
   175
		return self.list_dep('finch')
grim@801
   176
grim@801
   177
	def pidgin_plugins(self):
grim@801
   178
		return self.list_dep('pidgin')
grim@801
   179
grim@800
   180
	def unique_dirs(self):
grim@800
   181
		dirs = {}
grim@800
   182
		for name in self.plugins.keys():
grim@800
   183
			dirs[self.plugins[name].directory] = 1
grim@800
   184
grim@800
   185
		dirs = dirs.keys()
grim@800
   186
		dirs.sort()
grim@800
   187
grim@800
   188
		return dirs
grim@800
   189
grim@793
   190
	def help(self, args):
grim@802
   191
		"""Displays information about other commands"""
grim@793
   192
		try:
grim@793
   193
			cmd = self.commands[args[0]]
grim@793
   194
			print cmd.__doc__
grim@793
   195
		except KeyError:
grim@793
   196
			print 'command \'%s\' was not found' % args[0]
grim@793
   197
		except IndexError:
grim@890
   198
			print '%s' % (self.help.__doc__)
grim@889
   199
			print
grim@889
   200
			print 'help usage:'
grim@889
   201
			print '  help <command>'
grim@889
   202
			print
grim@889
   203
			print 'Available commands:'
grim@889
   204
grim@889
   205
			cmds = self.commands.keys()
grim@889
   206
			cmds.remove('help')
grim@889
   207
			cmds.sort()
grim@889
   208
			print '  %s' % (string.join(cmds, ' '))
grim@793
   209
	commands['help'] = help
grim@793
   210
grim@793
   211
	def dist_dirs(self, args):
grim@802
   212
		"""Displays a list of all plugin directories to included in the distribution"""
grim@800
   213
		print string.join(self.unique_dirs(), ' ')
grim@800
   214
	commands['dist_dirs'] = dist_dirs
grim@793
   215
grim@811
   216
	def build_dirs(self, args):
grim@814
   217
		"""Displays a list of the plugins that can be built"""
grim@811
   218
		if len(args) != 2:
grim@816
   219
			printerr('build_dirs expects 2 arguments:')
grim@816
   220
			printerr('\ta comma separated list of dependencies')
grim@816
   221
			printerr('\ta comma separated list of plugins to build')
grim@811
   222
			sys.exit(1)
grim@811
   223
grim@811
   224
		# store the external depedencies
grim@811
   225
		externals = args[0].split(',')
grim@811
   226
grim@811
   227
		deps = {}
grim@811
   228
grim@811
   229
		# run through the provided dependencies, setting their dependencies to
grim@811
   230
		# nothing since we know we already have them
grim@811
   231
		for d in externals:
grim@811
   232
			deps[d] = []
grim@811
   233
grim@811
   234
		# now run through the plugins adding their deps to the dictionary
grim@811
   235
		for name in self.plugins.keys():
grim@811
   236
			plugin = self.plugins[name]
grim@811
   237
grim@811
   238
			deps[plugin.provides] = plugin.depends
grim@811
   239
grim@811
   240
		# run through the requested plugins and store their plugin instance in check
grim@811
   241
		check = []
grim@811
   242
		for provides in args[1].split(','):
grim@811
   243
			try:
grim@811
   244
				if provides == 'all':
grim@811
   245
					defaults = []
grim@811
   246
					for p in self.default_plugins():
grim@811
   247
						defaults.append(p.provides)
grim@811
   248
grim@811
   249
					check += defaults
grim@811
   250
grim@811
   251
					continue
grim@811
   252
grim@811
   253
				plugin = self.plugins[provides]
grim@811
   254
				check.append(plugin.provides)
grim@811
   255
			except KeyError:
grim@811
   256
				continue
grim@811
   257
grim@811
   258
		# convert our list of plugins to check into a set to remove dupes
grim@811
   259
		#check = set(check)
grim@811
   260
grim@811
   261
		# create our list of plugins to build
grim@811
   262
		build = []
grim@811
   263
grim@811
   264
		# now define a function to check our deps
grim@811
   265
		def has_deps(provides):
grim@811
   266
			# don't add anything to build more than once
grim@811
   267
			if provides in build:
grim@811
   268
				return True
grim@811
   269
grim@811
   270
			try:
grim@811
   271
				dep_list = deps[provides]
grim@811
   272
			except KeyError:
grim@811
   273
				return False
grim@811
   274
grim@811
   275
			# now check the dependencies
grim@811
   276
			for dep in dep_list:
grim@984
   277
				if '|' in dep:
grim@984
   278
					count = 0
grim@984
   279
					for d in dep.split('|'):
grim@984
   280
						if has_deps(d):
grim@984
   281
							count += 1
grim@984
   282
grim@984
   283
					if count == 0:
grim@984
   284
						return False
grim@984
   285
				else:
grim@984
   286
					if not has_deps(dep):
grim@984
   287
						return False
grim@811
   288
grim@811
   289
			# make sure the provides isn't an external
grim@811
   290
			if not provides in externals:
grim@811
   291
				build.append(provides)
grim@811
   292
grim@811
   293
			# everything checks out!
grim@811
   294
			return True
grim@811
   295
grim@811
   296
		# check all the plugins we were told to for their dependencies
grim@811
   297
		for c in check:
grim@811
   298
			has_deps(c)
grim@811
   299
grim@812
   300
		# now create a list of all directories to build
grim@812
   301
		output = []
grim@811
   302
grim@811
   303
		for provides in build:
grim@811
   304
			plugin = self.plugins[provides]
grim@811
   305
grim@812
   306
			output.append(plugin.directory)
grim@811
   307
grim@812
   308
		output.sort()
grim@812
   309
grim@812
   310
		print "%s" % (string.join(output, ','))
grim@811
   311
	commands['build_dirs'] = build_dirs
grim@857
   312
	
grim@857
   313
	def list_plugins(self, args):
grim@889
   314
		"""Displays a list similiar to 'dpkg -l' about the plugin pack"""
grim@889
   315
grim@857
   316
		data = {}
grim@857
   317
grim@857
   318
		# create an array for the widths, we initialize it to the lengths of
grim@857
   319
		# the title strings.  We ignore summary, since that one shouldn't
grim@857
   320
		# matter.
grim@857
   321
		widths = [4, 8, 0]
grim@857
   322
grim@857
   323
		for p in self.plugins.keys():
grim@857
   324
			plugin = self.plugins[p]
grim@857
   325
grim@857
   326
			if plugin.type == 'abusive':
grim@857
   327
				type = 'a'
grim@857
   328
			elif plugin.type == 'incomplete':
grim@857
   329
				type = 'i'
grim@857
   330
			else:
grim@857
   331
				type = 'd'
grim@857
   332
grim@857
   333
			if 'finch' in plugin.depends:
grim@857
   334
				ui = 'f'
grim@857
   335
			elif 'pidgin' in plugin.depends:
grim@857
   336
				ui = 'p'
grim@857
   337
			elif 'purple' in plugin.depends:
grim@857
   338
				ui = 'r'
grim@857
   339
			else:
grim@857
   340
				ui = 'u'
grim@857
   341
grim@857
   342
			widths[0] = max(widths[0], len(plugin.name))
grim@857
   343
			widths[1] = max(widths[1], len(plugin.provides))
grim@857
   344
			widths[2] = max(widths[2], len(plugin.summary))
grim@857
   345
grim@857
   346
			data[plugin.provides] = [type, ui, plugin.name, plugin.provides, plugin.summary]
grim@857
   347
grim@857
   348
		print 'Type=Default/Incomplete/Abusive'
grim@857
   349
		print '| UI=Finch/Pidgin/puRple/Unknown'
grim@857
   350
		print '|/ Name%s Provides%s Summary' % (' ' * (widths[0] - 4), ' ' * (widths[1] - 8))
grim@857
   351
		print '++-%s-%s-%s' % ('=' * (widths[0]), '=' * (widths[1]), '=' * (widths[2]))
grim@857
   352
grim@857
   353
		# create the format var
grim@857
   354
		fmt = '%%s%%s %%-%ds %%-%ds %%s' % (widths[0], widths[1]) #, widths[2])
grim@857
   355
grim@857
   356
		# now loop through the list again, with everything formatted
grim@857
   357
		list = data.keys()
grim@857
   358
		list.sort()
grim@857
   359
grim@857
   360
		for p in list:
grim@857
   361
			d = data[p]
grim@857
   362
			print fmt % (d[0], d[1], d[2], d[3], d[4])
grim@857
   363
	commands['list'] = list_plugins
grim@811
   364
grim@800
   365
	def config_file(self, args):
grim@800
   366
		"""Outputs the contents for the file to be m4_include()'d from configure"""
grim@803
   367
		uniqdirs = self.unique_dirs()
grim@803
   368
grim@814
   369
		# add our --with-plugins option
grim@814
   370
		print 'AC_ARG_WITH(plugins,'
grim@814
   371
		print '            AC_HELP_STRING([--with-plugins], [what plugins to build]),'
grim@966
   372
		print '            ,with_plugins=all)'
grim@966
   373
		print 'if test -z $with_plugins ; then'
grim@966
   374
		print '\twith_plugins=all'
grim@966
   375
		print 'fi'
grim@814
   376
grim@814
   377
		# determine and add our output files
grim@803
   378
		print 'PP_DIST_DIRS="%s"' % (string.join(uniqdirs, ' '))
grim@803
   379
		print 'AC_SUBST(PP_DIST_DIRS)'
grim@803
   380
		print
grim@803
   381
		print 'AC_CONFIG_FILES(['
grim@803
   382
		for dir in uniqdirs:
grim@803
   383
			print '\t%s/Makefile' % (dir)
grim@803
   384
		print '])'
grim@814
   385
		print
grim@814
   386
grim@814
   387
		# setup a second call to determine the plugins to be built
grim@966
   388
		print 'PP_BUILD=`$PYTHON $srcdir/plugin_pack.py build_dirs $DEPENDENCIES $with_plugins`'
grim@814
   389
		print
grim@814
   390
		print 'PP_BUILD_DIRS=`echo $PP_BUILD | sed \'s/,/\ /g\'`'
grim@814
   391
		print 'AC_SUBST(PP_BUILD_DIRS)'
grim@814
   392
		print
grim@816
   393
		print 'PP_PURPLE_BUILD="$PYTHON $srcdir/plugin_pack.py -p show_names $PP_BUILD"'
grim@816
   394
		print 'PP_PIDGIN_BUILD="$PYTHON $srcdir/plugin_pack.py -P show_names $PP_BUILD"'
grim@816
   395
		print 'PP_FINCH_BUILD="$PYTHON $srcdir/plugin_pack.py -f show_names $PP_BUILD"'
grim@800
   396
	commands['config_file'] = config_file
grim@793
   397
grim@793
   398
	def dependency_graph(self, args):
grim@802
   399
		"""Outputs a graphviz script showing plugin dependencies"""
grim@774
   400
		def node_label(plugin):
grim@774
   401
			node = plugin.provides.replace('-', '_')
grim@774
   402
			label = plugin.name
grim@774
   403
grim@774
   404
			return node, label
grim@774
   405
grim@774
   406
		def print_plugins(list):
grim@774
   407
			for plugin in list:
grim@774
   408
				node, label = node_label(plugin)
grim@774
   409
grim@774
   410
				print '\t%s[label="%s"];' % (node, label)
grim@774
   411
grim@774
   412
		print 'digraph {'
grim@774
   413
		print '\tlabel="Dependency Graph";'
grim@774
   414
		print '\tlabelloc="t";'
grim@774
   415
		print '\tsplines=TRUE;'
grim@785
   416
		print '\toverlap=FALSE;'
grim@774
   417
		print
grim@785
   418
		print '\tnode[fontname="sans", fontsize="8", style="filled"];'
grim@774
   419
		print
grim@774
   420
grim@774
   421
		# run through the default plugins
grim@774
   422
		print '\t/* default plugins */'
grim@785
   423
		print '\tnode[fillcolor="palegreen",shape="tab"];'
grim@774
   424
		print_plugins(self.default_plugins())
grim@774
   425
		print
grim@774
   426
grim@774
   427
		# run through the incomplete plugins
grim@774
   428
		print '\t/* incomplete plugins */'
grim@785
   429
		print '\tnode[fillcolor="lightyellow1",shape="note"];'
grim@774
   430
		print_plugins(self.incomplete_plugins())
grim@774
   431
		print
grim@774
   432
grim@774
   433
		# run through the abusive plugins
grim@774
   434
		print '\t/* abusive plugins */'
grim@785
   435
		print '\tnode[fillcolor="lightpink",shape="octagon"];'
grim@774
   436
		print_plugins(self.abusive_plugins())
grim@774
   437
		print
grim@774
   438
grim@774
   439
		# run through again, this time showing the relations
grim@774
   440
		print '\t/* dependencies'
grim@774
   441
		print '\t * exteranl ones that don\'t have nodes get colored to the following'
grim@774
   442
		print '\t */'
grim@785
   443
		print '\tnode[fillcolor="powderblue", shape="egg"];'
grim@774
   444
grim@774
   445
		for name in self.plugins.keys():
grim@774
   446
			plugin = self.plugins[name]
grim@774
   447
grim@774
   448
			node, label = node_label(plugin)
grim@774
   449
grim@774
   450
			for dep in plugin.depends:
grim@774
   451
				dep = dep.replace('-', '_')
grim@774
   452
				print '\t%s -> %s;' % (node, dep)
grim@774
   453
grim@774
   454
		print '}'
grim@793
   455
	commands['dependency_graph'] = dependency_graph
grim@793
   456
grim@869
   457
	def debian_description(self, args):
grim@889
   458
		"""Outputs the description for the Debian packages"""
grim@871
   459
		print 'Description: %d useful plugins for Pidgin, Finch, and Purple' % len(self.plugins)
grim@869
   460
		print ' The Plugin Pack is a collection of many simple-yet-useful plugins for Pidgin,'
grim@869
   461
		print ' Finch, and Purple.  You will find a summary of each plugin below.  For more'
grim@869
   462
		print ' about an individual plugin, please see %s' % webpage
grim@871
   463
		print ' .'
rekkanoryo@876
   464
		print ' Note: not all %d of these plugins are currently usable' % len(self.plugins)
grim@869
   465
		
grim@869
   466
		list = self.plugins.keys()
grim@869
   467
		list.sort()
grim@869
   468
		for key in list:
grim@869
   469
			plugin = self.plugins[key]
grim@869
   470
			print ' .'
grim@869
   471
			print ' %s: %s' % (plugin.name, plugin.summary)
grim@869
   472
grim@869
   473
		print ' .'
grim@889
   474
		print ' .'
grim@869
   475
		print ' Homepage: %s' % webpage
grim@869
   476
	commands['debian_description'] = debian_description
grim@869
   477
grim@814
   478
	def show_names(self, args):
grim@814
   479
		"""Displays the names of the given comma separated list of provides"""
grim@814
   480
grim@854
   481
		if len(args) == 0 or len(args[0]) == 0:
grim@854
   482
			printerr('show_names expects a comma separated list of provides')
grim@854
   483
			sys.exit(1)
grim@854
   484
grim@816
   485
		provides = args[0].split(',')
grim@816
   486
		if len(provides) == 0:
grim@816
   487
			print "none"
grim@814
   488
grim@816
   489
		line = " "
grim@816
   490
grim@814
   491
		for provide in provides:
grim@816
   492
			if not provide in self.plugins:
grim@816
   493
				continue
grim@814
   494
grim@816
   495
			name = self.plugins[provide].name
grim@814
   496
grim@816
   497
			if len(line) + len(name) + 2 > 75:
grim@816
   498
				print line.rstrip(',')
grim@816
   499
				line = ' '
grim@816
   500
			
grim@816
   501
			line += ' %s,' % name 
grim@816
   502
grim@816
   503
		if len(line) > 1:
grim@816
   504
			print line.rstrip(',')
grim@814
   505
	commands['show_names'] = show_names
grim@814
   506
grim@793
   507
	def info(self, args):
grim@802
   508
		"""Displays all information about the given plugins"""
grim@793
   509
		for p in args:
grim@793
   510
			try:
grim@793
   511
				print self.plugins[p].__str__().strip()
grim@793
   512
			except KeyError:
grim@793
   513
				print 'Failed to find a plugin that provides \'%s\'' % (p)
grim@793
   514
grim@793
   515
			print
grim@793
   516
	commands['info'] = info
grim@769
   517
grim@801
   518
	def stats(self, args):
grim@802
   519
		"""Displays stats about the plugin pack"""
grim@801
   520
		counts = {}
grim@801
   521
		
grim@801
   522
		counts['total'] = len(self.plugins)
grim@801
   523
		counts['default'] = len(self.default_plugins())
grim@801
   524
		counts['incomplete'] = len(self.incomplete_plugins())
grim@801
   525
		counts['abusive'] = len(self.abusive_plugins())
grim@801
   526
		counts['purple'] = len(self.purple_plugins())
grim@801
   527
		counts['finch'] = len(self.finch_plugins())
grim@801
   528
		counts['pidgin'] = len(self.pidgin_plugins())
grim@801
   529
grim@801
   530
		def value(val):
grim@853
   531
			return "%3d (%6.2f%%)" % (val, (float(val) / float(counts['total'])) * 100.0)
grim@801
   532
grim@801
   533
		print "Purple Plugin Pack Stats"
grim@801
   534
		print ""
grim@801
   535
		print "%d plugins in total" % (counts['total'])
grim@801
   536
		print
grim@801
   537
		print "Status:"
grim@801
   538
		print "  complete:   %s" % (value(counts['default']))
grim@801
   539
		print "  incomplete: %s" % (value(counts['incomplete']))
grim@801
   540
		print "  abusive:    %s" % (value(counts['abusive']))
grim@801
   541
		print ""
grim@801
   542
		print "Type:"
grim@801
   543
		print "  purple: %s" % (value(counts['purple']))
grim@801
   544
		print "  finch:  %s" % (value(counts['finch']))
grim@801
   545
		print "  pidgin: %s" % (value(counts['pidgin']))
grim@801
   546
	commands['stats'] = stats
grim@801
   547
grim@802
   548
def show_usage(pp, exitcode):
grim@802
   549
	print __doc__
grim@802
   550
grim@802
   551
	cmds = pp.commands.keys()
grim@802
   552
	cmds.sort()
grim@802
   553
	
grim@802
   554
	for cmd in cmds:
grim@802
   555
		print "  %-20s %s" % (cmd, pp.commands[cmd].__doc__)
grim@802
   556
grim@802
   557
	print ""
grim@802
   558
grim@802
   559
	sys.exit(exitcode)
grim@802
   560
grim@769
   561
def main():
grim@774
   562
	# create our main instance
grim@770
   563
	pp = PluginPack()
grim@769
   564
grim@792
   565
	types = []
grim@792
   566
	depends = []
grim@770
   567
grim@774
   568
	try:
grim@792
   569
		shortopts = 'adfiPp'
grim@774
   570
grim@792
   571
		opts, args = getopt.getopt(sys.argv[1:], shortopts)
grim@774
   572
	except getopt.error, msg:
grim@774
   573
		print msg
grim@802
   574
		show_usage(pp, 1)
grim@774
   575
grim@792
   576
	for o, a in opts:
grim@792
   577
		if o == '-a':
grim@792
   578
			types.append('abusive')
grim@792
   579
		elif o == '-d':
grim@792
   580
			types.append('default')
grim@792
   581
		elif o == '-i':
grim@792
   582
			types.append('incomplete')
grim@792
   583
		elif o == '-f':
grim@792
   584
			depends.append('finch')
grim@792
   585
		elif o == '-P':
grim@792
   586
			depends.append('pidgin')
grim@792
   587
		elif o == '-p':
grim@792
   588
			depends.append('purple')
grim@774
   589
grim@793
   590
	# load the plugins that have been requested, if both lists are empty, all
grim@793
   591
	# plugins are loaded
grim@793
   592
	pp.load_plugins(types, depends)
grim@792
   593
grim@793
   594
	if(len(args) == 0):
grim@802
   595
		show_usage(pp, 1)
grim@769
   596
grim@793
   597
	cmd = args[0]
grim@793
   598
	args = args[1:]
grim@793
   599
grim@793
   600
	try:
grim@793
   601
		pp.commands[cmd](pp, args)
grim@793
   602
	except KeyError:
grim@793
   603
		printerr('\'%s\' command not found' % (cmd))
grim@793
   604
grim@793
   605
if __name__ == '__main__':
grim@916
   606
	# this is a work around when we're called for a directory that isn't the
grim@916
   607
	# directory that this file is in.  This happens during distcheck, as well
grim@916
   608
	# as a few other cases that most people won't use ;)
grim@916
   609
	if os.path.dirname(__file__) != '':
grim@916
   610
		os.chdir(os.path.dirname(__file__))
grim@916
   611
grim@769
   612
	main()
grim@916
   613