org.guifications.plugins.buildsystem_rewrite: 7f6bfa4e8e25e938bb9e79e8c9ef52e10fb5126b

grim at guifications.org grim at guifications.org
Sun Mar 30 00:30:07 CDT 2008


-----------------------------------------------------------------
Revision: 7f6bfa4e8e25e938bb9e79e8c9ef52e10fb5126b
Ancestor: 7f95626570ea716e4ea1bd38653ba0b634499d2c
Author: grim at guifications.org
Date: 2008-03-30T03:43:52
Branch: org.guifications.plugins.buildsystem_rewrite

Modified files:
        plugin_pack.py

ChangeLog: 

A lot of basic behavior for plugin_pack.py, but still can't be used to determine what to build


-----------------------------------------------------------------
This revision's diffstat output:
 plugin_pack.py |  185 ++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 169 insertions(+), 16 deletions(-)
-------------- next part --------------
============================================================
--- plugin_pack.py	74987897e2ba9a4689231911fd8e049b4ffa78df
+++ plugin_pack.py	6ef745d5e27c78f83268561ac3ae104eae2b3455
@@ -1,8 +1,42 @@
 #!/usr/bin/python
 
+# plugin_pack.py - Helper script for obtaining info about the plugin pack
+# Copyright (C) 2008 Gary Kramlich <grim at reaperworld.com>
+#
+# 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 Street, Fifth Floor, Boston, MA 02111-1301, USA.
+
+"""Usage: plugin_pack.py [options]
+
+  -a, --abusive-plugins     Outputs a comma-separated list of the abusive
+                            plugins
+  -D, --dist-dirs           Outputs the list of all directories that have
+                            plugins and should be included in the distribution
+  -d, --default-plugins     Outputs a comma-separated list of the default
+                            plugins
+      --dependency-graph    Outputs a graphviz diagram showing dependencies
+  -h, --help                Shows usage information
+  -i, --incomplete-plugins  Outputs a comma-separated list of the incomplete
+                            plugins
+  -p, --plugin=<name>       Outputs all info about <name>
+"""
+
 import ConfigParser
+import getopt
 import glob
 import os.path
+import string
 import sys
 
 def printerr(msg):
@@ -31,10 +65,18 @@ class Plugin:
 			printerr('\'%s\' has an unknown type of \'%s\'!' % (self.name, self.type))
 
 	def __str__(self):
-		return self.name
+		output  = 'name: %s\n' % self.name
+		output += 'type: %s\n' % self.type
+		output += 'depends: %s\n' % string.join(self.depends, ' ')
+		output += 'provides: %s\n' % self.provides
+		output += 'directory: %s\n' % self.directory
+		output += 'summary: %s\n' % self.summary
+		output += '%s\n' % self.description
 
+		return output
+
 class PluginPack:
-	plugins = []
+	plugins = {}
 
 	def load_plugins(self):
 		for file in glob.glob('*/plugins.cfg'):
@@ -49,37 +91,148 @@ class PluginPack:
 			for plugin in parser.sections():
 				p = Plugin(os.path.dirname(file), plugin, parser)
 
-				self.plugins.append(p)
+				self.plugins[p.name] = p
 
-	def list(self, type):
+	def list_type(self, type):
 		list = []
 
-		for plugin in self.plugins:
+		for name in self.plugins.keys():
+			plugin = self.plugins[name]
 			if plugin.type == type:
 				list.append(plugin)
 
+		list.sort()
+
 		return list
 
-	def dump_list(self, list):
-		for i in list:
-			print '\t%s' % i
+	def print_names(self, list):
+		names = []
+		for plugin in list:
+			names.append(plugin.name)
 
-	def debug(self):
-		print 'Default:'
-		self.dump_list(self.list('default'))
+		print string.join(names, ',')
 
-		print 'Abusive:'
-		self.dump_list(self.list('abusive'))
+	def dist_dirs(self):
+		dirs = {}
+		for name in self.plugins.keys():
+			dirs[name] = 1
 
-		print 'Incomplete:'
-		self.dump_list(self.list('incomplete'))
+		dirs = dirs.keys()
+		dirs.sort()
+		for dir in dirs:
+			print dir
 
+	def default_plugins(self):
+		return self.list_type('default')
+
+	def abusive_plugins(self):
+		return self.list_type('abusive')
+
+	def incomplete_plugins(self):
+		return self.list_type('incomplete')
+
+	def dependency_graph(self):
+		def node_label(plugin):
+			node = plugin.provides.replace('-', '_')
+			label = plugin.name
+
+			return node, label
+
+		def print_plugins(list):
+			for plugin in list:
+				node, label = node_label(plugin)
+
+				print '\t%s[label="%s"];' % (node, label)
+
+		print 'digraph {'
+		print '\tlabel="Dependency Graph";'
+		print '\tlabelloc="t";'
+		print '\tsplines=TRUE;'
+		print '\toverlap=scale;'
+		print
+		print '\tnode[fontname="sans", style="filled", shape="box"];'
+		print
+
+		# run through the default plugins
+		print '\t/* default plugins */'
+		print '\tnode[fillcolor="palegreen"];'
+		print_plugins(self.default_plugins())
+		print
+
+		# run through the incomplete plugins
+		print '\t/* incomplete plugins */'
+		print '\tnode[fillcolor="lightyellow1"];'
+		print_plugins(self.incomplete_plugins())
+		print
+
+		# run through the abusive plugins
+		print '\t/* abusive plugins */'
+		print '\tnode[fillcolor="lightpink"];'
+		print_plugins(self.abusive_plugins())
+		print
+
+		# run through again, this time showing the relations
+		print '\t/* dependencies'
+		print '\t * exteranl ones that don\'t have nodes get colored to the following'
+		print '\t */'
+		print '\tnode[fillcolor="powderblue"];'
+
+		for name in self.plugins.keys():
+			plugin = self.plugins[name]
+
+			node, label = node_label(plugin)
+
+			for dep in plugin.depends:
+				dep = dep.replace('-', '_')
+				print '\t%s -> %s;' % (node, dep)
+
+		print '}'
+
 def main():
+	# create our main instance
 	pp = PluginPack()
 
+	# load all our plugin data
 	pp.load_plugins()
 
-	pp.debug()
+	try:
+		shortopts = 'aDdhip:'
+		longopts = [
+			'abusive-plugins',
+			'dependency-graph',
+			'default-plugins',
+			'dist-dirs',
+			'help',
+			'incomplete-plugins',
+			'plugin',
+		]
 
+		opts, args = getopt.getopt(sys.argv[1:], shortopts, longopts)
+	except getopt.error, msg:
+		print msg
+		print __doc__
+		sys.exit(1)
+
+	if not opts:
+		print __doc__
+		sys.exit(1)
+
+	for o, a in opts:
+		if o in ('-a', '--abusive-plugins'):
+			pp.print_names(pp.abusive_plugins())
+		elif o == '--dependency-graph':
+			pp.dependency_graph()
+		elif o in ('-D', '--dist-dirs'):
+			pp.dist_dirs()
+		elif o in ('-d', '--default-plugins'):
+			pp.print_names(pp.default_plugins())
+		elif o in ('-h', '--help'):
+			print __doc__
+			sys.exit(0)
+		elif o in ('-i', '--incomplete-plugins'):
+			pp.print_names(pp.incomplete_plugins())
+		elif o in ('-p', '--plugin'):
+			print pp.plugins[a]
+
 if __name__ == "__main__":
 	main()


More information about the Plugins-commits mailing list