Djangoappengine – setting up
Objective:
Set up djangoappengine.
Steps:
1. Download appengine from http://code.google.com/appengine/downloads.html. (I am using Google App Engine SDK for Python – Linux/Other Platforms)
2. Download djangoappengine http://www.allbuttonspressed.com/projects/djangoappengine. The instructions on how to install are on the same page.
3. From the djangoappengine page.
Copy the following folders into your project (e.g., django-testapp):
* django-nonrel/django => /django
* djangotoolbox/djangotoolbox => /djangotoolbox
* django-autoload/autoload => /autoload
* django-dbindexer/dbindexer => /dbindexer
* djangoappengine => /djangoappengineThat’s it. Your project structure should look like this:
* /django
* /djangotoolbox
* /autoload
* /dbindexer
* /djangoappengine
Copy the folders from the zipped files into you django-testapp folder so that you have the same project structure as above. (In my case project was simply the django-testapp folder).
4. Within django-testapp folder run
user@computer:~$ cd /home/user/google_appengine/django-testapp user@computer:~/google_appengine/django-testapp$python2.5 manage.py runserver 127.0.0.1:8021 The Google App Engine SDK could not be found! Make sure it's accessible via your PATH environment and called google_appengine.
5. I needed to add google_appengine to where djangoappengine would find it.
From what I could tell, djangoappengine looks for google_appengine in various folders one of them being /usr/local/google_appengine. So I simply created a symbolic link to that folder. I had installed google_appengine in /home/user/google_appengine. So as root I created a symbolic link.
root@computer:~# ln -s /home/user/google_appengine /usr/local/google_appengine
6. Within django-testapp folder run
user@computer:~/google_appengine/django-testapp$python2.5 manage.py runserver 127.0.0.1:8021 WARNING:root:No ssl package found. urlfetch will not be able to validate SSL certificates. WARNING:root:Could not read datastore data from /home/user/google_appengine/django-testapp/.gaedata/datastore INFO:google.appengine.tools.appengine_rpc:Server: appengine.google.com WARNING:root:Could not read datastore data from /home/user/google_appengine/django-testapp/.gaedata/datastore INFO:root:Connecting to SQLite database '' with file '/home/user/google_appengine/django-testapp/.gaedata/rdbms' INFO:root:Running application ctst on port 8021: http://127.0.0.1:8021
NB. I am ignoring the warnings for now. I will post again once I figure out how to sort them out.
7. Open a browser and go to http://127.0.0.1:8021/.
If you get the above screen shot then you are good to go.
Update (15th September 2011):
1. The data store warning should go once you add data to your datastore.
2. For the follwing warning
WARNING:root:You are using the default Django version (0.96). The default
Django version will change in an App Engine release in the near future.
Please call use_library() to explicitly select a Django version. For more
information see
http://code.google.com/appengine/docs/python/tools/libraries.html#Django
Add to main.py as per app.yaml. In my case it is
– url: /.*
script: djangoappengine/main/main.py
os.environ[‘DJANGO_SETTINGS_MODULE’] = ‘settings’
from google.appengine.dist import use_library
use_library(‘django’, ‘1.2’)
But when I do that I get this error
UnacceptableVersionError: django 1.2 was requested, but 1.3.0.final.0 is already in use
When I set it to use_library(‘django’, ‘1.3’) I get
ValueError: 1.3 is not a supported version for django; supported versions are [‘0.96’, ‘1.0’, ‘1.1’, ‘1.2’]
So I am ignoring the warning and not adding use_library to my main.py.
bash – working with spaces
Problem:
Have bash ignore the spaces between words when looping through a file.
Eg
shell> cat model_country.txt Toyota / Japan Subaru / Japan Audi / Germany
shell>for list in $(cat model_country.txt);do echo $list; done Toyota / Japan Subaru / Japan Audi / Germany
Solution:
1. Change IFS
shell>export IFS=$'\n' shell>for list in $(cat model_country.txt);do echo $list; done Toyota / Japan Subaru / Japan Audi / Germany
Source:
http://blog.ynema.com/?p=260
NB. No need to change IFS back to ‘ \t\n’ as changes made in the example above are lost once the terminal is closed.
2. Use read
shell>cat model_country.txt | while read list; do echo $list; done Toyota / Japan Subaru / Japan Audi / Germany
Source:
http://sandrylogan.wordpress.com/2011/06/10/line-by-line-in-bash-coping-with-the-spaces/
sed – substituting certain text
Problem:
Substitute text in a file only for lines that contain a certain word.
Solution:
# substitute “foo” with “bar” ONLY for lines which contain “baz”
sed ‘/baz/s/foo/bar/g’
Source:
http://www.eng.cam.ac.uk/help/tpl/unix/sed.html
How I used it.
From
Date | Total |
2011-08-01 | 15,355 |
2011-08-02 | 16,799 |
2011-08-03 | 26,521 |
2011-08-04 | 41,876 |
2011-08-05 | 12,690 |
2011-08-06 | 19,489 |
The raw html. Saved as Aug2011_totals.html
<table> <tr style="background-color:black;font-family:sans-serif;color:white;font-weight:bold;"><td>Date</td><td>Total</td></tr> <tr style="background-color:#85c6ef;font-family:sans-serif;text-align:right;"><td style="font-weight:bold;">2011-08-01</td><td>15,355</td></tr> <tr style="background-color:#d0e3ef;font-family:sans-serif;text-align:right;"><td style="font-weight:bold;">2011-08-02</td><td>16,799</td></tr> <tr style="background-color:#85c6ef;font-family:sans-serif;text-align:right;"><td style="font-weight:bold;">2011-08-03</td><td>26,521</td></tr> <tr style="background-color:#d0e3ef;font-family:sans-serif;text-align:right;"><td style="font-weight:bold;">2011-08-04</td><td>41,876</td></tr> <tr style="background-color:#85c6ef;font-family:sans-serif;text-align:right;"><td style="font-weight:bold;">2011-08-05</td><td>12,690</td></tr> <tr style="background-color:#d0e3ef;font-family:sans-serif;text-align:right;"><td style="font-weight:bold;">2011-08-06</td><td>19,489</td></tr> </table>
To
Date | Total |
2011-08-01 | 15,355 |
2011-08-02 | 16,799 |
2011-08-03 | 26,521 |
2011-08-04 | 41,876 |
2011-08-05 | 12,690 |
2011-08-06 | 19,489 |
The raw html
<table> <tr style="background-color:black;font-family:sans-serif;color:white;font-weight:bold;"><td>Date</td><td>Total</td></tr> <tr style="background-color:#85c6ef;font-family:sans-serif;text-align:right;"><td style="font-weight:bold;">2011-08-01</td><td>15,355</td></tr> <tr style="background-color:#f60516;font-family:sans-serif;text-align:right;"><td style="font-weight:bold;">2011-08-02</td><td>16,799</td></tr> <tr style="background-color:#f60516;font-family:sans-serif;text-align:right;"><td style="font-weight:bold;">2011-08-03</td><td>26,521</td></tr> <tr style="background-color:#d0e3ef;font-family:sans-serif;text-align:right;"><td style="font-weight:bold;">2011-08-04</td><td>41,876</td></tr> <tr style="background-color:#85c6ef;font-family:sans-serif;text-align:right;"><td style="font-weight:bold;">2011-08-05</td><td>12,690</td></tr> <tr style="background-color:#d0e3ef;font-family:sans-serif;text-align:right;"><td style="font-weight:bold;">2011-08-06</td><td>19,489</td></tr> </table>
The dates to be highlighted in red may change and to prevent someone from “breaking” something when editing the raw html, it was decided to put the dates in a text file then use sed to make the change to the html file.
shell> less highlighted_dates.txt 2011-08-03 2011-08-02
To do the hightlighting based on the dates in the file. I used sed and bash. This can be then saved as a bash script.
shell> for date_ in $(cat highlighted_dates.txt); do sed -e "/$date_/s/\#85c6ef/\#f60516/" -e "/$date_/s/\#d0e3ef/\#f60516/" Aug2011_totals.html > Aug2011_totals.html.tmp && mv Aug2011_totals.html.tmp Aug2011_totals.html; done