Esempio n. 1
0
 def handler(self, name, data):
     if name == 'create_user':
         del data['name']
         try:
             floorc = BASE_FLOORC + '\n'.join(
                 ['%s %s' % (k, v) for k, v in data.items()]) + '\n'
             with open(G.FLOORC_PATH, 'wb') as floorc_fd:
                 floorc_fd.write(floorc.encode('utf-8'))
             utils.reload_settings()
             if False in [
                     bool(x) for x in (G.USERNAME, G.API_KEY, G.SECRET)
             ]:
                 sublime.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, 'wb') as fd:
                     text = welcome_text % (G.USERNAME, self.host)
                     fd.write(text.encode('utf-8'))
                 d = utils.get_persistent_data()
                 d['auto_generated_account'] = True
                 utils.update_persistent_data(d)
                 G.AUTO_GENERATED_ACCOUNT = True
                 sublime.active_window().open_file(p)
         except Exception as e:
             msg.error(e)
         try:
             d = utils.get_persistent_data()
             d['disable_account_creation'] = True
             utils.update_persistent_data(d)
         finally:
             self.stop()
 def handler(self, name, data):
     if name == "create_user":
         del data["name"]
         try:
             floorc = BASE_FLOORC + "\n".join(["%s %s" % (k, v) for k, v in data.items()]) + "\n"
             with open(G.FLOORC_PATH, "wb") as floorc_fd:
                 floorc_fd.write(floorc.encode("utf-8"))
             utils.reload_settings()
             if False in [bool(x) for x in (G.USERNAME, G.API_KEY, G.SECRET)]:
                 sublime.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, "wb") as fd:
                     text = welcome_text % (G.USERNAME, self.host)
                     fd.write(text.encode("utf-8"))
                 d = utils.get_persistent_data()
                 d["auto_generated_account"] = True
                 utils.update_persistent_data(d)
                 G.AUTO_GENERATED_ACCOUNT = True
                 sublime.active_window().open_file(p)
         except Exception as e:
             msg.error(e)
         try:
             d = utils.get_persistent_data()
             d["disable_account_creation"] = True
             utils.update_persistent_data(d)
         finally:
             self.stop()
 def handler(self, name, data):
     if name == 'create_user':
         del data['name']
         try:
             floorc = BASE_FLOORC + '\n'.join(['%s %s' % (k, v) for k, v in data.items()]) + '\n'
             with open(G.FLOORC_PATH, 'wb') as floorc_fd:
                 floorc_fd.write(floorc.encode('utf-8'))
             utils.reload_settings()
             if False in [bool(x) for x in (G.USERNAME, G.API_KEY, G.SECRET)]:
                 sublime.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, 'wb') as fd:
                     text = welcome_text % (G.USERNAME, self.host)
                     fd.write(text.encode('utf-8'))
                 d = utils.get_persistent_data()
                 d['auto_generated_account'] = True
                 utils.update_persistent_data(d)
                 G.AUTO_GENERATED_ACCOUNT = True
                 sublime.active_window().open_file(p)
         except Exception as e:
             msg.error(e)
         try:
             d = utils.get_persistent_data()
             d['disable_account_creation'] = True
             utils.update_persistent_data(d)
         finally:
             self.stop()
 def handler(self, name, data):
     if name == 'credentials':
         with open(G.FLOORC_PATH, 'wb') as floorc_fd:
             floorc = BASE_FLOORC + '\n'.join(['%s %s' % (k, v) for k, v in data['credentials'].items()]) + '\n'
             floorc_fd.write(floorc.encode('utf-8'))
         utils.reload_settings()  # This only works because G.JOINED_WORKSPACE is False
         if not G.USERNAME or not G.SECRET:
             sublime.message_dialog('Something went wrong. See https://%s/help/floorc/ to complete the installation.' % self.host)
             api.send_error({'message': 'No username or secret'})
         else:
             p = os.path.join(G.BASE_DIR, 'welcome.md')
             with open(p, 'wb') as fd:
                 text = 'Welcome %s!\n\nYou\'re all set to collaborate. You may want to check out our docs at https://%s/help/plugins/#sublime-usage' % (G.USERNAME, self.host)
                 fd.write(text.encode('utf-8'))
             sublime.active_window().open_file(p)
         self.stop()
