def run(self, args): self._downloader = DownloadFronted(self.client, args.exclude, args.include, args.follow_symlinks, args.ignore_size, args.no_single_device, False, self.info if args.verbose else None, self.success, self.error) if args.calculate_size: obj = self.client.remote('transfer') count, size = self._downloader.du(args.remote_file, obj) if count is not None and size is not None: self.success('Files: {} Size: {}'.format( count, size_human_readable(size))) else: self._downloader.download(args.remote_file, args.local_file, args.archive, args.chunk_size * 1024) if args.verbose: self.info('Destination folder: {}'.format( self._downloader.dest_file)) if args.open and path.exists(self._downloader.dest_file): viewer = self.config.get('default_viewers', 'xdg_open') or 'xdg-open' if args.verbose: self.info('Open file {} with {}'.format( self._downloader.dest_file, viewer)) with open(devnull, 'w') as DEVNULL: Popen([viewer, self._downloader.dest_file], stdin=DEVNULL, stdout=DEVNULL, stderr=DEVNULL)
class DownloaderScript(PupyModule): """ download a file/directory from a remote system """ dependencies = { 'all': [ 'transfer', 'scandir' ], 'windows': [ 'junctions' ] } @classmethod def init_argparse(cls): cls.arg_parser = PupyArgumentParser(prog='download', description=cls.__doc__) cls.arg_parser.add_argument('-v', '--verbose', action='store_true', default=False, help='Be verbose during download') cls.arg_parser.add_argument('-a', '--archive', action='store_true', default=False, help='Store to archive (use this only for dirs)') cls.arg_parser.add_argument('-i', '--include', help='Regex to include files') cls.arg_parser.add_argument('-e', '--exclude', help='Regex to exclude files') cls.arg_parser.add_argument('-F', '--follow-symlinks', action='store_true', help='Follow symlinks') cls.arg_parser.add_argument('-I', '--ignore-size', action='store_true', help='Ignore st_size') cls.arg_parser.add_argument('-X', '--no-single-device', action='store_false', default=True, help='Allow to touch another devices (st_rdev)') cls.arg_parser.add_argument('-S', '--calculate-size', action='store_true', help='Calculate size only') cls.arg_parser.add_argument('remote_file', metavar='<remote_path>', completer=remote_path_completer) cls.arg_parser.add_argument('local_file', nargs='?', metavar='<local_path>', completer=path_completer) def run(self, args): self._downloader = DownloadFronted( self.client, args.exclude, args.include, args.follow_symlinks, args.ignore_size, args.no_single_device, False, self.info if args.verbose else None, self.success, self.error ) if args.calculate_size: count, size = self._downloader.du(args.remote_file) if count is not None and size is not None: self.success('Files: {} Size: {}'.format(count, size_human_readable(size))) else: self._downloader.download( args.remote_file, args.local_file, args.archive ) if args.verbose: self.info('Destination folder: {}'.format(self._downloader.dest_file)) def interrupt(self): if self._downloader: self._downloader.interrupt()
def run(self, args): self._downloader = DownloadFronted( self.client, args.exclude, args.include, args.follow_symlinks, args.ignore_size, args.no_single_device, False, self.info if args.verbose else None, self.success, self.error ) if args.calculate_size: count, size = self._downloader.du(args.remote_file) if count is not None and size is not None: self.success('Files: {} Size: {}'.format(count, size_human_readable(size))) else: self._downloader.download( args.remote_file, args.local_file, args.archive ) if args.verbose: self.info('Destination folder: {}'.format(self._downloader.dest_file))
class DownloaderScript(PupyModule): """ download a file/directory from a remote system """ dependencies = { 'all': ['transfer', 'scandir', 'zipfile', 'tarfile'], 'windows': ['junctions'] } @classmethod def init_argparse(cls): cls.arg_parser = PupyArgumentParser(prog='download', description=cls.__doc__) cls.arg_parser.add_argument('-v', '--verbose', action='store_true', default=False, help='Be verbose during download') cls.arg_parser.add_argument('-O', '--open', action='store_true', default=False, help='Open file with xdg-open') cls.arg_parser.add_argument( '-a', '--archive', action='store_true', default=False, help='Store to archive (use this only for dirs)') cls.arg_parser.add_argument('-C', '--chunk-size', type=int, default=1 * 1024, help='Max transfer chunk (Kbytes)') cls.arg_parser.add_argument('-i', '--include', help='Regex to include files') cls.arg_parser.add_argument('-e', '--exclude', help='Regex to exclude files') cls.arg_parser.add_argument('-F', '--follow-symlinks', action='store_true', help='Follow symlinks') cls.arg_parser.add_argument('-I', '--ignore-size', action='store_true', help='Ignore st_size') cls.arg_parser.add_argument( '-X', '--no-single-device', action='store_false', default=True, help='Allow to touch another devices (st_rdev)') cls.arg_parser.add_argument('-S', '--calculate-size', action='store_true', help='Calculate size only') cls.arg_parser.add_argument('remote_file', metavar='<remote_path>', completer=remote_path_completer) cls.arg_parser.add_argument('local_file', nargs='?', metavar='<local_path>', completer=path_completer) def run(self, args): self._downloader = DownloadFronted(self.client, args.exclude, args.include, args.follow_symlinks, args.ignore_size, args.no_single_device, False, self.info if args.verbose else None, self.success, self.error) if args.calculate_size: obj = self.client.remote('transfer') count, size = self._downloader.du(args.remote_file, obj) if count is not None and size is not None: self.success('Files: {} Size: {}'.format( count, size_human_readable(size))) else: self._downloader.download(args.remote_file, args.local_file, args.archive, args.chunk_size * 1024) if args.verbose: self.info('Destination folder: {}'.format( self._downloader.dest_file)) if args.open and path.exists(self._downloader.dest_file): viewer = self.config.get('default_viewers', 'xdg_open') or 'xdg-open' if args.verbose: self.info('Open file {} with {}'.format( self._downloader.dest_file, viewer)) with open(devnull, 'w') as DEVNULL: Popen([viewer, self._downloader.dest_file], stdin=DEVNULL, stdout=DEVNULL, stderr=DEVNULL) def interrupt(self): if self._downloader: self._downloader.interrupt()
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()