# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function

import sys

import click

from polyaxon_cli.client import PolyaxonClient
from polyaxon_cli.client.exceptions import (
    PolyaxonClientException,
    PolyaxonHTTPError,
    PolyaxonShouldExitError
)
from polyaxon_cli.logger import clean_outputs
from polyaxon_cli.managers.ignore import IgnoreManager
from polyaxon_cli.managers.project import ProjectManager
from polyaxon_cli.utils.files import create_tarfile, get_files_in_current_directory
from polyaxon_cli.utils.formatting import Printer


@click.command()
@clean_outputs
def upload(sync=True):  # pylint:disable=assign-to-new-keyword
    """Upload code of the current directory while respecting the .polyaxonignore file."""
    project = ProjectManager.get_config_or_raise()
    files = IgnoreManager.get_unignored_file_paths()
    try:
        with create_tarfile(files, project.name) as file_path:
            with get_files_in_current_directory('repo', [file_path]) as (files, files_size):
                try:
                    PolyaxonClient().project.upload_repo(project.user,
                                                         project.name,
                                                         files,
                                                         files_size,
                                                         sync=sync)
                except (PolyaxonHTTPError, PolyaxonShouldExitError, PolyaxonClientException) as e:
                    Printer.print_error(
                        'Could not upload code for project `{}`.'.format(project.name))
                    Printer.print_error('Error message `{}`.'.format(e))
                    Printer.print_error('Check if you have access rights for this project and '
                                        'that you are not uploading large files.'
                                        'If you are running a notebook, '
                                        'you should stop it before uploading.')
                    sys.exit(1)
                Printer.print_success('Files uploaded.')
    except Exception as e:
        Printer.print_error("Could not upload the file.", add_sign=True)
        Printer.print_error('Error message `{}`.'.format(e))
        sys.exit(1)

@@ -1740,49 +1740,43 @@
 ror(
-'Check if you have access rights for this
+%0A                        'Check the
  pro
@@ -1780,19 +1780,23 @@
 project 
-and
+exists,
  '%0A     
@@ -1818,41 +1818,99 @@
     
-                'that you are not
+'and that you have access rights, '%0A                        'this could happen as well when
  upl
@@ -1954,32 +1954,16 @@
         
-                
 'If you 
@@ -1984,36 +1984,58 @@
 notebook
-, '%0A                
+ and mounting the code to the notebook, '%0A
         

Update list of possible errors when uploading code