Subversion Repositories MeX

Compare Revisions

Ignore whitespace Rev HEAD → Rev 1

/trunk/mex/data/plugins/coremetadataplugin.yapsy-plugin
File deleted
/trunk/mex/data/plugins/simpleplugin.yapsy-plugin
File deleted
/trunk/mex/data/plugins/CoreMetadataPlugin.py
File deleted
/trunk/mex/data/plugins/SimplePlugin.py
File deleted
\ No newline at end of file
/trunk/mex/core/mod_rdf.py
File deleted
/trunk/mex/services/srv_utils.py
File deleted
\ No newline at end of file
/trunk/mex/core/mod_env.py
9,8 → 9,7
 
import sys
import os
from os.path import abspath
from os.path import sep as SEP
from os.path import abspath, sep as SEP
 
ROOT = abspath(sys.modules[__name__].__file__ + "/../../")
USER_DIR = os.path.expanduser('~')
/trunk/mex/services/srv_application.py
7,112 → 7,21
# Description: Application service
"""
 
import os
import uuid
 
from mex.core.mod_srv import Service
from mex.core.mod_env import GPATH, LPATH, APP, SEP
from mex.core.mod_rdf import BASE, URIRef, Literal
from pprint import pprint
from mex.core.mod_env import LPATH, APP
 
 
class MexAppSrv(Service):
def initialize(self):
"""
Missing method docstring (missing-docstring)
"""
self.get_services()
pass
 
 
def get_services(self):
"""
Missing method docstring (missing-docstring)
"""
self.srvutl = self.get_service('Utils')
self.srvplg = self.get_service('Plugins')
 
 
 
def run(self, params):
self.log.debug("TARGET_PATH: %s" % params.TARGET_PATH)
if params.TARGET_PATH is None:
TARGET_PATH = os.path.join(LPATH['EXPORT'], 'repository.dot')
else:
TARGET_PATH = os.path.join(params.TARGET_PATH, 'repository.dot')
 
repodict = {}
repoobjs = {}
samerank = ""
 
def run(self):
self.log.debug("Starting Metadata eXplorer")
self.srv_plugins = self.get_service('Plugins')
self.plugins = self.srv_plugins.get_plugins_by_category('Metadata')
self.log.debug("Found %d plugins for 'Metadata' category" % len(self.plugins))
fileset = self.srvutl.get_files_from_dir(params.SOURCE_PATH)
self.log.debug("Got %d files" % len(fileset))
self.plugins = self.get_service('Plugins')
 
for path in fileset:
tuples = []
s = URIRef("%s%s" % (BASE, path))
rid = uuid.uuid4()
repodict[path] = {}
repodict[path]['uuid'] = str(rid)
samerank += "\"%s\"; " % rid
for plugin in self.plugins:
try:
metadata = plugin.plugin_object.get_metadata(self.app, path)
except:
metadata = []
tuples.extend(metadata)
for p, o in tuples:
predicate = self.srvutl.pname(p)
if isinstance(o, URIRef) or isinstance(o, Literal):
o = str(self.srvutl.pname(o))
repodict[path][predicate] = o
try:
objid = repoobjs[o]
except:
repoobjs[o] = str(uuid.uuid4())
 
# Graph
output = "graph repository{\n"
output += " rankdir = LR;\n"
 
# Nodes
nodes = []
relations = []
for path in fileset:
try:
node = " \"%s\" [shape=cylinder label=\"%s\" URL=\"file://%s\"]\n" % (repodict[path]['uuid'], repodict[path]['fileName'], path)
output += node
nodes.append(node)
for prop in repodict[path]:
if prop not in ['uuid', 'fileName', 'fileUrl']:
pid = repoobjs[repodict[path][prop]]
node = " \"%s\" [label=\"%s\"]\n" % (pid, repodict[path][prop])
nodes.append(node)
output += node
relation = " \"%s\" -- \"%s\" [label=\"%s\"]\n" % (repodict[path]['uuid'], repoobjs[repodict[path][prop]], prop)
relations.append(relation)
except:
pass
 
# Same Rank
output += " {rank = same; %s}\n" % samerank
 
# Relations
for relation in relations:
output += relation
 
# End graph
output += "}"
 
with open(TARGET_PATH, 'w') as dot:
dot.write(output)
self.log.debug("Generated dot file in: %s" % TARGET_PATH)
 
cmd = "circo -Tsvg %s > repository.html" % TARGET_PATH
self.log.debug("Execute command: %s" % cmd)
 
def end(self):
self.log.debug("Stopping Metadata eXplorer")
 
/trunk/mex/services/srv_plugins.py
9,44 → 9,15
 
 
from mex.core.mod_srv import Service
from mex.core.mod_env import GPATH, LPATH, APP
from mex.core.mod_env import LPATH, APP
from yapsy.PluginManager import PluginManager
from yapsy.IPlugin import IPlugin
 
class IMetadataPlugin(IPlugin):
pass
 
class MexPluginManager(Service):
def initialize(self):
self.log.debug("Loading Plugin Manager")
self.manager = PluginManager()
manager = PluginManager()
manager.setPluginPlaces([LPATH['PLUGINS']])
manager.collectPlugins()
 
# set plugins paths
self.manager.setPluginPlaces([GPATH['PLUGINS'], LPATH['PLUGINS']])
 
# allow only plugins belonging to the Metadata category
self.manager.setCategoriesFilter({
"Metadata" : IMetadataPlugin,
"Default" : IPlugin,
})
 
# Get all
self.manager.collectPlugins()
self.log.debug("Number of plugins found: %d" % len(self.manager.getAllPlugins()))
# ~ for plugin in self.manager.getAllPlugins():
# ~ self.log.debug("\tCategory: %s - Name: %s" % (plugin.category, plugin.name))
# ~ plugin.plugin_object.print_name()
 
 
def get_manager(self):
return self.manager
 
def get_plugins(self):
return self.manager.getAllPlugins()
 
def get_plugins_by_category(self, category):
try:
return self.manager.getPluginsOfCategory(category)
except:
self.log.warning("Plugin category '%s' doesn't exist" % category)
return []
for plugin in manager.getAllPlugins():
plugin.plugin_object.print_name()
/trunk/mex/mex.py
11,38 → 11,23
import sys
import signal
import shutil
import argparse
 
from mex.core.mod_env import APP, LPATH, GPATH, FILE
from mex.core.mod_log import get_logger
from mex.services.srv_plugins import MexPluginManager
from mex.services.srv_application import MexAppSrv
from mex.services.srv_utils import MexUtils
 
 
#DOC: http://stackoverflow.com/questions/16410852/keyboard-interrupt-with-with-python-gtk
signal.signal(signal.SIGINT, signal.SIG_DFL)
 
 
class readable_dir(argparse.Action):
# https://stackoverflow.com/questions/11415570/directory-path-types-with-argparse
def __call__(self, parser, namespace, values, option_string=None):
prospective_dir=values
if not os.path.isdir(prospective_dir):
exit("ERROR: '{0}' is not a valid path".format(prospective_dir))
if os.access(prospective_dir, os.R_OK):
setattr(namespace,self.dest,prospective_dir)
else:
exit("ERROR: '{0}' is not a readable dir".format(prospective_dir))
 
 
class MeX(object):
"""
MeX Application class
"""
def __init__(self, params):
def __init__(self):
"""
"""
self.params = params
self.setup_environment()
self.setup_logging()
self.setup_services()
84,10 → 69,8
self.services = {}
try:
services = {
'Utils' : MexUtils(),
'Application' : MexAppSrv(),
'Plugins' : MexPluginManager(),
 
}
 
for name in services:
151,23 → 134,14
Start MeX
"""
app = self.get_service('Application')
app.run(self.params)
app.run()
 
 
def parse_args():
parser = argparse.ArgumentParser(description="Metadata Explorer")
parser.add_argument('-sp', '--source-path', dest="SOURCE_PATH", action=readable_dir, help="Souce path of the repository to be analyzed", required=True)
parser.add_argument('-tp', '--target-path', dest="TARGET_PATH", action=readable_dir, help="Target path for output files")
parser.add_argument('-v', '--version', action='version', version='%s %s' % ("MeX", '0.1'))
return parser.parse_args()
 
 
def main():
"""
Entry point
"""
params = parse_args()
mex = MeX(params)
mex = MeX()
mex.run()
mex.stop()
 
/trunk/Changelog
File deleted
/trunk/setup.py
33,7 → 33,7
try:
data_files_mex = [
('mex/data/share', []),
('mex/data/share/docs',
("mex/data/share/docs",
[
'AUTHORS',
'LICENSE',
42,13 → 42,6
'CREDITS',
'Changelog'
]),
('mex/data/plugins',
[
'mex/data/plugins/simpleplugin.yapsy-plugin',
'mex/data/plugins/SimplePlugin.py',
'mex/data/plugins/coremetadataplugin.yapsy-plugin',
'mex/data/plugins/CoreMetadataPlugin.py',
]),
]
return data_files_mex
except:
73,10 → 66,7
# distutils does not support install_requires, but pip needs it to be
# able to automatically install dependencies
install_requires=[
'uuid',
'rdflib',
'yapsy',
'python-dateutil'
'yapsy',
],
include_package_data=True,
data_files=data_files,