From 715e324b292830100eecbee1758bf1be9e4772ff Mon Sep 17 00:00:00 2001 From: Slater-Victoroff Date: Wed, 29 May 2013 10:03:30 -0400 Subject: [PATCH] Updated documentation in doc and README and made some small edits to bash script for added robustness Added documenntation to the docs folder and edited the mac bash script in response to tests --- AUTHORS | 1 + README.md | 5 +- common/djangoapps/search/views.py | 83 +++++++++++++++++++ dist/edX_Apps-0.1-py2.7.egg | Bin 0 -> 5321 bytes scripts/create_mac_dev_env.sh | 127 ++++++++++++++++++++++++++++++ 5 files changed, 214 insertions(+), 2 deletions(-) create mode 100644 common/djangoapps/search/views.py create mode 100644 dist/edX_Apps-0.1-py2.7.egg create mode 100644 scripts/create_mac_dev_env.sh diff --git a/AUTHORS b/AUTHORS index cdfdd4c2fe..ca6e14b252 100644 --- a/AUTHORS +++ b/AUTHORS @@ -72,3 +72,4 @@ Giulio Gratta David Baumgold Jason Bau Frances Botsford +Slater Victoroff diff --git a/README.md b/README.md index ed52c21fb2..41a292b8aa 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,9 @@ Installation The installation process is a bit messy at the moment. Here's a high-level overview of what you should do to get started. -**TLDR:** There is a `scripts/create-dev-env.sh` script that will attempt to set all -of this up for you. If you're in a hurry, run that script. Otherwise, I suggest +**TLDR:** There is a `scripts/create-dev-env.sh` script, `scripts/create_mac_dev_env.sh` +for mac computer, that will attempt to set all of this up for you. +If you're in a hurry, run that script. Otherwise, I suggest that you understand what the script is doing, and why, by reading this document. Directory Hierarchy diff --git a/common/djangoapps/search/views.py b/common/djangoapps/search/views.py new file mode 100644 index 0000000000..f15dc9266b --- /dev/null +++ b/common/djangoapps/search/views.py @@ -0,0 +1,83 @@ +from django.http import HttpResponse +from django.template.loader import get_template +from django.template import Context +from django.contrib.auth.models import User +from django.contrib.staticfiles import finders +from courseware.courses import get_courses +from courseware.model_data import ModelDataCache +from courseware.module_render import get_module_for_descriptor + +from courseware.views import registered_for_course +#import logging +import lxml +import re +import posixpath +import urllib +from os import listdir +from os.path import isfile +from os.path import join + + +def test(request): + user = User.objects.prefetch_related("groups").get(id=request.user.id) + request.user = user + + course_list = get_courses(user, request.META.get('HTTP_HOST')) + + all_modules = [get_module(request, user, course) for course in course_list if registered_for_course(course, user)] + child_modules = [] + for module in all_modules: + child_modules.extend(module.get_children()) + bottom_modules = [] + for module in child_modules: + bottom_modules.extend(module.get_children()) + asset_divs = get_asset_div(convert_to_valid_html(bottom_modules[2].get_html())) + strings = [get_transcript_directory(lxml.html.tostring(div)) for div in asset_divs] + search_template = get_template('search.html') + html = search_template.render(Context({'course_list': strings})) + return HttpResponse(html) + + +def get_children(course): + """Returns the children of a given course""" + attributes = [child.location for child in course._child_instances] + return attributes + + +def convert_to_valid_html(html): + replacement = {"<": "<", ">": ">", """: "\"", "'": "'"} + for i, j in replacement.iteritems(): + html = html.replace(i, j) + return html + + +def get_asset_div(html_page): + return lxml.html.find_class(html_page, "video") + + +def get_module(request, user, course): + model_data_cache = ModelDataCache.cache_for_descriptor_descendents(course.id, user, course, depth=2) + course_module = get_module_for_descriptor(user, request, course, model_data_cache, course.id) + return course_module + + +def get_youtube_code(module_html): + youtube_snippet = re.sub(r'(.*?)(1\.0:)(.*?)(,1\.25)(.*)', r'\3', module_html) + sliced_youtube_code = youtube_snippet[:youtube_snippet.find('\n')] + return sliced_youtube_code + + +def get_transcript_directory(module_html): + directory_snippet = re.sub(r'(.*?)(data-caption-asset-path=\")(.*?)(\">.*)', r'\3', module_html) + sliced_directory = directory_snippet[:directory_snippet.find('\n')] + return resolve_to_absolute_path(sliced_directory) + + +def resolve_to_absolute_path(transcript_directory): + normalized_path = posixpath.normpath(urllib.unquote(transcript_directory)).lstrip('/') + return all_transcript_files(normalized_path) + + +def all_transcript_files(normalized_path): + files = [transcript for transcript in listdir(normalized_path) if isfile(join(normalized_path, transcript))] + return files diff --git a/dist/edX_Apps-0.1-py2.7.egg b/dist/edX_Apps-0.1-py2.7.egg new file mode 100644 index 0000000000000000000000000000000000000000..c82d7837dd818dfcd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?Q=iAU3ocBHMm?3lP-qkc*L+N1DwCLnSd`B?cgyS3p+&)fTgi=u5hni<5c+fqFa z@{dBQO$ZeUn8Q5SchdB=8uH{n&DJ~Psmhm$kb_t?Qol`z*%oi`=XQ{L-|-J0U~_!F zQgthA9n9?eIQ_Q93!6aG$WJ+!^d!p;D7a~n(-T&jJ^3)GRTmr4=EmF+Kt+_l-*5|KXG zC$N1*v)tAT?X>=oq0|nQ$SX;$)-&@_ePM7!{+{t@HF)k|Y~V%GN0%AP$t;S+c40|- zHi7N4jJC}oRHHqOh+zA!rT(fCm@#W0N(#}%>FQEfQ4^iyyH#e0)T|;<8+VYtE3I+} z)KSO7KL`Bxw+!s&@@FXsJpRFX**Go!-OI*bQUIVJP~e|p>(lDrJwTkOk2&?Y>EE5< zr(J$`={<2t!4kp0x%`sMvCV08ItKc`OFCJP{=`c5v=uJv8x2{6FM42z??yrlg-8It|pg7PuIFVv&2=;uKWlI^e?WiGw-zB>S1fFKCPF zae8Eqq4w`m5SV(}<8Q=0E&m~Iu&tRv?@dG6VU/dev/null || { + echo "Installing $pkg" + brew install $pkg + } +done + +# Manually Installing Ruby prereqs +brew install openssl + +# Install Ruby virtual environment +curl -L https://get.rvm.io | bash stable --ruby +source $HOME/.rvm/scripts/rvm +rvm install ruby-1.9.3-p374 +rvm use 1.9.3-p374 +rvm rubygems latest + +gem install bundler +bundle install --gemfile $PLATFORM_REPO/Gemfile + +# Install Python virtual environment +echo "Installing Python virtualenv" +sudo pip install virtualenvwrapper +export VIRTUALENVWRAPPER_PYTHON=$PYTHON_BIN +export VIRTUALENV_DISTRIBUTE=true +source $PYTHON_SHARE/virtualenvwrapper.sh +mkvirtualenv -a edx-platform --system-site-packages edx-platform + +# Install numpy and scipy +NUMPY_VER="1.6.2" +SCIPY_VER="0.10.1" + +echo "Downloading numpy and scipy" +curl -sL -o numpy.tar.gz http://downloads.sourceforge.net/project/numpy/NumPy/${NUMPY_VER}/numpy-${NUMPY_VER}.tar.gz +curl -sL -o scipy.tar.gz http://downloads.sourceforge.net/project/scipy/scipy/${SCIPY_VER}/scipy-${SCIPY_VER}.tar.gz +tar xf numpy.tar.gz +tar xf scipy.tar.gz +rm -f numpy.tar.gz scipy.tar.gz +echo "Compiling numpy" +cd "$BASE/numpy-${NUMPY_VER}" +python setup.py install +echo "Compiling scipy" +cd "$BASE/scipy-${SCIPY_VER}" +python setup.py install +cd "$BASE" +rm -rf numpy-${NUMPY_VER} scipy-${SCIPY_VER} + +# Activate the new Virtualenv for pip fixes +VIRTUALENV=$HOME/.virtualenvs/edx-platform/bin +cd $VIRTUALENV +source activate + +# building correct version of distribute from source +DISTRIBUTE_VER="0.6.28" +echo "Building Distribute" +SITE_PACKAGES=$HOME/.virtualenvs/edx-platform/lib/python2.7/site-packages +cd $SITE_PACKAGES +curl -O http://pypi.python.org/packages/source/d/distribute/distribute-${DISTRIBUTE_VER}.tar.gz +tar -xzvf distribute-${DISTRIBUTE_VER}.tar.gz +cd distribute-${DISTRIBUTE_VER} +python setup.py install +cd .. +rm distribute-${DISTRIBUTE_VER}.tar.gz + +# on mac os x get the latest pip +pip install -U pip +# need latest pytz before compiling numpy and scipy +pip install -U pytz +pip install -U numpy +# scipy needs cython +pip install cython +# fixes problem with scipy on 10.8 +pip install -e git+https://github.com/scipy/scipy#egg=scipy-dev + +# Install prereqs +echo "Installing prereqs" +cd $PLATFORM_REPO +rvm use 1.9.3-p374 +rake install_prereqs + +# Final dependecy +echo "Finishing Touches" +cd $BASE +pip install argcomplete +cd $PLATFORM_REPO +bundle install + +# Make required directories +cd $BASE +mkdir data log db + +# Finished +echo "Success!" \ No newline at end of file