def get_context(arg, defaults): def get_from_logpath(filesystems, logpath): if os.path.isfile(logpath): logpath = os.path.abspath(logpath) for k, v in filesystems.items(): if v.logpath == logpath: return v return None filesystems = get_filesystems(defaults) fs = None mount_info = None path = '/' # name:/path or logpath:/path if ':' in arg: name = arg.split(':')[0] # name:/path if name in filesystems: fs = filesystems[name] # logpath:/path else: fs = get_from_logpath(filesystems, name) if fs: path = ':'.join(arg.split(':')[1:]) # Inside a mountpoint if fs is None: mount_info = utils.get_mount_info(arg) if mount_info: logpath = mount_info.logpath fs = get_from_logpath(filesystems, logpath) path = os.path.abspath(logpath) path = re.sub(r'^%s' % mount_info.mountpoint, path, '') # name of logpath if fs is None: # name if arg in filesystems: fs = filesystems[arg] # logpath else: fs = get_from_logpath(filesystems, arg) if fs is None: sys.stderr.write("logpath or path?\n") sys.exit(2) if mount_info is None: mount_info = utils.get_mount_info(fs.logpath, logpath=True) return utils.AttrDict( fs=fs, path=path, mount_info=mount_info, )
def command(): if getpass.getuser() != 'root': sys.stderr.write("Err. Sorry you need root permissions for using iptables.\n") sys.exit(2) args = parser.parse_args() offset = 0 if args.ntp_server: offset = get_ntp_offset(args.ntp_server) mount_info = utils.get_mount_info() port = get_cmd_port(args, mount_info, get_defaults(args.user))-2 main2 = functools.partial(main, reset=args.reset, offset=offset, port=port) if not args.log: stdscr = curses.initscr() curses.curs_set(0) try: curses.wrapper(main2) except KeyboardInterrupt: i = 0 line = stdscr.instr(i, 0) while line: sys.stdout.write(line.decode()+'\n') i += 1 line = stdscr.instr(i, 0) else: main2()
def command(): if getpass.getuser() != 'root': sys.stderr.write( "Err. Sorry you need root permissions for using iptables.\n") sys.exit(2) args = parser.parse_args() offset = 0 if args.ntp_server: offset = get_ntp_offset(args.ntp_server) mount_info = utils.get_mount_info() port = get_cmd_port(args, mount_info, get_defaults(args.user)) - 2 main2 = functools.partial(main, reset=args.reset, offset=offset, port=port) if not args.log: stdscr = curses.initscr() curses.curs_set(0) try: curses.wrapper(main2) except KeyboardInterrupt: i = 0 line = stdscr.instr(i, 0) while line: sys.stdout.write(line.decode() + '\n') i += 1 line = stdscr.instr(i, 0) else: main2()