Esempio n. 5
0
    def _on_join_workspace(self, data):
        workspace = data["workspace"]
        owner = data["workspace_owner"]
        G.USERNAME = data["username"]
        G.SECRET = data["secret"]
        utils.reload_settings()
        try:
            G.PROJECT_PATH = utils.get_persistent_data()["workspaces"][owner][workspace]["path"]
        except Exception:
            G.PROJECT_PATH = ""

        if G.PROJECT_PATH and os.path.isdir(G.PROJECT_PATH):
            return self.remote_connect(owner, workspace)

        G.PROJECT_PATH = "~/floobits/share/%s/%s" % (owner, workspace)
        self.get_input("Give me a directory to sync data to: ", G.PROJECT_PATH, self.join_workspace, owner, workspace)
Esempio n. 6
0
    def _on_join_workspace(self, data):
        workspace = data['workspace']
        owner = data['workspace_owner']
        G.USERNAME = data['username']
        G.SECRET = data['secret']
        editor.line_endings = data['line_endings'].find("unix") >= 0 and "\n" or "\r\n"
        utils.reload_settings()
        try:
            G.PROJECT_PATH = utils.get_persistent_data()['workspaces'][owner][workspace]['path']
        except Exception:
            G.PROJECT_PATH = ''

        if G.PROJECT_PATH and os.path.isdir(G.PROJECT_PATH):
            return self.remote_connect(owner, workspace)

        G.PROJECT_PATH = '~/floobits/share/%s/%s' % (owner, workspace)
        self.get_input('Save workspace files to: ', G.PROJECT_PATH, self.join_workspace, owner, workspace)
Esempio n. 7
0
    def _on_join_workspace(self, data):
        workspace = data['workspace']
        owner = data['workspace_owner']
        G.USERNAME = data['username']
        G.SECRET = data['secret']
        utils.reload_settings()
        try:
            G.PROJECT_PATH = utils.get_persistent_data(
            )['workspaces'][owner][workspace]['path']
        except Exception:
            G.PROJECT_PATH = ''

        if G.PROJECT_PATH and os.path.isdir(G.PROJECT_PATH):
            return self.remote_connect(owner, workspace)

        G.PROJECT_PATH = '~/floobits/share/%s/%s' % (owner, workspace)
        self.get_input('Give me a directory to sync data to: ', G.PROJECT_PATH,
                       self.join_workspace, owner, workspace)
    def _on_join_workspace(self, data):
        workspace = data['workspace']
        owner = data['workspace_owner']
        G.USERNAME = data['username']
        G.SECRET = data['secret']
        editor.line_endings = data['line_endings'].find(
            "unix") >= 0 and "\n" or "\r\n"
        utils.reload_settings()
        try:
            G.PROJECT_PATH = utils.get_persistent_data(
            )['workspaces'][owner][workspace]['path']
        except Exception:
            G.PROJECT_PATH = ''

        if G.PROJECT_PATH and os.path.isdir(G.PROJECT_PATH):
            return self.remote_connect(owner, workspace)

        G.PROJECT_PATH = '~/floobits/share/%s/%s' % (owner, workspace)
        self.get_input('Save workspace files to: ', G.PROJECT_PATH,
                       self.join_workspace, owner, workspace)
 def handler(self, name, data):
     if name == "credentials":
         with open(G.FLOORC_PATH, "wb") as floorc_fd:
             floorc = BASE_FLOORC + "\n".join(["%s %s" % (k, v) for k, v in data["credentials"].items()]) + "\n"
             floorc_fd.write(floorc.encode("utf-8"))
         utils.reload_settings()  # This only works because G.JOINED_WORKSPACE is False
         if not G.USERNAME or not G.SECRET:
             sublime.message_dialog(
                 "Something went wrong. See https://%s/help/floorc/ to complete the installation." % self.host
             )
             api.send_error({"message": "No username or secret"})
         else:
             p = os.path.join(G.BASE_DIR, "welcome.md")
             with open(p, "wb") as fd:
                 text = (
                     "Welcome %s!\n\nYou're all set to collaborate. You may want to check out our docs at https://%s/help/plugins/#sublime-usage"
                     % (G.USERNAME, self.host)
                 )
                 fd.write(text.encode("utf-8"))
             sublime.active_window().open_file(p)
         self.stop()
