Exemplo n.º 1
0
def run(args):

    opts = parse_args(args)

    if not os.path.exists(os.path.join(opts.plume_dir, 'plume.py')):
        print('Plume does not appear to be installed in %s.' % opts.plume_dir)
        ans = parse_bool("Would you like to install it [Y/n]: ")
        if not ans:
            print 'Installation cancelled. Quitting...'
            exit(-1)
        os.system('canari install-plume --install-dir %s' % opts.plume_dir)
        opts.plume_dir = os.path.join(opts.plume_dir, 'plume')


    if opts.package.endswith('.transforms'):
        opts.package = opts.package.replace('.transforms', '')


    print ('Looking for transforms in %s.transforms' % opts.package)
    transform_package = None
    try:
        transform_package = import_package('%s.transforms' % opts.package)
    except ImportError, e:
        print ("Does not appear to be a valid canari package. "
               "Couldn't import the '%s.transforms' package in '%s'. Error message: %s" %
               (opts.package, opts.package, e))
        exit(-1)
Exemplo n.º 2
0
def run(args):

    if os.name == 'posix' and not os.geteuid():
        login = os.getlogin()

        if login != 'root':
            print 'Why are you using root to run this command? You should be using %s! Bringing you down...' % login
            import pwd
            user = pwd.getpwnam(login)
            os.setgid(user.pw_gid)
            os.setuid(user.pw_uid)

    opts = parse_args(args)

    makedirs(opts.working_dir)
    fix_pypath()
    fix_etree()

    if opts.package.endswith('.transforms'):
        opts.package = opts.package.replace('.transforms', '')

    try:
        installconf(opts, args)
    except ImportError:
        pass

    print ('Looking for transforms in %s.transforms' % opts.package)
    m = None
    try:
        m = import_package('%s.transforms' % opts.package)
    except ImportError, e:
        print ("Does not appear to be a valid canari package. Couldn't import the '%s.transforms' package in '%s'. Error message: %s" % (opts.package, opts.package, e))
        exit(-1)
Exemplo n.º 3
0
def run(args):

    opts = parse_args(args)

    if not os.path.exists(os.path.join(opts.plume_dir, 'plume.py')):
        print('Plume does not appear to be installed in %s.' % opts.plume_dir)
        ans = parse_bool("Would you like to install it [Y/n]: ")
        if not ans:
            print 'Installation cancelled. Quitting...'
            exit(-1)
        os.system('canari install-plume --install-dir %s' % opts.plume_dir)
        opts.plume_dir = os.path.join(opts.plume_dir, 'plume')

    if opts.package.endswith('.transforms'):
        opts.package = opts.package.replace('.transforms', '')

    print('Looking for transforms in %s.transforms' % opts.package)
    transform_package = None
    try:
        transform_package = import_package('%s.transforms' % opts.package)
    except ImportError, e:
        print(
            "Does not appear to be a valid canari package. "
            "Couldn't import the '%s.transforms' package in '%s'. Error message: %s"
            % (opts.package, opts.package, e))
        exit(-1)
Exemplo n.º 4
0
 def __init__(self, package):
     package = import_package(package)
     transforms = dict(dir=dir)
     for name, mod in package.__dict__.iteritems():
         if getattr(mod, 'dotransform', ''):
             transforms[name] = ShellCommand(mod)
     InteractiveConsole.__init__(self, locals=transforms)
     self.init_history(os.path.expanduser('~/.mtgsh_history'))
Exemplo n.º 5
0
 def __init__(self, package):
     package = import_package(package)
     transforms = dict(dir=dir)
     for name, mod in package.__dict__.iteritems():
         if getattr(mod, 'dotransform', ''):
             transforms[name] = ShellCommand(mod)
     InteractiveConsole.__init__(self, locals=transforms)
     self.init_history(os.path.expanduser('~/.mtgsh_history'))
Exemplo n.º 6
0
def run(args):
    opts = parse_args(args)

    fix_pypath()

    if opts.port == -1:
        opts.port = 443 if not opts.disable_ssl else 80

    if os.name == 'posix' and os.geteuid() and (opts.port <= 1024
                                                or opts.enable_privileged):
        print('You must run this server as root to continue...')
        os.execvp('sudo', ['sudo'] + sys.argv)

    fix_binpath(config['default/path'])

    transforms = {}

    print('Loading transform packages...')

    try:
        for pkg_name in opts.packages:

            if not pkg_name.endswith('.transforms'):
                pkg_name = ('%s.transforms' % pkg_name)

            print('Loading transform package %s' % pkg_name)

            transform_package = import_package(pkg_name)

            for transform_name in transform_package.__all__:

                transform_name = ('%s.%s' % (pkg_name, transform_name))
                transform_module = import_transform(transform_name)

                if not hasattr(transform_module, 'dotransform'):
                    continue

                if os.name == 'posix' and hasattr(transform_module.dotransform, 'privileged') and \
                        (os.geteuid() or not opts.enable_privileged):
                    continue

                if hasattr(transform_module.dotransform,
                           'remote') and transform_module.dotransform.remote:
                    print('Loading %s at /%s...' %
                          (transform_name, transform_name))
                    inputs = []
                    if hasattr(transform_module.dotransform, 'inputs'):
                        for category, entity_type in transform_module.dotransform.inputs:
                            inputs.append(entity_type.type)
                            inputs.append(entity_type._v2type_)
                    transforms['/%s' %
                               transform_name] = (transform_module.dotransform,
                                                  inputs)

    except Exception, e:
        print(str(e))
        print('Failed to load transforms... exiting')
        exit(-1)
