Example #1
0
    def backup_vimdir(self):
        """Backs up the .vim directory

        Args:
            None.

        Returns:
            bool. True or False

        """
        msg = ('Backing up your vim directory...')
        generic_msg.info(msg)
        self.backup_directory = os.path.join(self.home_dir, '.vim_backup')
        if os.path.exists(self.backup_directory):
            msg = ('It appears that the directory already exists. Would you '
                   'like to backup the older directory with the current '
                   'datetime appended to it? [y/n]')
            generic_msg.prompt(msg)
            input_result = raw_input().lower()
            if input_result in self.yes_answers:
                cur_date = datetime.now().strftime('%Y_%M_%d_%H_%M_%S')
                self.backup_directory = os.path.join(
                    self.home_dir, '.vim_backup_%s' % (cur_date)
                )
            else:
                msg = ('User cancelled vim setup.')
                generic_msg.info(msg)
                sys.exit(1)

        result = handle_moving_dirs(self.vim_dir, self.backup_directory)
        return result
Example #2
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)
Example #3
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)
Example #4
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
Example #5
0
def handle_mkdir(dir_name):
    """Handles making directories so we don't replicate code.

    Args:
        dir_name (str): The directory to create.

    Returns:
        dict. Failure or Success and the output message.
            {'success': True,
            'msg': 'Success message'}
            {'success': False,
            'msg': 'Failure message'}

    """
    out_data = {
        'success': True,
        'msg': 'Successfully created directory: %s' % (dir_name)
    }
    if os.path.exists(dir_name):
        msg = ('Directory %s exists. Attempting to '
               'remove it.' % (dir_name))
        generic_msg.info(msg)
        rmdir_result = handle_rmdir(dir_name)
        if not rmdir_result:
            msg = ('Was not able to delete it. Will continue on '
                   'hoping for the best. :)')
            generic_msg.warning(msg)
            return out_data
    try:
        os.mkdir(dir_name)
    except OSError as err:
        out_data['msg'] = ('Failed to create directory: %s. '
                           'Error: %s' % (dir_name, err))
        out_data['success'] = False

    return out_data