Esempio n. 10
0
 def handler(self, name, data):
     if name == 'credentials':
         with open(G.FLOORC_PATH, 'wb') as floorc_fd:
             floorc = BASE_FLOORC + '\n'.join(
                 ['%s %s' % (k, v)
                  for k, v in data['credentials'].items()]) + '\n'
             floorc_fd.write(floorc.encode('utf-8'))
         utils.reload_settings(
         )  # This only works because G.JOINED_WORKSPACE is False
         if not G.USERNAME or not G.SECRET:
             sublime.message_dialog(
                 'Something went wrong. See https://%s/help/floorc/ to complete the installation.'
                 % self.host)
             api.send_error({'message': 'No username or secret'})
         else:
             p = os.path.join(G.BASE_DIR, 'welcome.md')
             with open(p, 'wb') as fd:
                 text = 'Welcome %s!\n\nYou\'re all set to collaborate. You may want to check out our docs at https://%s/help/plugins/#sublime-usage' % (
                     G.USERNAME, self.host)
                 fd.write(text.encode('utf-8'))
             sublime.active_window().open_file(p)
         self.stop()
 def reload_settings(self):
     utils.reload_settings()
     self.username = G.USERNAME
     self.secret = G.SECRET
     self.api_key = G.API_KEY
Esempio n. 12
0
    def _on_share_dir(self, data):
        file_to_share = None
        utils.reload_settings()
        G.USERNAME = data['username']
        G.SECRET = data['secret']
        dir_to_share = data['dir_to_share']
        perms = data['perms']
        editor.line_endings = data['line_endings'].find(
            "unix") >= 0 and "\n" or "\r\n"
        dir_to_share = os.path.expanduser(dir_to_share)
        dir_to_share = utils.unfuck_path(dir_to_share)
        workspace_name = os.path.basename(dir_to_share)
        G.PROJECT_PATH = os.path.realpath(dir_to_share)
        msg.debug('%s %s %s' % (G.USERNAME, workspace_name, G.PROJECT_PATH))

        if os.path.isfile(dir_to_share):
            file_to_share = dir_to_share
            dir_to_share = os.path.dirname(dir_to_share)

        try:
            utils.mkdir(dir_to_share)
        except Exception:
            return msg.error(
                "The directory %s doesn't exist and I can't create it." %
                dir_to_share)

        floo_file = os.path.join(dir_to_share, '.floo')

        info = {}
        try:
            floo_info = open(floo_file, 'rb').read().decode('utf-8')
            info = json.loads(floo_info)
        except (IOError, OSError):
            pass
        except Exception as e:
            msg.warn("Couldn't read .floo file: %s: %s" % (floo_file, str(e)))

        workspace_url = info.get('url')
        if workspace_url:
            parsed_url = api.prejoin_workspace(workspace_url, dir_to_share,
                                               {'perms': perms})
            if parsed_url:
                # TODO: make sure we create_flooignore
                # utils.add_workspace_to_persistent_json(parsed_url['owner'], parsed_url['workspace'], workspace_url, dir_to_share)
                agent = self.remote_connect(parsed_url['owner'],
                                            parsed_url['workspace'], False)
                return agent.once(
                    "room_info",
                    lambda: agent.upload(file_to_share or dir_to_share))

        parsed_url = utils.get_workspace_by_path(
            dir_to_share, lambda workspace_url: api.prejoin_workspace(
                workspace_url, dir_to_share, {'perms': perms}))
        if parsed_url:
            agent = self.remote_connect(parsed_url['owner'],
                                        parsed_url['workspace'], False)
            return agent.once(
                "room_info",
                lambda: agent.upload(file_to_share or dir_to_share))

        def on_done(data, choices=None):
            self.get_input('Workspace name:',
                           workspace_name,
                           self._on_create_workspace,
                           workspace_name,
                           dir_to_share,
                           owner=data.get('response'),
                           perms=perms)

        try:
            r = api.get_orgs_can_admin()
        except IOError as e:
            return editor.error_message('Error getting org list: %s' % str(e))
        if r.code >= 400 or len(r.body) == 0:
            return on_done({'response': G.USERNAME})
        i = 0
        choices = []
        choices.append([G.USERNAME, i])
        for org in r.body:
            i += 1
            choices.append([org['name'], i])

        self.get_input('Create workspace owned by (%s) ' %
                       " ".join([x[0] for x in choices]),
                       '',
                       on_done,
                       choices=choices)