Exemplo n.º 7
0
def run(args):

    opts = parser.parse_args(args)

    fix_pypath()

    if opts.port == -1:
        opts.port = 443 if not opts.disable_ssl else 80

    if name == "posix" and geteuid() and (opts.port <= 1024 or opts.enable_privileged):
        print("You must run this server as root to continue...")
        execvp("sudo", ["sudo"] + list(argv))

    fix_binpath(config["default/path"])

    transforms = {}

    print("Loading transform packages...")

    try:
        for p in opts.packages:

            if not p.endswith(".transforms"):
                p = "%s.transforms" % p

            print("Loading transform package %s" % p)

            m = import_package(p)

            for t in m.__all__:

                t = "%s.%s" % (p, t)
                m2 = import_transform(t)

                if not hasattr(m2, "dotransform"):
                    continue

                if (
                    name == "posix"
                    and hasattr(m2.dotransform, "privileged")
                    and (geteuid() or not opts.enable_privileged)
                ):
                    continue

                if hasattr(m2.dotransform, "remote") and m2.dotransform.remote:
                    print("Loading %s at /%s..." % (t, t))
                    if hasattr(m2.dotransform, "inputs"):
                        inputs = [e[1]("").type for e in m2.dotransform.inputs]
                        inputs = inputs + [i.split(".")[-1] for i in inputs]
                        transforms["/%s" % t] = (m2.dotransform, inputs)
                    else:
                        transforms["/%s" % t] = (m2.dotransform, [])

    except Exception, e:
        print(str(e))
        print("Failed to load transforms... exiting")
        exit(-1)
Exemplo n.º 8
0
def run(args):

    opts = parse_args(args)

    fix_pypath()

    if opts.port == -1:
        opts.port = 443 if not opts.disable_ssl else 80

    if os.name == 'posix' and os.geteuid() and (opts.port <= 1024 or opts.enable_privileged):
        print ('You must run this server as root to continue...')
        os.execvp('sudo', ['sudo'] + sys.argv)

    fix_binpath(config['default/path'])


    transforms = {}

    print ('Loading transform packages...')

    try:
        for p in opts.packages:

            if not p.endswith('.transforms'):
                p = ('%s.transforms' % p)

            print ('Loading transform package %s' % p)

            m = import_package(p)

            for t in m.__all__:

                t = ('%s.%s' % (p, t))
                m2 = import_transform(t)

                if not hasattr(m2, 'dotransform'):
                    continue

                if os.name == 'posix' and hasattr(m2.dotransform, 'privileged') and (os.geteuid() or not opts.enable_privileged):
                    continue

                if hasattr(m2.dotransform, 'remote') and m2.dotransform.remote:
                    print ('Loading %s at /%s...' % (t, t))
                    if hasattr(m2.dotransform, 'inputs'):
                        inputs = [e[1]('').type for e in m2.dotransform.inputs]
                        inputs = inputs + [i.split('.')[-1] for i in inputs]
                        transforms['/%s' % t] = (m2.dotransform, inputs)
                    else:
                        transforms['/%s' % t] = (m2.dotransform, [])

    except Exception, e:
        print (str(e))
        print ('Failed to load transforms... exiting')
        exit(-1)
