def main(): settings = read_floorc() usage = "usage: %prog --workspace=WORKSPACE --owner=OWNER [options] term_name.\n\n\tSee https://github.com/Floobits/flootty" parser = optparse.OptionParser(usage=usage) parser.add_option("-u", "--username", dest="username", default=settings.get('username'), help="Your Floobits username") parser.add_option("-s", "--secret", dest="secret", default=settings.get('secret'), help="Your Floobits secret (api key)") parser.add_option("--host", dest="host", default="floobits.com", help="The host to connect to") parser.add_option("-p", "--port", dest="port", default=3448, help="The port to connect to") parser.add_option("-c", "--create", dest="create", default=False, action="store_true", help="The terminal name to create") parser.add_option("-w", "--workspace", dest="room", help="The workspace name") parser.add_option("-o", "--owner", dest="owner", help="The workspace owner") parser.add_option("-l", "--list", dest="list", default=False, action="store_true", help="List all ptys in the workspace") parser.add_option("--no-ssl", dest="use_ssl", default=True, action="store_false", help="Do not use this option unless you know what you are doing!") parser.add_option("--url", dest="room_url", default=None, help="The URL of the workspace to connect to. This is a convenience for copy-pasting from the browser.") options, args = parser.parse_args() G.USERNAME = options.username G.SECRET = options.secret default_term_name = "" if options.create: default_term_name = "_" term_name = args and args[0] or default_term_name if options.room and options.owner and options.room_url: parser.error("You can either specify --workspace and --owner, or --url, but not both.") if not options.room or not options.owner: floo = {} if options.room_url: floo = parse_url(options.room_url) else: for floo_path in walk_up(os.path.realpath('.')): try: floo = json.loads(open(os.path.join(floo_path, '.floo'), 'rb').read().decode('utf-8')) floo = parse_url(floo['url']) except Exception: pass options.room = floo.get('room') options.owner = floo.get('owner') if not options.port: options.port = floo.get('port') if not options.host: options.host = floo.get('host') if not options.room or not options.owner: try: now_editing = api.get_now_editing_workspaces() now_editing = json.loads(now_editing.read().decode('utf-8')) if len(now_editing) == 1: options.room = now_editing[0]['name'] options.owner = now_editing[0]['owner'] # TODO: list possible workspaces to join if > 1 is active except Exception as e: raise e if options.list: if len(term_name) != 0: die("I don't understand why you gave me a positional argument.") for opt in ['room', 'owner', 'username', 'secret']: if not getattr(options, opt): parser.error('%s not given' % opt) f = Flootty(options, term_name) atexit.register(f.cleanup) f.connect_to_internet() f.select()
def main(): settings = read_floorc() parser = optparse.OptionParser(usage=usage) parser.add_option("-u", "--username", dest="username", default=settings.get('username'), help="Your Floobits username") parser.add_option("-s", "--secret", dest="secret", default=settings.get('secret'), help="Your Floobits secret (api key)") parser.add_option("-c", "--create", dest="create", default=False, action="store_true", help="The terminal name to create") parser.add_option("--host", dest="host", default=DEFAULT_HOST, help="The host to connect to. Deprecated. Use --url instead.") parser.add_option("-p", "--port", dest="port", default=DEFAULT_PORT, help="The port to connect to. Deprecated. Use --url instead.") parser.add_option("-w", "--workspace", dest="workspace", help="The workspace name. --owner is required with this option. Deprecated. Use --url instead.") parser.add_option("-o", "--owner", dest="owner", help="The workspace owner. --workspace is required with this option. Deprecated. Use --url instead.") parser.add_option("-l", "--list", dest="list", default=False, action="store_true", help="List all terminals in the workspace") parser.add_option("--unsafe", dest="safe", default=True, action="store_false", help="Less safe terminal. This allows other users to send enter in your terminal.") parser.add_option("--no-ssl", dest="use_ssl", default=True, action="store_false", help="Do not use this option unless you know what you are doing!") parser.add_option("--url", dest="workspace_url", default=None, help="The URL of the workspace to connect to.") parser.add_option("--resize", dest="resize", default=False, action="store_true", help="Resize your terminal to the host terminal size.") parser.add_option("-P", "--preserve-ps1", dest="set_prompt", default=True, action="store_false", help="Don't change $PS1 (bash/zsh prompt)") parser.add_option("-v", "--version", dest="version", default=False, action="store_true", help="Print version") options, args = parser.parse_args() if options.version: print(CLIENT) return G.USERNAME = options.username G.SECRET = options.secret default_term_name = "" if options.create: default_term_name = "ftty" term_name = args and args[0] or default_term_name if options.workspace and options.owner and options.workspace_url: # TODO: confusing parser.error("You can either specify --workspace and --owner, or --url, but not both.") if bool(options.workspace) != bool(options.owner): parser.error("You must specify a workspace and owner or neither.") for opt in ['owner', 'workspace']: if getattr(options, opt): print('%s is deprecated. Please use --url instead.' % opt) if not options.workspace or not options.owner: floo = {} if options.workspace_url: floo = utils.parse_url(options.workspace_url) else: for floo_path in walk_up(os.path.realpath('.')): try: floo = json.loads(open(os.path.join(floo_path, '.floo'), 'rb').read().decode('utf-8')) floo = utils.parse_url(floo['url']) except Exception: pass else: break options.host = floo.get('host') options.workspace = floo.get('workspace') options.owner = floo.get('owner') options.use_ssl = floo.get('secure') if not options.port: options.port = floo.get('port') if not options.host: options.host = floo.get('host') if not options.workspace or not options.owner: now_editing = api.get_now_editing_workspaces() now_editing = json.loads(now_editing.read().decode('utf-8')) if len(now_editing) == 1: options.workspace = now_editing[0]['name'] options.owner = now_editing[0]['owner'] # TODO: list possible workspaces to join if > 1 is active if options.list: if len(term_name) != 0: die("I don't understand why you gave me a positional argument.") for opt in ['workspace', 'owner', 'username', 'secret']: if not getattr(options, opt): parser.error('%s not given' % opt) color_reset = '\033[0m' if options.safe: green = '\033[92m' print('%sTerminal is safe. Other users will not be able to send [enter]%s' % (green, color_reset)) else: yellorange = '\033[93m' print('%sTerminal is unsafe. Other users will be able to send [enter]. Be wary!%s' % (yellorange, color_reset)) f = Flootty(options, term_name) atexit.register(f.cleanup) f.connect_to_internet() f.select()