def execute(self, context, args, options=[]): regexp = args[0] if len(args) == 2: path = args[1] else: path = context.cwd regexp = args[0] comp_regexp = re.compile( regexp, (('-i' in options) and re.IGNORECASE or 0) | re.UNICODE) walk_builtin = BuiltinRegistry.getInstance()['walk'] newctx = HotwireContext(context.cwd) for fobj in walk_builtin.execute(newctx, [path]): fp = None try: fp = open_text_file(fobj.path) for i, line in enumerate(fp): match = comp_regexp.search(line) if match: yield FileStringMatch(fobj.path, line[:-1], i, match.start(), match.end()) fp.close() except OSError, e: pass except UnicodeDecodeError, e: pass
def apply(context, *args): _("""Like Unix xargs - take input and convert to arguments.""") newargs = list(args) for argument in context.input: if not isinstance(argument, str): argument = str(argument) newargs.append(argument) new_context = HotwireContext(initcwd=context.cwd) # TODO - pull in resolver from shell.py? Should this function expand # aliases? pipeline = Pipeline.create(new_context, None, *newargs) pipeline.execute_sync(assert_all_threaded=True) for result in pipeline.get_output(): yield result
def script(*args, **kwargs): from hotwire.command import Pipeline, HotwireContext if not 'context' in kwargs: kwargs['context'] = HotwireContext(initcwd=(kwargs.get('cwd', None))) return Pipeline.create(kwargs['context'], kwargs.get('resolver', None), *args)
def setUp(self): self._tmpd = None self._context = HotwireContext()