Example #1
0
def show(opts, args):
    """Show script details"""
    mojo = Mojo(**opts)
    script = mojo.get_script(args.script)

    if mojo.unauthorized:
        print("Authentication failed")
    else:
        print_script(script)
Example #2
0
def reload_jojo(opts):
    """Reload the Jojo"""
    mojo = Mojo(**opts)
    result = mojo.reload()

    if result is True:
        print("Reload successful!")
    elif result is False:
        print("Authentication failed")
    elif type(result) == int:
        print(
            "The Jojo responded with an unexpected status code: {}".
            format(result)
        )
Example #3
0
    def create_datasource(self, datapath):
        '''
    '''

        # detect data source type
        last_folder = datapath.rstrip(os.sep).split(os.sep)[-1]
        last_folder = last_folder.lower()
        if last_folder == 'mojo':
            ds = Mojo(self, datapath)
        else:
            ds = RegularImageStack(self, datapath)

        # call index
        ds.index()

        self._datasources[datapath] = ds
Example #4
0
  def create_datasource(self, datapath):
    '''
    '''

    # detect data source type
    last_folder = datapath.rstrip(os.sep).split(os.sep)[-1]
    last_folder = last_folder.lower()
    if last_folder == 'mojo':
      ds = Mojo(self, datapath)
    else:
      ds = RegularImageStack(self, datapath)

    # call index
    ds.index()

    self._datasources[datapath] = ds
Example #5
0
def list_scripts(opts):
    """List available scripts"""
    mojo = Mojo(**opts)
    if mojo.unauthorized:
        print("Authentication failed")
    else:
        if opts["boolean"] is not None and opts["tags"] is not None:
            if opts["boolean"] == "and":
                param = "tags"
            elif opts["boolean"] == "or":
                param = "any_tags"
            elif opts["boolean"] == "not":
                param = "not_tags"
            scripts = mojo.get_scripts(param, opts["tags"])
            for script in sorted(scripts):
                print_script(mojo.get_script(script))
                print("")
        else:
            for script in sorted(mojo.scripts):
                print(script)
Example #6
0
def run(opts, args):
    """Run a script"""
    mojo = Mojo(**opts)

    # Parse CLI-given parameters
    params = {}
    for param in args.params:
        broken = param.split("=")
        params[broken[0]] = broken[1]

    resp = mojo.run(args.script, params)

    if mojo.auth and mojo.unauthorized:
        print("Authentication failed")
    else:
        print("Status Code: {}".format(resp.status_code))
        print("Headers:")
        for header in resp.headers:
            print("  {}: {}".format(header, resp.headers[header]))
        j = resp.json()
        print("Script return code: {}".format(j['retcode']))
        if "stderr" in j:
            print("Stderr:")
            if type(j["stderr"]) is unicode:
                print(j["stderr"])
            else:
                for line in j["stderr"]:
                    print("  {}".format(line))
        if "stdout" in j:
            print("Stdout:")
            if type(j["stdout"]) is unicode:
                print(j["stdout"])
            else:
                for line in j["stdout"]:
                    print("  {}".format(line))
        if "return_values" in j and len(j["return_values"]) > 0:
            print("Return Values:")
            for key in sorted(j["return_values"]):
                print("  {}: {}".format(key, j["return_values"][key]))
Example #7
0
    def create_datasource(self, datapath):
        '''
        '''

        for allowed_path in settings.ALLOWED_PATHS:
            if datapath.startswith(allowed_path):
                break
        else:
            raise urllib2.HTTPError(
                None, 403, datapath + " is not an allowed datapath. " +
                "Contact the butterfly admin to configure a new datapath",
                [], None)
        for datasource in settings.DATASOURCES:
            try:
                if datasource == 'mojo':
                    from mojo import Mojo
                    ds = Mojo(self, datapath)
                    break
                elif datasource == 'regularimagestack':
                    from regularimagestack import RegularImageStack
                    ds = RegularImageStack(self, datapath)
                    break
                elif datasource in ("tilespecs"):
                    from tilespecs import Tilespecs
                    ds = Tilespecs(self, datapath)
                    break
                elif datasource in ("comprimato", "multibeam"):
                    from multibeam import MultiBeam
                    ds = MultiBeam(self, datapath)
                    break
            except:
                rh_logger.logger.report_event(
                    "Can't load %s with %s" % (datapath, datasource),
                    log_level=logging.DEBUG)
                continue
        else:
            rh_logger.logger.report_event(
                "Failed to find datasource for %s" % datapath,
                log_level=logging.WARNING)
            raise urllib2.HTTPError(
                None, 404, "Can't find a loader for datapath=%s" % datapath,
                [], None)
        # call index
        ds.index()

        self._datasources[datapath] = ds