def on_data(self, name, data): if name == 'create_user': del data['name'] try: floorc = self.BASE_FLOORC + '\n'.join(['%s %s' % (k, v) for k, v in data.items()]) + '\n' with open(G.FLOORC_PATH, 'w') as floorc_fd: floorc_fd.write(floorc) utils.reload_settings() if False in [bool(x) for x in (G.USERNAME, G.API_KEY, G.SECRET)]: editor.message_dialog('Something went wrong. You will need to sign up for an account to use Floobits.') api.send_error({'message': 'No username or secret'}) else: p = os.path.join(G.BASE_DIR, 'welcome.md') with open(p, 'w') as fd: text = editor.welcome_text % (G.USERNAME, self.proto.host) fd.write(text) d = utils.get_persistent_data() d['auto_generated_account'] = True utils.update_persistent_data(d) G.AUTO_GENERATED_ACCOUNT = True editor.open_file(p) except Exception as e: msg.debug(traceback.format_exc()) msg.error(str(e)) try: d = utils.get_persistent_data() d['disable_account_creation'] = True utils.update_persistent_data(d) finally: self.proto.stop()
def create_or_link_account(self, context, host, force, cb): if host != "floobits.com": self.link_account(context, host, cb) return disable_account_creation = utils.get_persistent_data().get( 'disable_account_creation') if disable_account_creation and not force: print( 'We could not automatically create or link your floobits account. Please go to floobits.com and sign up to use this plugin.' ) return if not G.EXPERT_MODE: editor.message_dialog( 'Thank you for installing the Floobits plugin!\n\nLet\'s set up your editor to work with Floobits.' ) choices = [ 'Sign in to Floobits', 'Automatically create a Floobits account', 'Cancel (see https://floobits.com/help/floorc)' ] ( choice, index ) = yield self.user_select, context, 'You need an account to use Floobits! Do you want to:', choices, None if index == -1 or index == 2: d = utils.get_persistent_data() if not d.get('disable_account_creation'): d['disable_account_creation'] = True utils.update_persistent_data(d) # TODO: this instruction is only useful for Sublime Text editor.message_dialog( '''You can set up a Floobits account at any time under:\n\nTools -> Floobits -> Set up''' ) cb(None) return agent = None if index == 0: agent = credentials.RequestCredentialsHandler() else: agent = account.CreateAccountHandler() agent.once('end', cb) try: reactor.reactor.connect(agent, host, G.DEFAULT_PORT, True) except Exception as e: print(str_e(e))
def create_or_link_account(self, context, host, force, cb): if host != "floobits.com": self.link_account(context, host, cb) return disable_account_creation = utils.get_persistent_data().get("disable_account_creation") if disable_account_creation and not force: print( "We could not automatically create or link your floobits account. Please go to floobits.com and sign up to use this plugin." ) return if not G.EXPERT_MODE: editor.message_dialog( "Thank you for installing the Floobits plugin!\n\nLet's set up your editor to work with Floobits." ) choices = ["Sign in to Floobits", "Create a Floobits account", "Cancel (see https://floobits.com/help/floorc)"] (choice, index) = ( yield self.user_select, context, "You need an account to use Floobits! Do you want to:", choices, None, ) if index == -1 or index == 2: d = utils.get_persistent_data() if not d.get("disable_account_creation"): d["disable_account_creation"] = True utils.update_persistent_data(d) # TODO: this instruction is only useful for Sublime Text editor.message_dialog( """You can set up a Floobits account at any time under\n\nTools -> Floobits -> Set up""" ) cb(None) return agent = None if index == 0: agent = credentials.RequestCredentialsHandler() else: agent = account.CreateAccountHandler() agent.once("end", cb) try: reactor.reactor.connect(agent, host, G.DEFAULT_PORT, True) except Exception as e: print(str_e(e))
def on_data(self, name, data): if name == 'credentials': with open(G.FLOORC_PATH, 'w') as floorc_fd: floorc = self.BASE_FLOORC + '\n'.join(['%s %s' % (k, v) for k, v in data['credentials'].items()]) + '\n' floorc_fd.write(floorc) utils.reload_settings() if not G.USERNAME or not G.SECRET: editor.message_dialog('Something went wrong. See https://%s/help/floorc/ to complete the installation.' % self.proto.host) api.send_error({'message': 'No username or secret'}) else: p = os.path.join(G.BASE_DIR, 'welcome.md') with open(p, 'w') as fd: text = WELCOME_MSG % (G.USERNAME, self.proto.host) fd.write(text) editor.open_file(p) self.proto.stop()
def on_data(self, name, data): if name == 'create_user': del data['name'] try: floorc = self.BASE_FLOORC + '\n'.join( ['%s %s' % (k, v) for k, v in data.items()]) + '\n' with open(G.FLOORC_PATH, 'w') as floorc_fd: floorc_fd.write(floorc) utils.reload_settings() if False in [ bool(x) for x in (G.USERNAME, G.API_KEY, G.SECRET) ]: editor.message_dialog( 'Something went wrong. You will need to sign up for an account to use Floobits.' ) api.send_error({'message': 'No username or secret'}) else: p = os.path.join(G.BASE_DIR, 'welcome.md') with open(p, 'w') as fd: text = editor.welcome_text % (G.USERNAME, self.proto.host) fd.write(text) d = utils.get_persistent_data() d['auto_generated_account'] = True utils.update_persistent_data(d) G.AUTO_GENERATED_ACCOUNT = True editor.open_file(p) except Exception as e: msg.debug(traceback.format_exc()) msg.error(str(e)) try: d = utils.get_persistent_data() d['disable_account_creation'] = True utils.update_persistent_data(d) finally: self.proto.stop()
def stomp_prompt(self, changed_bufs, missing_bufs, new_files, ignored, cb): if not (G.EXPERT_MODE or hasattr(sublime, 'KEEP_OPEN_ON_FOCUS_LOST')): editor.message_dialog( 'Your copy of %s/%s is out of sync. ' 'You will be prompted after you close this dialog.' % (self.owner, self.workspace)) def pluralize(arg): return arg != 1 and 's' or '' overwrite_local = '' overwrite_remote = '' missing = [buf['path'] for buf in missing_bufs] changed = [buf['path'] for buf in changed_bufs] to_remove = set(missing + ignored) to_upload = set(new_files + changed).difference(to_remove) to_fetch = changed + missing to_upload_len = len(to_upload) to_remove_len = len(to_remove) remote_len = to_remove_len + to_upload_len to_fetch_len = len(to_fetch) msg.log('To fetch: ', ', '.join(to_fetch)) msg.log('To upload: ', ', '.join(to_upload)) msg.log('To remove: ', ', '.join(to_remove)) if not to_fetch: overwrite_local = 'Fetch nothing' elif to_fetch_len < 5: overwrite_local = 'Fetch %s' % ', '.join(to_fetch) else: overwrite_local = 'Fetch %s file%s' % (to_fetch_len, pluralize(to_fetch_len)) if to_upload_len < 5: to_upload_str = 'Upload %s' % ', '.join(to_upload) else: to_upload_str = 'Upload %s' % to_upload_len if to_remove_len < 5: to_remove_str = 'remove %s' % ', '.join(to_remove) else: to_remove_str = 'remove %s' % to_remove_len if to_upload: overwrite_remote += to_upload_str if to_remove: overwrite_remote += ' and ' if to_remove: overwrite_remote += to_remove_str if remote_len >= 5 and overwrite_remote: overwrite_remote += ' files' # Be fancy and capitalize "remove" if it's the first thing in the string if len(overwrite_remote) > 0: overwrite_remote = overwrite_remote[0].upper( ) + overwrite_remote[1:] connected_users_msg = '' def filter_user(u): if u.get('is_anon'): return False if 'patch' not in u.get('perms'): return False if u.get('username') == self.username: return False return True users = set([ v['username'] for k, v in self.workspace_info['users'].items() if filter_user(v) ]) if users: if len(users) < 4: connected_users_msg = ' Connected: ' + ', '.join(users) else: connected_users_msg = ' %s users connected' % len(users) # TODO: change action based on numbers of stuff action = 'Overwrite' opts = [ [ '%s %s remote file%s.' % (action, remote_len, pluralize(remote_len)), overwrite_remote ], [ '%s %s local file%s.' % (action, to_fetch_len, pluralize(to_fetch_len)), overwrite_local ], ['Cancel', 'Disconnect.' + connected_users_msg], ] w = sublime.active_window() or G.WORKSPACE_WINDOW flags = 0 if hasattr(sublime, 'KEEP_OPEN_ON_FOCUS_LOST'): flags |= sublime.KEEP_OPEN_ON_FOCUS_LOST w.show_quick_panel(opts, cb, flags)
def stomp_prompt(self, changed_bufs, missing_bufs, new_files, ignored, cb): if not (G.EXPERT_MODE or hasattr(sublime, 'KEEP_OPEN_ON_FOCUS_LOST')): editor.message_dialog('Your copy of %s/%s is out of sync. ' 'You will be prompted after you close this dialog.' % (self.owner, self.workspace)) def pluralize(arg): return arg != 1 and 's' or '' overwrite_local = '' overwrite_remote = '' missing = [buf['path'] for buf in missing_bufs] changed = [buf['path'] for buf in changed_bufs] to_remove = set(missing + ignored) to_upload = set(new_files + changed).difference(to_remove) to_fetch = changed + missing to_upload_len = len(to_upload) to_remove_len = len(to_remove) remote_len = to_remove_len + to_upload_len to_fetch_len = len(to_fetch) msg.log('To fetch: ', ', '.join(to_fetch)) msg.log('To upload: ', ', '.join(to_upload)) msg.log('To remove: ', ', '.join(to_remove)) if not to_fetch: overwrite_local = 'Fetch nothing' elif to_fetch_len < 5: overwrite_local = 'Fetch %s' % ', '.join(to_fetch) else: overwrite_local = 'Fetch %s file%s' % (to_fetch_len, pluralize(to_fetch_len)) if to_upload_len < 5: to_upload_str = 'Upload %s' % ', '.join(to_upload) else: to_upload_str = 'Upload %s' % to_upload_len if to_remove_len < 5: to_remove_str = 'remove %s' % ', '.join(to_remove) else: to_remove_str = 'remove %s' % to_remove_len if to_upload: overwrite_remote += to_upload_str if to_remove: overwrite_remote += ' and ' if to_remove: overwrite_remote += to_remove_str if remote_len >= 5 and overwrite_remote: overwrite_remote += ' files' # Be fancy and capitalize "remove" if it's the first thing in the string if len(overwrite_remote) > 0: overwrite_remote = overwrite_remote[0].upper() + overwrite_remote[1:] connected_users_msg = '' def filter_user(u): if u.get('is_anon'): return False if 'patch' not in u.get('perms'): return False if u.get('username') == self.username: return False return True users = set([v['username'] for k, v in self.workspace_info['users'].items() if filter_user(v)]) if users: if len(users) < 4: connected_users_msg = ' Connected: ' + ', '.join(users) else: connected_users_msg = ' %s users connected' % len(users) # TODO: change action based on numbers of stuff action = 'Overwrite' opts = [ ['%s %s remote file%s.' % (action, remote_len, pluralize(remote_len)), overwrite_remote], ['%s %s local file%s.' % (action, to_fetch_len, pluralize(to_fetch_len)), overwrite_local], ['Cancel', 'Disconnect.' + connected_users_msg], ] w = sublime.active_window() or G.WORKSPACE_WINDOW flags = 0 if hasattr(sublime, 'KEEP_OPEN_ON_FOCUS_LOST'): flags |= sublime.KEEP_OPEN_ON_FOCUS_LOST w.show_quick_panel(opts, cb, flags)
def stomp_prompt(self, changed_bufs, missing_bufs, new_files, ignored, cb): if not G.EXPERT_MODE: editor.message_dialog('Your copy of %s/%s is out of sync. ' 'You will be prompted after you close this dialog.' % (self.owner, self.workspace)) def pluralize(arg): return arg != 1 and 's' or '' overwrite_local = '' overwrite_remote = '' missing = [buf['path'] for buf in missing_bufs] changed = [buf['path'] for buf in changed_bufs] to_remove = set(missing + ignored) to_upload = set(new_files + changed).difference(to_remove) to_fetch = changed + missing to_upload_len = len(to_upload) to_remove_len = len(to_remove) remote_len = to_remove_len + to_upload_len to_fetch_len = len(to_fetch) msg.log('To fetch: ', ', '.join(to_fetch)) msg.log('To upload: ', ', '.join(to_upload)) msg.log('To remove: ', ', '.join(to_remove)) if not to_fetch: overwrite_local = 'Fetch nothing' elif to_fetch_len < 5: overwrite_local = 'Fetch %s' % ', '.join(to_fetch) else: overwrite_local = 'Fetch %s file%s' % (to_fetch_len, pluralize(to_fetch_len)) if to_upload_len < 5: to_upload_str = 'upload %s' % ', '.join(to_upload) else: to_upload_str = 'upload %s' % to_upload_len if to_remove_len < 5: to_remove_str = 'remove %s' % ', '.join(to_remove) else: to_remove_str = 'remove %s' % to_remove_len if to_upload: overwrite_remote += to_upload_str if to_remove: overwrite_remote += ' and ' if to_remove: overwrite_remote += to_remove_str if remote_len >= 5 and overwrite_remote: overwrite_remote += ' files' overwrite_remote = overwrite_remote.capitalize() action = 'Overwrite' # TODO: change action based on numbers of stuff opts = [ ['%s %s remote file%s.' % (action, remote_len, pluralize(remote_len)), overwrite_remote], ['%s %s local file%s.' % (action, to_fetch_len, pluralize(to_fetch_len)), overwrite_local], ['Cancel', 'Disconnect and resolve conflict manually.'], ] w = sublime.active_window() or G.WORKSPACE_WINDOW w.show_quick_panel(opts, cb)
def stomp_prompt(self, changed_bufs, missing_bufs, new_files, ignored, cb): if not G.EXPERT_MODE: editor.message_dialog( 'Your copy of %s/%s is out of sync. ' 'You will be prompted after you close this dialog.' % (self.owner, self.workspace)) def pluralize(arg): return arg != 1 and 's' or '' overwrite_local = '' overwrite_remote = '' missing = [buf['path'] for buf in missing_bufs] changed = [buf['path'] for buf in changed_bufs] to_upload = set(new_files + changed).difference(set(ignored)) to_remove = missing + ignored to_fetch = changed + missing to_upload_len = len(to_upload) to_remove_len = len(to_remove) remote_len = to_remove_len + to_upload_len to_fetch_len = len(to_fetch) msg.log('To fetch: %s' % ', '.join(to_fetch)) msg.log('To upload: %s' % ', '.join(to_upload)) msg.log('To remove: %s' % ', '.join(to_remove)) if not to_fetch: overwrite_local = 'Fetch nothing' elif to_fetch_len < 5: overwrite_local = 'Fetch %s' % ', '.join(to_fetch) else: overwrite_local = 'Fetch %s file%s' % (to_fetch_len, pluralize(to_fetch_len)) if to_upload_len < 5: to_upload_str = 'upload %s' % ', '.join(to_upload) else: to_upload_str = 'upload %s' % to_upload_len if to_remove_len < 5: to_remove_str = 'remove %s' % ', '.join(to_remove) else: to_remove_str = 'remove %s' % to_remove_len if to_upload: overwrite_remote += to_upload_str if to_remove: overwrite_remote += ' and ' if to_remove: overwrite_remote += to_remove_str if remote_len >= 5 and overwrite_remote: overwrite_remote += ' files' overwrite_remote = overwrite_remote.capitalize() action = 'Overwrite' # TODO: change action based on numbers of stuff opts = [ [ '%s %s remote file%s.' % (action, remote_len, pluralize(remote_len)), overwrite_remote ], [ '%s %s local file%s.' % (action, to_fetch_len, pluralize(to_fetch_len)), overwrite_local ], ['Cancel', 'Disconnect and resolve conflict manually.'], ] # TODO: sublime text doesn't let us focus a window. so use the active window. super lame # G.WORKSPACE_WINDOW.show_quick_panel(opts, cb) w = sublime.active_window() or G.WORKSPACE_WINDOW w.show_quick_panel(opts, cb)