Exemplo n.º 9
0
def run(args):
    opts = parse_args(args)

    fix_pypath()

    if opts.port == -1:
        opts.port = 443 if not opts.disable_ssl else 80

    if os.name == 'posix' and os.geteuid() and (opts.port <= 1024 or opts.enable_privileged):
        print ('You must run this server as root to continue...')
        os.execvp('sudo', ['sudo'] + sys.argv)

    fix_binpath(config['default/path'])

    transforms = {}

    print ('Loading transform packages...')

    try:
        for pkg_name in opts.packages:

            if not pkg_name.endswith('.transforms'):
                pkg_name = ('%s.transforms' % pkg_name)

            print ('Loading transform package %s' % pkg_name)

            transform_package = import_package(pkg_name)

            for transform_name in transform_package.__all__:

                transform_name = ('%s.%s' % (pkg_name, transform_name))
                transform_module = import_transform(transform_name)

                if not hasattr(transform_module, 'dotransform'):
                    continue

                if os.name == 'posix' and hasattr(transform_module.dotransform, 'privileged') and \
                        (os.geteuid() or not opts.enable_privileged):
                    continue

                if hasattr(transform_module.dotransform, 'remote') and transform_module.dotransform.remote:
                    print ('Loading %s at /%s...' % (transform_name, transform_name))
                    inputs = []
                    if hasattr(transform_module.dotransform, 'inputs'):
                        for category, entity_type in transform_module.dotransform.inputs:
                            inputs.append(entity_type.type)
                            inputs.append(entity_type._v2type_)
                    transforms['/%s' % transform_name] = (transform_module.dotransform, inputs)

    except Exception, e:
        print (str(e))
        print ('Failed to load transforms... exiting')
        exit(-1)
Exemplo n.º 10
0
def run(args):

    opts = parse_args(args)

    if not os.path.exists(os.path.join(opts.plume_dir, 'plume.py')):
        print('Plume does not appear to be installed in %s.' % opts.plume_dir)
        exit(-1)

    if opts.package.endswith('.transforms'):
        opts.package = opts.package.replace('.transforms', '')

    print('Looking for transforms in %s.transforms' % opts.package)
    transform_package = None
    try:
        transform_package = import_package('%s.transforms' % opts.package)
    except ImportError, e:
        print(
            "Does not appear to be a valid canari package. "
            "Couldn't import the '%s.transforms' package in '%s'. Error message: %s"
            % (opts.package, opts.package, e))
        exit(-1)
Exemplo n.º 11
0
def run(args):

    opts = parse_args(args)

    if not os.path.exists(os.path.join(opts.plume_dir, 'plume.py')):
        print('Plume does not appear to be installed in %s.' % opts.plume_dir)
        exit(-1)

    if opts.package.endswith('.transforms'):
        opts.package = opts.package.replace('.transforms', '')


    print ('Looking for transforms in %s.transforms' % opts.package)
    transform_package = None
    try:
        transform_package = import_package('%s.transforms' % opts.package)
    except ImportError, e:
        print ("Does not appear to be a valid canari package. "
               "Couldn't import the '%s.transforms' package in '%s'. Error message: %s" %
               (opts.package, opts.package, e))
        exit(-1)
Exemplo n.º 12
0
def run(args):

    opts = parse_args(args)

    fix_pypath()
    fix_etree()

    if opts.package.endswith('.transforms'):
        opts.package = opts.package.replace('.transforms', '')

    try:
        installconf(opts, args)
    except ImportError:
        pass

    print ('Looking for transforms in %s.transforms' % opts.package)
    m = None
    try:
        m = import_package('%s.transforms' % opts.package)
    except ImportError, e:
        print ("Does not appear to be a valid canari package. Couldn't import the '%s.transforms' package in '%s'. Error message: %s" % (opts.package, opts.package, e))
        exit(-1)
Exemplo n.º 13
0
def run(args):
    if os.name == 'posix' and not os.geteuid():
        login = os.getlogin()

        if login != 'root':
            print 'Why are you using root to run this command? You should be using %s! Bringing you down...' % login
            import pwd

            user = pwd.getpwnam(login)
            os.setgid(user.pw_gid)
            os.setuid(user.pw_uid)

    opts = parse_args(args)

    makedirs(opts.working_dir)
    fix_pypath()
    fix_etree()

    if opts.package.endswith('.transforms'):
        opts.package = opts.package.replace('.transforms', '')

    try:
        print('Writing canari.config to %s...' % opts.working_dir)
        installconf(opts, args)
    except ImportError:
        pass

    print ('Looking for transforms in %s.transforms' % opts.package)
    m = None
    try:
        m = import_package('%s.transforms' % opts.package)
    except ImportError, e:
        print (
            "Does not appear to be a valid canari package. "
            "Couldn't import the '%s.transforms' package in '%s'. Error message: %s" % (
                opts.package, opts.package, e))
        exit(-1)
Exemplo n.º 14
0
def run(args):

    opts = parse_args(args)

    if opts.package.endswith('.transforms'):
        opts.package = opts.package.replace('.transforms', '')

    fix_pypath()

    fix_etree()

    m = import_package('%s.transforms' % opts.package)

    for t in m.__all__:
        transform = '%s.transforms.%s' % (opts.package, t)
        m2 = import_transform(transform)
        if hasattr(m2, 'dotransform') and hasattr(m2.dotransform, 'label'):
            uninstall_transform(
                m2.__name__,
                m2.dotransform,
                opts.settings_dir
            )

    uninstallmachines(opts.package, opts.settings_dir)