Repository: conda/conda

Issue:
conda clean --json error
`conda clean -t --json --dry-run
{
  "error": "Traceback (most recent call last):\n  File \"C:\\Anaconda27\\lib\\site-packages\\conda\\exceptions.py\", line 632, in conda_exception_handler\n    return_value = func(*args, **kwargs)\n  File \"C:\\Anaconda27\\lib\\site-packages\\conda\\cli\\main.py\", line 137, in _main\n    exit_code = args.func(args, p)\n  File \"C:\\Anaconda27\\lib\\site-packages\\conda\\cli\\main_clean.py\", line 306, in execute\n    rm_tarballs(args, pkgs_dirs, totalsize, verbose=not context.json)\n  File \"C:\\Anaconda27\\lib\\site-packages\\conda\\cli\\main_clean.py\", line 123, in rm_tarballs\n    if not context.json or not context.yes:\nAttributeError: 'Context' object has no attribute 'yes'\n"
}

conda info --all
Current conda install:

               platform : win-64
          conda version : 4.3.21
       conda is private : False
      conda-env version : 4.3.21
    conda-build version : 2.1.15
         python version : 2.7.13.final.0
       requests version : 2.12.4
       root environment : C:\Anaconda27  (writable)
    default environment : C:\Anaconda27
       envs directories : C:\Anaconda27\envs
                          C:\Users\Oammous\AppData\Local\conda\conda\envs
                          C:\Users\Oammous\.conda\envs
          package cache : C:\Anaconda27\pkgs
                          C:\Users\Oammous\AppData\Local\conda\conda\pkgs
           channel URLs : http://conda/prod/win-64
                          http://conda/prod/noarch
                          https://repo.continuum.io/pkgs/free/win-64
                          https://repo.continuum.io/pkgs/free/noarch
                          https://repo.continuum.io/pkgs/r/win-64
                          https://repo.continuum.io/pkgs/r/noarch
                          https://repo.continuum.io/pkgs/pro/win-64
                          https://repo.continuum.io/pkgs/pro/noarch
                          https://repo.continuum.io/pkgs/msys2/win-64
                          https://repo.continuum.io/pkgs/msys2/noarch
                          https://conda.anaconda.org/conda-forge/win-64
                          https://conda.anaconda.org/conda-forge/noarch
            config file : C:\Users\Oammous\.condarc
             netrc file : None
           offline mode : False
             user-agent : conda/4.3.21 requests/2.12.4 CPython/2.7.13 Windows/10 Windows/10.0.10586
          administrator : False
# conda environments:
#
_test                    C:\Anaconda27\envs\_test
gulbis                   C:\Anaconda27\envs\gulbis
py3                      C:\Anaconda27\envs\py3
root                  *  C:\Anaconda27

sys.version: 2.7.13 |Anaconda custom (64-bit)| (defau...
sys.prefix: C:\Anaconda27
sys.executable: C:\Anaconda27\python.exe
conda location: C:\Anaconda27\lib\site-packages\conda
conda-build: C:\Anaconda27\Scripts\conda-build.exe
conda-convert: C:\Anaconda27\Scripts\conda-convert.exe
conda-develop: C:\Anaconda27\Scripts\conda-develop.exe
conda-env: C:\Anaconda27\Scripts\conda-env.exe
conda-index: C:\Anaconda27\Scripts\conda-index.exe
conda-inspect: C:\Anaconda27\Scripts\conda-inspect.exe
conda-metapackage: C:\Anaconda27\Scripts\conda-metapackage.exe
conda-render: C:\Anaconda27\Scripts\conda-render.exe
conda-server: C:\Anaconda27\Scripts\conda-server.exe
conda-sign: C:\Anaconda27\Scripts\conda-sign.exe
conda-skeleton: C:\Anaconda27\Scripts\conda-skeleton.exe
conda-verify: C:\Anaconda27\Scripts\conda-verify.exe
`


Discussion:

Resolving patch:
diff --git a/conda/cli/main_clean.py b/conda/cli/main_clean.py
--- a/conda/cli/main_clean.py
+++ b/conda/cli/main_clean.py
@@ -120,7 +120,7 @@ def rm_tarballs(args, pkgs_dirs, totalsize, verbose=True):
         print(fmt % ('Total:', human_bytes(totalsize)))
         print()
 
-    if not context.json or not context.yes:
+    if not context.json or not context.always_yes:
         confirm_yn(args)
     if context.json and args.dry_run:
         return
@@ -218,7 +218,7 @@ def rm_pkgs(args, pkgs_dirs, warnings, totalsize, pkgsizes,
         print(fmt % ('Total:', human_bytes(totalsize)))
         print()
 
-    if not context.json or not context.yes:
+    if not context.json or not context.always_yes:
         confirm_yn(args)
     if context.json and args.dry_run:
         return
@@ -279,7 +279,7 @@ def rm_source_cache(args, cache_dirs, warnings, cache_sizes, total_size):
 
     print("%-40s %10s" % ("Total:", human_bytes(total_size)))
 
-    if not context.json or not context.yes:
+    if not context.json or not context.always_yes:
         confirm_yn(args)
     if context.json and args.dry_run:
         return


Test patch:
diff --git a/tests/test_create.py b/tests/test_create.py
--- a/tests/test_create.py
+++ b/tests/test_create.py
@@ -1072,8 +1072,11 @@ def test_clean_tarballs_and_packages(self):
                 assert any(basename(d).startswith('flask-') for d in pkgs_dir_dirs)
                 assert any(basename(f).startswith('flask-') for f in pkgs_dir_tarballs)
 
-                run_command(Commands.CLEAN, prefix, "--packages --yes")
-                run_command(Commands.CLEAN, prefix, "--tarballs --yes")
+                # --json flag is regression test for #5451
+                run_command(Commands.CLEAN, prefix, "--packages --yes --json")
+
+                # --json flag is regression test for #5451
+                run_command(Commands.CLEAN, prefix, "--tarballs --yes --json")
 
                 pkgs_dir_contents = [join(pkgs_dir, d) for d in os.listdir(pkgs_dir)]
                 pkgs_dir_dirs = [d for d in pkgs_dir_contents if isdir(d)]
@@ -1102,7 +1105,8 @@ def test_clean_source_cache(self):
 
         assert all(isdir(d) for d in itervalues(cache_dirs))
 
-        run_command(Commands.CLEAN, '', "--source-cache --yes")
+        # --json flag is regression test for #5451
+        run_command(Commands.CLEAN, '', "--source-cache --yes  --json")
 
         assert not all(isdir(d) for d in itervalues(cache_dirs))