Esempio n. 13
0
    def _on_share_dir(self, data):
        utils.reload_settings()
        G.USERNAME = data['username']
        G.SECRET = data['secret']
        dir_to_share = data['dir_to_share']
        perms = data.get('perms')
        dir_to_share = os.path.expanduser(dir_to_share)
        dir_to_share = utils.unfuck_path(dir_to_share)
        workspace_name = os.path.basename(dir_to_share)
        G.PROJECT_PATH = os.path.realpath(dir_to_share)
        msg.debug('%s %s %s' % (G.USERNAME, workspace_name, G.PROJECT_PATH))

        if os.path.isfile(dir_to_share):
            return msg.error('%s is a file. Give me a directory please.' %
                             dir_to_share)

        try:
            utils.mkdir(dir_to_share)
        except Exception:
            return msg.error(
                "The directory %s doesn't exist and I can't make it." %
                dir_to_share)

        floo_file = os.path.join(dir_to_share, '.floo')

        info = {}
        try:
            floo_info = open(floo_file, 'rb').read().decode('utf-8')
            info = json.loads(floo_info)
        except (IOError, OSError):
            pass
        except Exception:
            msg.debug("Couldn't read the floo_info file: %s" % floo_file)

        workspace_url = info.get('url')
        if workspace_url:
            try:
                result = utils.parse_url(workspace_url)
            except Exception as e:
                msg.error(str(e))
            else:
                workspace_name = result['workspace']
                try:
                    # TODO: blocking. beachballs sublime 2 if API is super slow
                    api.get_workspace_by_url(workspace_url)
                except HTTPError:
                    workspace_url = None
                    workspace_name = os.path.basename(dir_to_share)
                else:
                    utils.add_workspace_to_persistent_json(
                        result['owner'], result['workspace'], workspace_url,
                        dir_to_share)

        workspace_url = utils.get_workspace_by_path(
            dir_to_share) or workspace_url

        if workspace_url:
            try:
                api.get_workspace_by_url(workspace_url)
            except HTTPError:
                pass
            else:
                result = utils.parse_url(workspace_url)
                agent = self.remote_connect(result['owner'],
                                            result['workspace'], False)
                return agent.once("room_info",
                                  lambda: agent.upload(dir_to_share))

        def on_done(data, choices=None):
            self._on_create_workspace({},
                                      workspace_name,
                                      dir_to_share,
                                      owner=data.get('response'),
                                      perms=perms)

        orgs = api.get_orgs_can_admin()
        orgs = json.loads(orgs.read().decode('utf-8'))
        if len(orgs) == 0:
            return on_done({'response': G.USERNAME})
        i = 0
        choices = []
        choices.append([G.USERNAME, i])
        for o in orgs:
            i += 1
            choices.append([o['name'], i])

        self.get_input('Create workspace for (%s) ' %
                       " ".join([x[0] for x in choices]),
                       '',
                       on_done,
                       choices=choices)
Esempio n. 14
0
    def _on_share_dir(self, data):
        file_to_share = None
        utils.reload_settings()
        G.USERNAME = data['username']
        G.SECRET = data['secret']
        dir_to_share = data['dir_to_share']
        perms = data['perms']
        editor.line_endings = data['line_endings'].find("unix") >= 0 and "\n" or "\r\n"
        dir_to_share = os.path.expanduser(dir_to_share)
        dir_to_share = utils.unfuck_path(dir_to_share)
        workspace_name = os.path.basename(dir_to_share)
        G.PROJECT_PATH = os.path.realpath(dir_to_share)
        msg.debug('%s %s %s' % (G.USERNAME, workspace_name, G.PROJECT_PATH))

        if os.path.isfile(dir_to_share):
            file_to_share = dir_to_share
            dir_to_share = os.path.dirname(dir_to_share)

        try:
            utils.mkdir(dir_to_share)
        except Exception:
            return msg.error("The directory %s doesn't exist and I can't create it." % dir_to_share)

        floo_file = os.path.join(dir_to_share, '.floo')

        info = {}
        try:
            floo_info = open(floo_file, 'rb').read().decode('utf-8')
            info = json.loads(floo_info)
        except (IOError, OSError):
            pass
        except Exception as e:
            msg.warn("Couldn't read .floo file: %s: %s" % (floo_file, str(e)))

        workspace_url = info.get('url')
        if workspace_url:
            parsed_url = api.prejoin_workspace(workspace_url, dir_to_share, {'perms': perms})
            if parsed_url:
                # TODO: make sure we create_flooignore
                # utils.add_workspace_to_persistent_json(parsed_url['owner'], parsed_url['workspace'], workspace_url, dir_to_share)
                agent = self.remote_connect(parsed_url['owner'], parsed_url['workspace'], False)
                return agent.once("room_info", lambda: agent.upload(file_to_share or dir_to_share))

        parsed_url = utils.get_workspace_by_path(dir_to_share,
                                                 lambda workspace_url: api.prejoin_workspace(workspace_url, dir_to_share, {'perms': perms}))
        if parsed_url:
            agent = self.remote_connect(parsed_url['owner'], parsed_url['workspace'], False)
            return agent.once("room_info", lambda: agent.upload(file_to_share or dir_to_share))

        def on_done(data, choices=None):
            self.get_input('Workspace name:',
                           workspace_name,
                           self._on_create_workspace,
                           workspace_name,
                           dir_to_share,
                           owner=data.get('response'),
                           perms=perms)

        try:
            r = api.get_orgs_can_admin()
        except IOError as e:
            return editor.error_message('Error getting org list: %s' % str(e))
        if r.code >= 400 or len(r.body) == 0:
            return on_done({'response': G.USERNAME})
        i = 0
        choices = []
        choices.append([G.USERNAME, i])
        for org in r.body:
            i += 1
            choices.append([org['name'], i])

        self.get_input('Create workspace owned by (%s) ' % " ".join([x[0] for x in choices]), '', on_done, choices=choices)
