Commit c87e4696 by Slater-Victoroff

files cleaned up and debugging nearing the final steps

parent 56433729
......@@ -8,8 +8,7 @@ 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, `scripts/create_mac_dev_env.sh`
for mac computer, that will attempt to set all of this up for you.
**TLDR:** There is a `scripts/create-dev-env.sh` 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.
......
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 = {"&lt;": "<", "&gt;": ">", "&#34;": "\"", "&#39;": "'"}
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
......@@ -236,7 +236,7 @@ case `uname -s` in
Raring requires an install of rvm to work correctly as the raring
package manager does not yet include a package for rvm
Press return to continue or control-C to abort"
read dummy
sudo apt-get install git
......@@ -412,14 +412,14 @@ fi
# Create edX virtualenv and link it to repo
# virtualenvwrapper automatically sources the activation script
if [[ $systempkgs ]]; then
mkvirtualenv -a "$BASE/edx-platform" --system-site-packages edx-platform || {
mkvirtualenv -a "$HOME/.virtualenvs" --system-site-packages edx-platform || {
error "mkvirtualenv exited with a non-zero error"
return 1
}
else
# default behavior for virtualenv>1.7 is
# --no-site-packages
mkvirtualenv -a "$BASE/edx-platform" edx-platform || {
mkvirtualenv -a "$HOME/.virtualenvs" edx-platform || {
error "mkvirtualenv exited with a non-zero error"
return 1
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment