Exemple #1
0
    def start_setup(self):
        """Starts our setup.

        Args:
            None.

        Returns:
            bool. True or False on success.

        """
        backup_result = self.backup_vimdir()
        if not backup_result:
            msg = ('Could not backup vim directory. Failing.')
            generic_msg.error(msg)
            self.handle_failure()

        setup_result = self.vim_setup()
        if not setup_result:
            self.handle_failure()

        msg = ('If a problem occurs with your new vim setup, your previous '
               '.vim, is backed up here: %s' % (self.backup_directory))
        generic_msg.info(msg)

        msg = ('Finished setup. Looks like it worked! Woot! '
               'Thanks for using it!')
        generic_msg.final(msg)
Exemple #2
0
def handle_moving_dirs(dir_location, new_location):
    """Handles moving our directories.

    Args:
        dir_location (str): The directory to move.
        new_location (str): Where to move it to.

    Returns:
        bool. True or False.

    """
    if os.path.exists(new_location):
        msg = ('Location we are trying to move to already '
               'exists: %s.' % (new_location))
        generic_msg.error(msg)
        return False

    if os.path.exists(dir_location):
        try:
            shutil.move(dir_location, new_location)
        except shutil.Error as err:
            msg = ('There was an error moving directory %s to %s. '
                   'Error: %s' % (dir_location, new_location, err))
            generic_msg.error(msg)
            return False

    return True
Exemple #3
0
def handle_rmdir(dir_name, recursive=False):
    """Handles removing directories so we don't replicate code.

    Args:
        dir_name (str): The directory to remove.
        recursive (bool): Remove it recursively or not.

    Returns:
        bool. True or False.

    """
    if recursive:
        try:
            os.removedirs(dir_name)
        except OSError as err:
            msg = ('Failure to remove directory %s. '
                   'Error: %s' % (dir_name, err))
            generic_msg.error(msg)
            return False
    else:
        try:
            os.rmdir(dir_name)
        except OSError as err:
            msg = ('Failure to remove directory %s. '
                   'Error: %s' % (dir_name, err))
            generic_msg.error(msg)
            return False

    return True
Exemple #4
0
    def handle_failure(self):
        """Handles our failure cases.

        Args:
            None.

        Returns:
            None.

        """
        msg = ('Failed during vim setup. Do you wish to '
               'roll back the changes? [y/n]')
        generic_msg.prompt(msg)
        input_result = raw_input().lower()
        if input_result in self.yes_answers:
            msg = ('Rolling back changes.')
            generic_msg.info(msg)
            rmdir_result = handle_rmdir(self.vim_dir, recursive=True)
            if not rmdir_result:
                msg = ('There was an issue removing the .vim directory.')
                generic_msg.error(msg)
            else:
                msg = ('Moving the backup directory %s back '
                       'to .vim.' % (self.backup_directory))
                generic_msg.info(msg)
                handle_moving_dirs(self.backup_directory, self.vim_dir)
        else:
            msg = ('Not rolling back. VIM setup may be '
                   'incomplete. Your backup can be found '
                   'here: %s' % (self.backup_directory))
            generic_msg.warning(msg)

        exit_msg = ('Failed to do the setup properly. My apologies.')
        sys.exit(exit_msg)
Exemple #5
0
    def get_plugins(self):
        """Gets the plugins we want for vim.

        Args:
            None.

        Returns:
            bool. True or False.

        """
        status_code = 0
        plugin_file = os.path.join(os.getcwd(), 'vim_plugins.json')
        with open(plugin_file, 'r') as fopen:
            try:
                vim_plugins = json.loads(fopen.read())
            except ValueError as err:
                msg = ('An error occurred when attempting to parse the '
                       'json file. Error: %s' % (err))
                generic_msg.error(err)
                self.handle_failure()
            except TypeError as err:
                msg = ('An error occurred when attempting to parse the '
                       'json file. Error: %s' % (err))
                generic_msg.error(err)
                self.handle_failure()

        pathogen_url = ('https://raw.github.com/tpope/vim-pathogen/master'
                        '/autoload/pathogen.vim')

        result = self.handle_curl_clone(pathogen_url,
                                        os.path.join(self.vim_dir, 'autoload'))
        status_code += result

        for key, value in vim_plugins.iteritems():
            full_dirname = os.path.join(self.vim_dir, key)
            for obj in value:
                if obj['type'] == 'git':
                    result = self.handle_git_clone(
                        obj['location'], full_dirname
                    )
                    status_code += result
                elif obj['type'] == 'curl':
                    result = self.handle_curl_clone(
                        obj['location'], full_dirname
                    )
                    status_code += result
                else:
                    msg = ('No type specified. Ignoring. %s %s' % (key, obj))
                    generic_msg.warning(msg)

        if status_code:
            msg = ('Looks like the setup had some issues. We are '
                   'gonna go ahead and continue on. Note the error '
                   'messages though.')
            generic_msg.warning(msg)

        return True
Exemple #6
0
    def vim_setup(self):
        """This does all of our setup to grab all the necessary data.

        Args:
            None.

        Returns:
            bool. True or False.

        """
        pathogen_dirs = ['autoload', 'bundle',
                         'colors', 'plugin']

        vimdir_result = handle_mkdir(self.vim_dir)
        if not vimdir_result['success']:
            generic_msg.error(vimdir_result['msg'])
            self.handle_failure()

        msg = ('Making the following '
               'directories: %s' % (', '.join(pathogen_dirs)))
        generic_msg.info(msg)
        for dirname in pathogen_dirs:
            full_dirname = os.path.join(self.vim_dir, dirname)
            dir_result = handle_mkdir(full_dirname)
            if not dir_result['success']:
                generic_msg.error(dir_result['msg'])
                self.handle_failure()

        plugin_result = self.get_plugins()
        if not plugin_result:
            msg = ('Something really f****d up here. We have to '
                   'kill this now.')
            generic_msg.error(msg)
            self.handle_failure()

        msg = ('We can run some cleanup and try and remove all of the '
               '.rst, .md and .markdown files now if you would like. '
               'Proceed? [y/n]')
        generic_msg.prompt(msg)
        input_result = raw_input().lower()
        if input_result in self.yes_answers:
            cleanup_result = self.handle_cleanup()
            if cleanup_result:
                msg = ('Something during the cleanup process got borked. '
                       'Not a big deal, but you should probably check '
                       'it out.')
                generic_msg.warning(msg)

        return True