Esempio n. 15
0
 def reload_settings(self):
     utils.reload_settings()
     self.username = G.USERNAME
     self.secret = G.SECRET
     self.api_key = G.API_KEY
Esempio n. 16
0

VUI = vui.VUI()

reactor = reactor.reactor

# Protocol version
G.__VERSION__ = '0.11'
G.__PLUGIN_VERSION__ = '3.1.8'

G.LOG_TO_CONSOLE = False
G.CHAT_VIEW = True

msg.editor_log = msg.floobits_log

utils.reload_settings()


class EventLoop(Thread):
    def __init__(self, vim, ticker):
        super(EventLoop, self).__init__()
        self.vim = vim
        self.ticker = ticker
        self.intervals = []

    def run(self):
        msg.log("Starting event loop.")
        while True:
            sleep(0.1)
            self.vim.session.threadsafe_call(self.tick)
Esempio n. 17
0
    def _on_share_dir(self, data):
        utils.reload_settings()
        G.USERNAME = data["username"]
        G.SECRET = data["secret"]
        dir_to_share = data["dir_to_share"]
        perms = data.get("perms")
        dir_to_share = os.path.expanduser(dir_to_share)
        dir_to_share = utils.unfuck_path(dir_to_share)
        workspace_name = os.path.basename(dir_to_share)
        G.PROJECT_PATH = os.path.realpath(dir_to_share)
        msg.debug("%s %s %s" % (G.USERNAME, workspace_name, G.PROJECT_PATH))

        if os.path.isfile(dir_to_share):
            return msg.error("%s is a file. Give me a directory please." % dir_to_share)

        try:
            utils.mkdir(dir_to_share)
        except Exception:
            return msg.error("The directory %s doesn't exist and I can't make it." % dir_to_share)

        floo_file = os.path.join(dir_to_share, ".floo")

        info = {}
        try:
            floo_info = open(floo_file, "rb").read().decode("utf-8")
            info = json.loads(floo_info)
        except (IOError, OSError):
            pass
        except Exception:
            msg.debug("Couldn't read the floo_info file: %s" % floo_file)

        workspace_url = info.get("url")
        if workspace_url:
            try:
                result = utils.parse_url(workspace_url)
            except Exception as e:
                msg.error(str(e))
            else:
                workspace_name = result["workspace"]
                try:
                    # TODO: blocking. beachballs sublime 2 if API is super slow
                    api.get_workspace_by_url(workspace_url)
                except HTTPError:
                    workspace_url = None
                    workspace_name = os.path.basename(dir_to_share)
                else:
                    utils.add_workspace_to_persistent_json(
                        result["owner"], result["workspace"], workspace_url, dir_to_share
                    )

        workspace_url = utils.get_workspace_by_path(dir_to_share) or workspace_url

        if workspace_url:
            try:
                api.get_workspace_by_url(workspace_url)
            except HTTPError:
                pass
            else:
                result = utils.parse_url(workspace_url)
                agent = self.remote_connect(result["owner"], result["workspace"], False)
                return agent.once("room_info", lambda: agent.upload(dir_to_share))

        def on_done(data, choices=None):
            self._on_create_workspace({}, workspace_name, dir_to_share, owner=data.get("response"), perms=perms)

        orgs = api.get_orgs_can_admin()
        orgs = json.loads(orgs.read().decode("utf-8"))
        if len(orgs) == 0:
            return on_done({"response": G.USERNAME})
        i = 0
        choices = []
        choices.append([G.USERNAME, i])
        for o in orgs:
            i += 1
            choices.append([o["name"], i])

        self.get_input("Create workspace for (%s) " % " ".join([x[0] for x in choices]), "", on_done, choices=choices)