Semi-automatically generate scripts out of our tutorials

Summary:
The idea is the following. We are going to automatically generate .py files using a jupyter post-save hook. Also, there is a script to generate these for all the tutorials. The script is also used from Jenkins test.sh. So if you don't run the sync anyhow, test will complain.

In this diff I include the framework itself + .py files generated for all tutorials. They live under a separate folder.
Closes https://github.com/caffe2/caffe2/pull/1762

Differential Revision: D6749358

Pulled By: salexspb

fbshipit-source-id: d6ad28e863a0670af2d1e5af86e16909dc0dcf2c
diff --git a/.jenkins/test.sh b/.jenkins/test.sh
index 608fbc0..8c201a0 100755
--- a/.jenkins/test.sh
+++ b/.jenkins/test.sh
@@ -14,6 +14,22 @@
 export PYTHONPATH="${PYTHONPATH}:/usr/local/caffe2"
 export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/usr/local/caffe2/lib"
 
+exit_code=0
+
+cd "$ROOT_DIR"/caffe2/python/tutorials
+python tutorials_to_script_converter.py
+git status
+if git diff --quiet HEAD; then
+  echo "Source tree is clean."
+else
+  echo "After running a tutorial -> script sync there are changes. This probably means you edited an ipython notebook without a proper sync to a script. Please see caffe2/python/tutorials/README.md for more information"
+  if [ "$exit_code" -eq 0 ]; then
+    exit_code=1
+  fi
+fi
+
+cd "$ROOT_DIR"
+
 if [ -d ./test ]; then
   echo "Directory ./test already exists; please remove it..."
   exit 1
@@ -22,11 +38,11 @@
 mkdir -p ./test/{cpp,python}
 TEST_DIR="$PWD/test"
 
+
 cd /usr/local/caffe2
 
 # Commands below may exit with non-zero status
 set +e
-exit_code=0
 
 # C++ tests
 echo "Running C++ tests.."