def plugin_loaded(): global called_plugin_loaded if called_plugin_loaded: return called_plugin_loaded = True print('Floobits: Called plugin_loaded.') if not os.path.exists(G.FLOORC_JSON_PATH): migrations.migrate_floorc() utils.reload_settings() G.SOCK_SINGLE_READ = SOCK_SINGLE_READ # TODO: one day this can be removed (once all our users have updated) old_colab_dir = os.path.realpath(os.path.expanduser(os.path.join('~', '.floobits'))) if os.path.isdir(old_colab_dir) and not os.path.exists(G.BASE_DIR): print('Renaming %s to %s' % (old_colab_dir, G.BASE_DIR)) os.rename(old_colab_dir, G.BASE_DIR) os.symlink(G.BASE_DIR, old_colab_dir) try: utils.normalize_persistent_data() except Exception as e: print('Floobits: Error normalizing persistent data:', str_e(e)) # Keep on truckin' I guess d = utils.get_persistent_data() G.AUTO_GENERATED_ACCOUNT = d.get('auto_generated_account', False) setup()
def plugin_loaded(): global called_plugin_loaded if called_plugin_loaded: return called_plugin_loaded = True print('Floobits: Called plugin_loaded.') if not os.path.exists(G.FLOORC_JSON_PATH): migrations.migrate_floorc() utils.reload_settings() # TODO: one day this can be removed (once all our users have updated) old_colab_dir = os.path.realpath( os.path.expanduser(os.path.join('~', '.floobits'))) if os.path.isdir(old_colab_dir) and not os.path.exists(G.BASE_DIR): print('Renaming %s to %s' % (old_colab_dir, G.BASE_DIR)) os.rename(old_colab_dir, G.BASE_DIR) os.symlink(G.BASE_DIR, old_colab_dir) try: utils.normalize_persistent_data() except Exception as e: print('Floobits: Error normalizing persistent data:', str_e(e)) # Keep on truckin' I guess d = utils.get_persistent_data() G.AUTO_GENERATED_ACCOUNT = d.get('auto_generated_account', False) # Sublime plugin API stuff can't be called right off the bat if not utils.can_auth(): utils.set_timeout(create_or_link_account, 1) utils.set_timeout(global_tick, 1)
def main(): G.__VERSION__ = '0.11' G.__PLUGIN_VERSION__ = '1.5.10' utils.reload_settings() if not os.path.exists(G.FLOORC_JSON_PATH): migrations.migrate_floorc() utils.reload_settings() migrations.rename_floobits_dir() migrations.migrate_symlinks() try: utils.normalize_persistent_data() except Exception: pass emacs = emacs_handler.EmacsHandler() G.emacs = emacs _, port = reactor.reactor.listen(emacs) utils.set_timeout(cb, 100, port) reactor.reactor.block()
def main(): G.__VERSION__ = '0.11' G.__PLUGIN_VERSION__ = '1.5.6' utils.reload_settings() if not os.path.exists(G.FLOORC_JSON_PATH): migrations.migrate_floorc() utils.reload_settings() migrations.rename_floobits_dir() migrations.migrate_symlinks() try: utils.normalize_persistent_data() except Exception: pass emacs = emacs_handler.EmacsHandler() G.emacs = emacs _, port = reactor.reactor.listen(emacs) utils.set_timeout(cb, 100, port) reactor.reactor.block()
def main(): G.__VERSION__ = '0.11' G.__PLUGIN_VERSION__ = None parser = optparse.OptionParser(usage='%prog [options]') parser.add_option("-p", "--port", dest="port", default=0, help="The port to listen on. Useful for debugging.") parser.add_option("--set-version", dest="version") options, args = parser.parse_args() port = int(options.port) G.__PLUGIN_VERSION__ = options.version if not G.__PLUGIN_VERSION__: print('--set-version is a required argument') print('args: %s' % ' '.join(args)) sys.exit(1) utils.reload_settings() if not os.path.exists(G.FLOORC_JSON_PATH): migrations.migrate_floorc() utils.reload_settings() migrations.rename_floobits_dir() migrations.migrate_symlinks() try: utils.normalize_persistent_data() except Exception: pass emacs = emacs_handler.EmacsHandler() G.emacs = emacs _, port = reactor.reactor.listen(emacs, port=port) utils.set_timeout(cb, 100, port) reactor.reactor.block()
def main(): if not os.path.exists(G.FLOORC_JSON_PATH): migrations.migrate_floorc() utils.reload_settings() default_auth = G.AUTH.get(G.DEFAULT_HOST, {}) parser = optparse.OptionParser(usage=usage) parser.add_option("-u", "--username", dest="username", default=default_auth.get('username'), help="Your Floobits username") parser.add_option("-s", "--secret", dest="secret", default=default_auth.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=G.DEFAULT_HOST, help="The host to connect to. Deprecated. Use --url instead.") parser.add_option("-p", "--port", dest="port", default=G.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('flootty %s' % version.FLOOTTY_VERSION) return 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 options.host is None: options.host = G.DEFAULT_HOST if options.host != G.DEFAULT_HOST and options.secret == default_auth.get('secret'): auth = G.AUTH.get(options.host) if not auth: return die("Please add credentials for %s in ~/.floorc.json" % options.host) options.username = auth.get('username') options.secret = auth.get('secret') if not options.workspace or not options.owner: try: now_editing = get_now_editing_workspaces() except Exception as e: print(str_e(e)) else: if len(now_editing.body) == 1: options.workspace = now_editing.body[0]['name'] options.owner = now_editing.body[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) G.AGENT = f atexit.register(f.cleanup) f.connect_to_internet() f.select()