from clint.textui import colored

from distutils.version import StrictVersion
import importlib

packages = {
    "IPython": "4.0",
    "pandas": "0.18",
    "numpy": "1.10",
    "matplotlib": "1.5",
    "seaborn": "0.7",
    "sklearn": "0.17",
    "xgboost": "0.4",
    "ggplot": "0.10"
}

def verify_packages(packages):
    missing_packages = []
    upgrade_packages = []

    for package_name, package_version in packages.items():
        current_version = get_version_package(package_name)
        if False == current_version:
            print(colored.red("{0} - missing".format(package_name)))
            missing_packages.append(package_name)
        else:
            if version_is_good(current_version, package_version):
                print(colored.green("{0}-{1} - OK".format(package_name, current_version)))
            else:
                print(colored.yellow("{0}-{1} should be upgraded to {0}-{2}".format(package_name, current_version, package_version)))
                upgrade_packages.append(package_name)

    return missing_packages, upgrade_packages

def get_version_package(package_name):
    try:
        return importlib.import_module(package_name).__version__
    except ImportError:
        return False

def version_is_good(actual_version, expected_version):
    return StrictVersion(actual_version) >= StrictVersion(expected_version)

if __name__ == '__main__':
    missing_packages, upgrade_packages = verify_packages(packages)


    if not missing_packages and not upgrade_packages:
        print("")
        print(colored.green("=" * 50))
        print(colored.green("All right, you are ready to go on Data Workshop!"))

    if missing_packages:
        print("")
        print(colored.red("=" * 50))
        print(colored.red("REQUIRED"))
        print(colored.red("Please install those packages before Data Workshop: " + ", ".join(missing_packages)))
        print(colored.blue("pip install {0}".format( " ".join(missing_packages) )))
        if 'xgboost' in missing_packages:
            print(colored.red("More info how to install xgboost: ") + colored.blue("http://xgboost.readthedocs.org/en/latest/build.html"))


    if upgrade_packages:
        print("")
        print(colored.yellow("=" * 50))
        print(colored.yellow("RECOMENDATION (without upgrade some needed features could be missing)"))
        print(colored.blue("pip install --upgrade {0}".format( " ".join(upgrade_packages) )))

@@ -120,24 +120,51 @@
 on%22: %224.0%22,%0A
+    %22ipywidgets%22: %224.1.1%22,%0A
     %22pandas%22
@@ -173,16 +173,16 @@
 %220.18%22,%0A
-
     %22num
@@ -306,16 +306,237 @@
 : %220.10%22
+,%0A    %22ml_metrics%22: %220.1.4%22,%0A%7D%0A%0Aadditional_visual_packages = %7B%0A    %22gmplot%22: %221.1.1%22,%0A    %22geoplotlib%22: %220.3.2%22,%0A    %22folium%22: %220.2.1%22,%0A    %22vincent%22: %220.4.4%22,%0A    %22geopandas%22: %220.2.1%22,%0A    %22mpl_toolkits.basemap%22: %221.0.7%22
 %0A%7D%0A%0Adef 
@@ -726,32 +726,33 @@
 e(package_name)%0A
+%0A
         if False
@@ -891,16 +891,145 @@
 e_name)%0A
+        elif current_version is None:%0A            handle_package_without_version(current_version, package_version, package_name)%0A
         
@@ -1445,16 +1445,349 @@
 ckages%0A%0A
+def handle_package_without_version(current_version, package_version, package_name):%0A    if current_version != package_version:%0A        print(colored.yellow(%22%7B0%7D exists, but has no attribute version. Expected versin %7B1%7D%22.format(package_name, package_version)))%0A    else:%0A        print(colored.green(%22%7B0%7D - OK%22.format(package_name)))%0A%0A
 def get_
@@ -1935,16 +1935,63 @@
 rn False
+%0A    except AttributeError:%0A        return None
 %0A%0Adef ve
@@ -2143,16 +2143,16 @@
 ain__':%0A
+
     miss
@@ -2211,17 +2211,16 @@
 kages)%0A%0A
-%0A
     if n

add extra visual libraries