From 4ec926486e34bb2a0769e95ee33924b8b6bff6ab Mon Sep 17 00:00:00 2001 From: allfro Date: Thu, 25 Oct 2012 22:10:25 -0400 Subject: [PATCH] Finally fixed the path issue for linux distros --- src/canari/commands/common.py | 8 ++++++++ src/canari/commands/install_package.py | 5 ++--- src/canari/commands/run_transform.py | 5 ++--- src/canari/commands/shell.py | 1 - src/canari/maltego/message.py | 15 ++++++++++----- 5 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/canari/commands/common.py b/src/canari/commands/common.py index 13568e8..2fcb2ad 100644 --- a/src/canari/commands/common.py +++ b/src/canari/commands/common.py @@ -4,6 +4,8 @@ from canari.config import CanariConfigParser from os import path, listdir, sep, environ, mkdir, pathsep, getcwd from pkg_resources import resource_filename +from distutils.dist import Distribution +from distutils.command.install import install from sys import path as pypath, platform from datetime import datetime from string import Template @@ -20,6 +22,12 @@ __email__ = 'ndouba@gmail.com' __status__ = 'Development' +def get_bin_dir(): + d = install(Distribution()) + d.finalize_options() + return d.install_scripts + + def get_commands(module='canari.commands'): sc = __import__(module, globals(), locals(), fromlist=['__all__']) commands = {} diff --git a/src/canari/commands/install_package.py b/src/canari/commands/install_package.py index c02a35d..749d74e 100644 --- a/src/canari/commands/install_package.py +++ b/src/canari/commands/install_package.py @@ -4,11 +4,10 @@ from ..maltego.configuration import (MaltegoTransform, CmdCwdTransformProperty, CmdLineTransformProperty, CmdParmTransformProperty, InputConstraint, TransformSet, TransformSettings, CmdCwdTransformPropertySetting, CmdDbgTransformPropertySetting, CmdLineTransformPropertySetting, CmdParmTransformPropertySetting) -from common import detect_settings_dir, cmd_name, fix_pypath +from common import detect_settings_dir, cmd_name, fix_pypath, get_bin_dir from ..maltego.message import ElementTree from os import sep, path, mkdir, chdir, getcwd, name -from distutils.sysconfig import get_config_var from pkg_resources import resource_filename from argparse import ArgumentParser from string import Template @@ -125,7 +124,7 @@ def install_transform(module, name, author, spec, prefix, working_dir): ElementTree(transform).write(sep.join([installdir, '%s.transform' % n])) transformsettings = TransformSettings(properties=[ - CmdLineTransformPropertySetting(path.join(get_config_var('BINDIR'), 'dispatcher')), + CmdLineTransformPropertySetting(path.join(get_bin_dir(), 'dispatcher')), CmdParmTransformPropertySetting(name), CmdCwdTransformPropertySetting(working_dir), CmdDbgTransformPropertySetting(spec.debug) diff --git a/src/canari/commands/run_transform.py b/src/canari/commands/run_transform.py index 06c768c..4ee420e 100644 --- a/src/canari/commands/run_transform.py +++ b/src/canari/commands/run_transform.py @@ -1,10 +1,9 @@ #!/usr/bin/env python from ..maltego.message import MaltegoException, MaltegoTransformResponseMessage +from common import cmd_name, import_transform, fix_binpath, get_bin_dir from ..maltego.utils import onterminate, parseargs, croak, message -from common import cmd_name, import_transform, fix_binpath -from distutils.sysconfig import get_config_var from os import execvp, geteuid, name, path from argparse import ArgumentParser from traceback import format_exc @@ -66,7 +65,7 @@ def run(args): [transform, params, value, fields] = parseargs(['canari %s' % cmd_name(__name__)] + args) m = None - pysudo = path.join(get_config_var('BINDIR'), 'pysudo') + pysudo = path.join(get_bin_dir(), 'pysudo') fix_binpath(config['default/path']) try: diff --git a/src/canari/commands/shell.py b/src/canari/commands/shell.py index 355f259..cc10045 100644 --- a/src/canari/commands/shell.py +++ b/src/canari/commands/shell.py @@ -4,7 +4,6 @@ from common import console_message, cmd_name, highlight, fix_pypath, fix_binpath from ..maltego.message import MaltegoTransformResponseMessage from ..config import config -from distutils.sysconfig import get_config_var from os import path, name, geteuid, execvp from code import InteractiveConsole from argparse import ArgumentParser diff --git a/src/canari/maltego/message.py b/src/canari/maltego/message.py index 4d52185..20c8af7 100644 --- a/src/canari/maltego/message.py +++ b/src/canari/maltego/message.py @@ -284,14 +284,19 @@ class Entity(MaltegoElement): def __init__(self, value, **kwargs): super(Entity, self).__init__("Entity") - type = kwargs.get('type', None) + type = kwargs.pop('type', None) if type is None: self.type = '%s.%s' % (self.namespace, self.__class__.__name__ if self.name is None else self.name) + else: + self.type = type self.value = value - self.weight = kwargs.get('weight', self.weight) - self.iconurl = kwargs.get('iconurl', self.iconurl) - self.appendelements(kwargs.get('fields')) - self.appendelements(kwargs.get('labels')) + self.weight = kwargs.pop('weight', self.weight) + self.iconurl = kwargs.pop('iconurl', self.iconurl) + self.appendelements(kwargs.pop('fields', None)) + self.appendelements(kwargs.pop('labels', None)) + for p in kwargs: + if hasattr(self, p): + setattr(self, p, kwargs[p]) def appendelement(self, other): if isinstance(other, Field): -- 2.45.1