예제 #1
0
파일: sdusrcon.py 프로젝트: ncarenton/synda
    def do_search(self,arg):
        self.parameter=arg.split()
        self.complete_parameter()

        localsearch=sdsessionparam.get_value('localsearch')
        dry_run=sdsessionparam.get_value('dry_run')
        
        type_=sdsessionparam.get_value('type')

        kw={'parameter':self.parameter,'dry_run':dry_run}

        if localsearch:
            if type_=='Dataset':
                datasets=sdldataset.get_datasets(**kw)
                if not dry_run:
                    if len(datasets)==0:
                        print "Dataset not found"
                    else:
                        sdldataset.print_list(datasets)
            elif type_=='File':
                files=sdlfile.get_files(**kw)
                if not dry_run:
                    sdlfile.print_(files)
        else:
            if type_=='Dataset':
                datasets=sdrdataset.get_datasets(**kw)
                if not dry_run:
                    if len(datasets)==0:
                        print "Dataset not found"
                    else:
                        sdrdataset.print_list(datasets)
            elif type_=='File':
                files=sdrfile.get_files(**kw)
                if not dry_run:
                    sdrfile.print_list(files)
예제 #2
0
    def do_search(self, arg):
        self.parameter = arg.split()
        self.complete_parameter()

        localsearch = sdsessionparam.get_value('localsearch')
        dry_run = sdsessionparam.get_value('dry_run')

        type_ = sdsessionparam.get_value('type')

        kw = {'parameter': self.parameter, 'dry_run': dry_run}

        if localsearch:
            if type_ == 'Dataset':
                datasets = sdldataset.get_datasets(**kw)
                if not dry_run:
                    if len(datasets) == 0:
                        sdtools.print_stderr('Dataset not found')
                    else:
                        sdldataset.print_list(datasets)
            elif type_ == 'File':
                files = sdlfile.get_files(**kw)
                if not dry_run:
                    sdlfile.print_(files)
        else:
            if type_ == 'Dataset':
                datasets = sdrdataset.get_datasets(**kw)
                if not dry_run:
                    if len(datasets) == 0:
                        sdtools.print_stderr('Dataset not found')
                    else:
                        sdrdataset.print_list(datasets)
            elif type_ == 'File':
                files = sdrfile.get_files(**kw)
                if not dry_run:
                    sdrfile.print_list(files)
예제 #3
0
    def complete_parameter(self):
        self.parameter.extend(
            sdsessionparam.get_serialized_session_facets()
        )  # TODO: maybe set session facets as default parameter being overwrited by parameter

        sddeferredafter.add_default_parameter(
            self.parameter, 'limit', sdsessionparam.get_value('limit'))
        sddeferredafter.add_default_parameter(
            self.parameter, 'verbose', sdsessionparam.get_value('verbose'))
예제 #4
0
    def cmdloop(self, intro=None):
        """This override is an hack that add an exception handler to Cmd module.

        It provides two things:
            - Better handling of SDException (prevent leaving the console when SDException occur)
            - Better handling of CTRL-C (prevent the console to exit when hitting CTRL-C (just stops the current instruction if any))
                - TODO: currently, this DOESN'T WORK: see below

        Notes:
            This method override Cmd base class method.
            Hack from http://stackoverflow.com/questions/8813291/better-handling-of-keyboardinterrupt-in-cmd-cmd-command-line-interpreter
        """
        print(self.intro) # displays intro msg only once

        while True:
            try:
                super(BaseConsole, self).cmdloop(intro="") # note that we don't display intro here on purpose (else, it would be displayed twice)

                # during normal exit, we come here
                self.postloop()
                break
            except SDException,e: # prevent exiting console when SDException is raised
                sdtools.print_stderr()
                sdtools.print_stderr('*** Error occured ***')
                sdtools.print_stderr()

                sdtools.print_stderr('Error code: %s'%e.code)
                sdtools.print_stderr('Error message: %s'%e.msg)
                sdtools.print_stderr()

                debug=sdsessionparam.get_value('debug')
                if debug:
                    sdtools.print_stderr('Stacktrace:')
                    traceback.print_exc(file=sys.stderr)
            """
예제 #5
0
 def do_l(self,arg):
     localsearch=sdsessionparam.get_value('localsearch')
     if not localsearch:
         sdsessionparam.set('localsearch','true')
         print 'Local search enabled'
     else:
         sdsessionparam.set('localsearch','false')
         print 'Local search disabled'
예제 #6
0
    def do_t(self,arg):

        type_=sdsessionparam.get_value('type')

        if type_=='Dataset':
            sdsessionparam.set('type','File')
            print "Type set to 'File'"
        elif type_=='File':
            sdsessionparam.set('type','Dataset')
            print "Type set to 'Dataset'"
예제 #7
0
파일: sdlock.py 프로젝트: Prodiguer/synda
def lock(model):
    dry_run=sdsessionparam.get_value('dry_run')
    params=sdremoteparam.run(pname='index_node',facets_group={'type':['Dataset'],'model':[model],'replica':['false']},dry_run=dry_run)
    indexes=params.get('index_node',[])

    if not dry_run:
        if len(indexes)>0:
            master_index=max(indexes, key=attrgetter('count'))

            sdsessionparam.set("searchapi_host",master_index.name)
            sdsessionparam.set("distrib","false")
            sdsessionparam.set("model",model)
        else:
            raise SDException('SDATLOCK-001','Model not found')
예제 #8
0
파일: sdadmcon.py 프로젝트: ncarenton/synda
    def do_select(self,arg):
        # -- SQL mode (non-documented as not sure if this is here to stay) -- #
        tokens=arg.split()

        column=tokens[0]

        table=tokens[2]
        where_clause=tokens[4:]

        parameter=where_clause

        dry_run=sdsessionparam.get_value('dry_run')

        parameter.append('type=%s'%table.title())
        result=sdquicksearch.run(parameter=parameter,dry_run=dry_run)

        for f in result.files:
            if column in f:
                print f[column]
예제 #9
0
def lock(model):
    dry_run = sdsessionparam.get_value('dry_run')
    params = sdremoteparam.run(pname='index_node',
                               facets_group={
                                   'type': ['Dataset'],
                                   'model': [model],
                                   'replica': ['false']
                               },
                               dry_run=dry_run)
    indexes = params.get('index_node', [])

    if not dry_run:
        if len(indexes) > 0:
            master_index = max(indexes, key=attrgetter('count'))

            sdsessionparam.set("searchapi_host", master_index.name)
            sdsessionparam.set("distrib", "false")
            sdsessionparam.set("model", model)
        else:
            raise SDException('SDATLOCK-001', 'Model not found')
예제 #10
0
    def do_select(self, arg):
        # -- SQL mode (non-documented as not sure if this is here to stay) -- #

        import sdsessionparam, sdquicksearch

        tokens = arg.split()

        column = tokens[0]

        table = tokens[2]
        where_clause = tokens[4:]

        parameter = where_clause

        dry_run = sdsessionparam.get_value('dry_run')

        parameter.append('type=%s' % table.title())
        result = sdquicksearch.run(parameter=parameter, dry_run=dry_run)

        for f in result.files:
            if column in f:
                print f[column]
예제 #11
0
    def cmdloop(self, intro=None):
        """This override is an hack that add an exception handler to Cmd module.

        It provides two things:
            - Better handling of SDException (prevent leaving the console when SDException occur)
            - Better handling of CTRL-C (prevent the console to exit when hitting CTRL-C (just stops the current instruction if any))
                - TODO: currently, this DOESN'T WORK: see below

        Notes:
            This method override Cmd base class method.
            Hack from http://stackoverflow.com/questions/8813291/better-handling-of-keyboardinterrupt-in-cmd-cmd-command-line-interpreter
        """
        print(self.intro)  # displays intro msg only once

        while True:
            try:
                super(BaseConsole, self).cmdloop(
                    intro=""
                )  # note that we don't display intro here on purpose (else, it would be displayed twice)

                # during normal exit, we come here
                self.postloop()
                break
            except SDException, e:  # prevent exiting console when SDException is raised
                sdtools.print_stderr()
                sdtools.print_stderr('*** Error occured ***')
                sdtools.print_stderr()

                sdtools.print_stderr('Error code: %s' % e.code)
                sdtools.print_stderr('Error message: %s' % e.msg)
                sdtools.print_stderr()

                debug = sdsessionparam.get_value('debug')
                if debug:
                    sdtools.print_stderr('Stacktrace:')
                    traceback.print_exc(file=sys.stderr)
            """
예제 #12
0
 def do_d(self,arg):
     localsearch=sdsessionparam.get_value('dry_run')
     if not localsearch:
         sdsessionparam.set('dry_run','true')
예제 #13
0
    def complete_parameter(self):
        self.parameter.extend(sdsessionparam.get_serialized_session_facets()) # TODO: maybe set session facets as default parameter being overwrited by parameter

        sddeferredafter.add_default_parameter(self.parameter,'limit',sdsessionparam.get_value('limit'))
        sddeferredafter.add_default_parameter(self.parameter,'verbose',sdsessionparam.get_value('verbose'))