def run(self, args): if args.download: args.no_content = True search = self.client.remote('pupyutils.search') newer = None older = None if args.timestamp_newer: try: newer = datetime.fromtimestamp(int(args.timestamp_newer)) except ValueError: newer = dateparser.parse(args.timestamp_newer) newer = int((newer - datetime.fromtimestamp(0)).total_seconds()) if args.timestamp_older: try: older = datetime.fromtimestamp(int(args.timestamp_older)) except ValueError: older = dateparser.parse(args.timestamp_older) older = int((older - datetime.fromtimestamp(0)).total_seconds()) s = search.Search( args.filename, strings=args.strings, max_size=args.max_size, root_path=args.path, follow_symlinks=args.links, no_content=args.no_content, case=args.insensitive, binary=args.binary, same_fs=not args.no_same_fs, search_in_archives=args.archive, content_only=args.content_only, suid=args.suid, sgid=args.sgid, user=args.user, group=args.group, owaw=args.own_world_accessible_write, newer=newer, older=older, xattr=args.xattr if args.xattr else args.xattr is not False) if args.download: config = self.client.pupsrv.config download_folder = config.get_folder( 'searches', {'%c': self.client.short_name()}) downloader = DownloadFronted(self.client, honor_single_file_root=True, verbose=self.info, error=self.error) on_data, on_completed = downloader.create_download_callback( download_folder) def on_completed_info(): self.success('Search completed, finish download engine') on_completed() self.terminate = downloader.interrupt self.info('Search+Download started. Use ^C to interrupt') s.run_cbs(on_data, on_completed_info, self.error) downloader.process() self.success('Search+Download completed') else: terminate = Event() def on_data(res): if terminate.is_set(): return if type(res) == tuple: f, v = res self.success(u'{}: {}'.format(f, v)) else: self.success(res) def on_completed(): terminate.set() self.info('complete') self.terminate = terminate.set self.info('Search started. Use ^C to interrupt') error = self.error if not args.verbose: def error(x): pass s.run_cb(on_data, on_completed, error) terminate.wait() s.stop()
def run(self, args): if args.download: args.no_content = True s = self.client.conn.modules['pupyutils.search'].Search( args.filename, strings=args.strings, max_size=args.max_size, root_path=args.path, follow_symlinks=args.links, no_content=args.no_content, case=args.insensitive, binary=args.binary, ) if args.download: config = self.client.pupsrv.config or PupyConfig() download_folder = config.get_folder( 'searches', {'%c': self.client.short_name()}) downloader = DownloadFronted(self.client, honor_single_file_root=True, verbose=self.info, error=self.error) on_data, on_completed = downloader.create_download_callback( download_folder) self.terminate = downloader.interrupt self.info('Search+Download started. Use ^C to interrupt') s.run_cbs(on_data, on_completed, self.error) downloader.process() self.info('complete') else: terminate = threading.Event() def on_data(res): if terminate.is_set(): return if args.strings and not args.no_content: if type(res) == tuple: f, v = res if type(f) == unicode: f = f.encode('utf-8') if type(v) == unicode: v = v.encode('utf-8') self.success('{}: {}'.format(f, v)) elif not args.content_only: self.success(res) else: self.success(res) def on_completed(): terminate.set() self.info('complete') self.terminate = terminate.set self.info('Search started. Use ^C to interrupt') s.run_cb(on_data, on_completed, self.error) terminate.wait() s.stop()