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 0000000000..c82d7837dd Binary files /dev/null and b/dist/edX_Apps-0.1-py2.7.egg differ diff --git a/scripts/create_mac_dev_env.sh b/scripts/create_mac_dev_env.sh new file mode 100644 index 0000000000..2e60b6d7a4 --- /dev/null +++ b/scripts/create_mac_dev_env.sh @@ -0,0 +1,127 @@ +#!/usr/bin/env bash + +BASE=$HOME/edx_all +PLATFORM_REPO=$BASE/edx-platform +PYTHON_BIN=/usr/local/bin/python +PYTHON_SHARE=/usr/local/share/python + +#Add python directory to $PATH for this session +$PATH=$PYTHON_SHARE:$PATH + +# Create a directory to store everything +echo "Creating $BASE directory" +mkdir -p $BASE + +# Install HomeBrew +echo "Installing HomeBrew" +ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)" + +#Install git +echo "Installing Git Version Control" +brew install git + +# Clone the edx-platform repository +echo "Cloning edx-platform repo" +cd $BASE +git clone https://github.com/edx/edx-platform.git + +#Set git push defaults to upstream rather than master +echo "Changing git defaults" +git config --global push.default upstream + +# Install system prereqs +echo "Installing Mac OS X prereqs" +BREW_FILE=$PLATFORM_REPO/requirements/system/mac_os_x/brew-formulas.txt +for pkg in $(cat $BREW_FILE); do + grep $pkg <(brew list) &>/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