summaryrefslogtreecommitdiffstats
path: root/native_client_sdk/src/doc/cds2014/python.rst
blob: be988da68cac488796dc0ae1c6190df71b7e96fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
.. _cds2014_python:

########################################
What a Difference Python Makes - Codelab
########################################

Introduction
------------

.. include:: python_summary.inc

.. include:: ../nacldev/setup_web.inc


Get the Code!
-------------

Rather than start from nothing, for this codelab we've provided
you with a zip file containing a starting point.

Download the codelab::

  geturl https://nacltools.storage.googleapis.com/cds2014/cds2014_python.zip cds2014_python.zip

Unzip it::

  unzip cds2014_python.zip

Go into the codelab directory::

  cd cds2014_python

Create a new local git repo::

  git init

Add everything::

  git add .

Commit it::

  git commit -am "initial"

While working, you can see what you've changed by running::

  git diff


Your challenge, should you choose to accept it...
-------------------------------------------------

Javascript has many wonderful features out of the box.
Unfortunately, generating textual diffs is not one of them.
Python on the other hand has the |difflib| module in its standard library.

The starting point you've just extracted contains the shell
of a web app using Portable Native Client Python to generate a diff.
Just one thing is missing, that whole diffing thing...

To see where things stand, deploy the sample like this::

  make

This will attempt to open the sample, but will be blocked by
a popup blocker the first time. Click on the URL to accept the popup.
It also clobbers /tmp/differ for good measure.

As you can see, this isn't quite what we're going for.

You'll want to modify diff.py, using the editor you selected earlier.
You'll probably want to consult the |difflib| documentation.
I would suggest you check out the HtmlDiff class and make use of
the make_file member function. Note our goal is to create a
full HTML diff, so the make_table function is insufficient.
The splitlines function may also come in handy.

You can test diff.py manually as you would in a normal UNIX environment.
It can be run like this::

  ./diff.py before.txt after.txt out.html

Once everything is working, diff.html will contain an html diff.
After the initial `make` you can hit "Run" to test your changes.

Now get to it, and good luck!


What you've learned
-------------------

While the details of building and packaging Python have been
insulated from you for the purpose of this exercise, the key take-home lesson
is how easy it is to leverage Python using PNaCl.
As you've likely experienced, the initial start time is non-trivial.
We're working on improving this, both by improving PNaCl,
and our Python port.

The same approach to deploying Python apps can be used for the other
interpreted languages that have been ported to PNaCl.

Check out the range of interpreters, libraries, and tools
`already ported to PNaCl and ready to be integrated with your Web App
<https://code.google.com/p/naclports/wiki/PortList>`_.

While our in-browser environment is rapidly evolving
to become a complete development solution,
for the broadest range of development options, check out the
`NaCl SDK
<https://developer.chrome.com/native-client/sdk/download>`_.

Send us comments and feedback on the `native-client-discuss
<https://groups.google.com/forum/#!forum/native-client-discuss>`_ mailing list,
or ask questions using Stack Overflow's `google-nativeclient
<https://stackoverflow.com/questions/tagged/google-nativeclient>`_ tag.

Bring your interpreted app to PNaCl today!

.. include:: ../nacldev/cleanup_web.inc