Skip to content

Commit

Permalink
Merged in f3-update (pull request #1)
Browse files Browse the repository at this point in the history
Updated templates and sass
  • Loading branch information
0atman committed Aug 29, 2014
2 parents 73272dc + e3db3ad commit b341603
Show file tree
Hide file tree
Showing 3,077 changed files with 23,904 additions and 45,698 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
9 changes: 7 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
*.pyc
templates/static/css/styles.css
*.bak
*.tmp
*.css.map
.sass-cache
.~1~
*.~*~
env/
static/css/styles.css
static/css/core-print.css
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# A sample Gemfile
source "https://rubygems.org"

# gem "rails"
gem 'sass'
156 changes: 156 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
SHELL := /bin/bash # Use bash syntax

define HELP_TEXT
Canonical.com website project
===

Usage:

> make setup # Install dependencies
> make develop # Auto-compile sass files and run the dev server

endef

# Variables
##

ENVPATH=${VIRTUAL_ENV}
VEX=vex --path ${ENVPATH}
ifeq ($(ENVPATH),)
ENVPATH=env
endif

##
# Print help text
##
help:
$(info ${HELP_TEXT})

##
# Start the development server
##
develop: sass-watch dev-server

##
# Prepare the project
##
setup: install-dependencies update-env

##
# Run server
##
dev-server:
${VEX} ./manage.py runserver_plus 0.0.0.0:8000

##
# Run SASS watcher
##
sass-watch:
sass --debug-info --watch static/css/styles.scss &
sass --debug-info --watch static/css/core-print.scss &

##
# Build SASS
##
sass-build:
sass --style compressed --update static/css/styles.scss
sass --style compressed --update static/css/core-print.scss

##
# Get virtualenv ready
##
update-env:
${MAKE} create-env

${VEX} ${MAKE} install-requirements

# Get download mirrors file
wget --output-document=/tmp/mirrors.rss https://launchpad.net/ubuntu/+cdmirrors-rss

##
# Make virtualenv directory if it doesn't exist and we're not in an env
##
create-env:
if [ ! -d ${ENVPATH} ]; then virtualenv ${ENVPATH}; fi

##
# Install pip requirements
# Only if inside a virtualenv
##
install-requirements:
if [ "${VIRTUAL_ENV}" ]; then pip install -r requirements/dev.txt; fi

##
# Install required system dependencies
##
install-dependencies:
if [ $$(command -v apt-get) ]; then ${MAKE} apt-dependencies; fi
if [ $$(command -v brew) ]; then ${MAKE} brew-dependencies; fi

if [ ! $$(command -v virtualenv) ]; then sudo pip install virtualenv; fi
if [ ! $$(command -v vex) ]; then sudo pip install vex; fi

## Install dependencies with apt
apt-dependencies:
if [ ! $$(command -v pip) ]; then sudo apt-get install python-pip; fi
if [ ! $$(command -v sass) ]; then sudo apt-get install ruby-sass; fi

## Install dependencies with brew
brew-dependencies:
if [ ! $$(command -v pip) ]; then sudo easy_install pip; fi
if [ ! $$(command -v sass) ]; then sudo gem install sass; fi

update-templates:
rm -rf templates
rm -rf static
bzr branch lp:ubuntu-website-content templates
rm -rf templates/.bzr*

mv templates/static .

# Template replacements
# ==
find templates -type f -name '*.html' | xargs sed -i '/^ *[{][%] load scss [%][}] *$$/d' # Remove references to scss module
find templates -type f -name '*.html' | xargs sed -i 's/[{][%]\s*scss\s\+["]\([^"]\+\).scss["]\s*[%][}]/\1.css/g' # Point to CSS instead of SCSS
find templates -type f -name '*.html' | xargs sed -i 's/[{][{] *STATIC_URL *[}][}]u[/]/{{ STATIC_URL }}/g' # Fix static file locations
find templates -type f -name '*.html' | xargs sed -i 's/[{][%] *\(extends\|include\|with\) \+["]ubuntu[/]/{% \1 "/g' # Remove "ubuntu" from include paths

# Stylesheet replacements
# ==
find static/css -type f -name '*.scss' | xargs sed -i 's/[%][%]/%/g' # Remove erroneous double-percent
find static/css -type f -name '*.scss' | xargs sed -i 's/[@]import ["]css[/]/@import "/g' # Fix include paths for sass

update-templates-local:
rm -rf templates
rm -rf static
#bzr branch lp:ubuntu-website-content templates
bzr pull --directory ../ubuntu-website-content
cp -rf ../ubuntu-website-content templates
rm -rf templates/.bzr*

mv templates/static .

# Template replacements
# ==
find templates -type f -name '*.html' | xargs sed -i '/^ *[{][%] load scss [%][}] *$$/d' # Remove references to scss module
find templates -type f -name '*.html' | xargs sed -i 's/[{][%]\s*scss\s\+["]\([^"]\+\).scss["]\s*[%][}]/\1.css/g' # Point to CSS instead of SCSS
find templates -type f -name '*.html' | xargs sed -i 's/[{][{] *STATIC_URL *[}][}]u[/]/{{ STATIC_URL }}/g' # Fix static file locations
find templates -type f -name '*.html' | xargs sed -i 's/[{][%] *\(extends\|include\|with\) \+["]ubuntu[/]/{% \1 "/g' # Remove "ubuntu" from include paths

# Stylesheet replacements
# ==
find static/css -type f -name '*.scss' | xargs sed -i 's/[%][%]/%/g' # Remove erroneous double-percent
find static/css -type f -name '*.scss' | xargs sed -i 's/[@]import ["]css[/]/@import "/g' # Fix include paths for sass

clean:
rm -rf env static/css/styles.css static/css/core-print.css

# The below targets
# are just there to allow you to type "make it so"
# as a replacement for "make" or "make develop"
# - Thanks to https://directory.canonical.com/list/ircnick/deadlight/

it:
# Nothing

so: develop
30 changes: 17 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
Run site
Ubuntu.com website project
===

To run the site locally:

``` bash
sass --watch --debug-info templates/static/css/styles.scss &
./manage runserver
make setup # Install dependencies - only needed the first time
make develop # Auto-compile sass files and run the dev server
```

Updating templates to work with this project
===
Now visit <http://127.0.0.1:8000>

``` bash
perl -pi -e 's/\{\{ STATIC_URL \}\}u\//{{ STATIC_URL }}/g' `find .`
perl -pi -e 's/\{\% (extends|include) "ubuntu\//{% $1 "/g' `find .`
```
Fenchurch
---

Updating sass files to compile correctly
===
This site depends on [Fenchurch 3](https://launchpad.net/fenchurch/3.0.0) - which is currently a private repository. Make sure you have SSH access to the above repository before attempting to install dependencies.

Updating templates from [ubuntu-website-content](https://launchpad.net/ubuntu-website-content)
---

Until this project is released, new template work will be being added to the [ubuntu-website-content](https://launchpad.net/ubuntu-website-content) project.

To update the templates directory with the template changes from this repository:

``` bash
perl -pi -e 's/\@import \"css\//\@import \"/g' `find . -name '*.scss'`
make update-templates
```
=======
File renamed without changes.
File renamed without changes.
120 changes: 120 additions & 0 deletions lib/gsa.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import requests


class GSAParser:
"""
Query the Google Search Appliance
for results in JSON format
and fix the results in various ways
before returning them as a data object
Usage:
search_parser = GSAParser(domain="gsa.example.com")
results = search_parser.fixed_results(query="hello world")
"""

domain = ""
client = ""
default_collection = ""
stylesheet = ""

def __init__(
self, domain,
client="default_frontend",
site_collection="default_collection",
stylesheet="json_frontend"
):
self.domain = domain
self.client = client
self.site_collection = site_collection
self.stylesheet = stylesheet

def fixed_results(self, query, start=0, num=10):
"""
Return a data object of results from the GSA,
fixed to show the correct total and avoid errors:
{
"query": <GSA's generated query>,
"results": [
{
"url": ..,
"title": ..,
"summary": ..,
"meta_tags" : [..],
"size": ..
}, ..
],
"results_nav": {
"total_results": <total - fixed to be accurate>,
"results_start": ..,
"results_end": ..,
"current_view": ..,
"have_prev": "1", # may exist
"have_next": "1", # may exist
}
}
"""

results_data = self.results(query, start, num)
results_data["results_nav"]["total_results"] = self.total_results(query)

return results_data

def total_results(self, query):
"""
Inexplicably, the GSA returns a completely incorrect total
This is a hack to get the correct total.
If you request with start>1000, the GSA returns nothing.
But if you request with start = 990, it returns the last page
even if there are only 10 results.
Therefore this is the way to get the real total
"""

last_results = self.results(query, start=990, num=10)

return last_results["results_nav"]["results_end"]

def results(self, query, start, num):
"""
GSA often returns invalid JSON - attempt to fix it
"""

results_json = self.results_json(query, start, num)

return results_json

def results_json(self, query, start, num):
"""
Query the GSA to get response in JSON format
and return it
Throws a URLError exception if it fails to
communicate with the GSA
"""

# Query mustn't have spaces - or BREAKZ!
query = query.replace(' ', '+')

# Build the GSA URL
search_url_template = (
'http://{domain}/search'
'?q={q}&num={num}&start={start}&client={client}'
'&site={site}&output=xml_no_dtd'
'&proxystylesheet={stylesheet}'
)
search_url = search_url_template.format(
domain=self.domain,
q=query,
num=str(num),
start=str(start),
client=self.client,
site=self.site_collection,
stylesheet=self.stylesheet
)

response = requests.get(search_url)

return response.json()
2 changes: 0 additions & 2 deletions requirements.txt

This file was deleted.

3 changes: 3 additions & 0 deletions requirements/base.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Django==1.6.2
feedparser==5.1.3
requests==2.3.0
4 changes: 4 additions & 0 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-r standard.txt
django-extensions
werkzeug
ipdb
2 changes: 2 additions & 0 deletions requirements/standard.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-r base.txt
-e bzr+ssh://bazaar.launchpad.net/+branch/fenchurch/3.0.0/#egg=fenchurch
Loading

0 comments on commit b341603

Please sign in to comment.