def __init__(self, tractography_spatial_indexing, initial_body=None, tractography=None, save_query_callback=None, include_folders=['.']): cmd.Cmd.__init__(self, 'Tab') self.prompt = '[wmql] ' self.include_folders = include_folders self.tractography = tractography self.querier = EvaluateQueries(tractography_spatial_indexing) self.save_query_callback = save_query_callback self.save_query_visitor = SaveQueries(self.save_query_callback, self.querier) if initial_body is not None: if isinstance(initial_body, str): initial_body = queries_preprocess( initial_body, filename='Shell', include_folders=self.include_folders) if isinstance(initial_body, list): self.querier.visit(ast.Module(initial_body)) else: self.querier.visit(initial_body)
class TractQuerierCmd(cmd.Cmd): def __init__( self, tractography_spatial_indexing, initial_body=None, tractography=None, save_query_callback=None, include_folders=['.'] ): cmd.Cmd.__init__(self, 'Tab') self.prompt = '[wmql] ' self.include_folders = include_folders self.tractography = tractography self.querier = EvaluateQueries(tractography_spatial_indexing) self.save_query_callback = save_query_callback self.save_query_visitor = SaveQueries( self.save_query_callback, self.querier ) if initial_body is not None: if isinstance(initial_body, str): initial_body = queries_preprocess( initial_body, filename='Shell', include_folders=self.include_folders ) if isinstance(initial_body, list): self.querier.visit(ast.Module(initial_body)) else: self.querier.visit(initial_body) @safe_method def do_dir(self, patterns): if patterns == '': patterns = '*' patterns = patterns.split(' ') k = self.names() keys = [] if len(patterns) > 0: for p in patterns: keys_found = fnmatch.filter(k, p) keys_found.sort() keys += keys_found else: keys = k for k in keys: print k @safe_method def do_save(self, line): try: body = queries_preprocess( line, filename='shell', include_folders=self.include_folders ) self.save_query_visitor.visit(ast.Module(body=body)) except SyntaxError, e: print e.value except TractQuerierSyntaxError, e: print e.value
class TractQuerierCmd(cmd.Cmd): def __init__(self, tractography_spatial_indexing, initial_body=None, tractography=None, save_query_callback=None, include_folders=['.']): cmd.Cmd.__init__(self, 'Tab') self.prompt = '[wmql] ' self.include_folders = include_folders self.tractography = tractography self.querier = EvaluateQueries(tractography_spatial_indexing) self.save_query_callback = save_query_callback self.save_query_visitor = SaveQueries(self.save_query_callback, self.querier) if initial_body is not None: if isinstance(initial_body, str): initial_body = queries_preprocess( initial_body, filename='Shell', include_folders=self.include_folders) if isinstance(initial_body, list): self.querier.visit(ast.Module(initial_body)) else: self.querier.visit(initial_body) @safe_method def do_dir(self, patterns): if patterns == '': patterns = '*' patterns = patterns.split(' ') k = self.names() keys = [] if len(patterns) > 0: for p in patterns: keys_found = fnmatch.filter(k, p) keys_found.sort() keys += keys_found else: keys = k for k in keys: print k @safe_method def do_save(self, line): try: body = queries_preprocess(line, filename='shell', include_folders=self.include_folders) self.save_query_visitor.visit(ast.Module(body=body)) except SyntaxError, e: print e.value except TractQuerierSyntaxError, e: print e.value
def __init__( self, tractography_spatial_indexing, initial_body=None, tractography=None, save_query_callback=None, include_folders=['.'] ): cmd.Cmd.__init__(self, 'Tab') self.prompt = '[wmql] ' self.include_folders = include_folders self.tractography = tractography self.querier = EvaluateQueries(tractography_spatial_indexing) self.save_query_callback = save_query_callback self.save_query_visitor = SaveQueries( self.save_query_callback, self.querier ) if initial_body is not None: if isinstance(initial_body, str): initial_body = queries_preprocess( initial_body, filename='Shell', include_folders=self.include_folders ) if isinstance(initial_body, list): self.querier.visit(ast.Module(initial_body)) else: self.querier.visit(initial_body)