OLD | NEW |
(Empty) | |
| 1 .. _cds2014_python: |
| 2 |
| 3 ######################################## |
| 4 What a difference Python Makes - Codelab |
| 5 ######################################## |
| 6 |
| 7 Introduction |
| 8 ------------ |
| 9 |
| 10 .. include:: python_summary.inc |
| 11 |
| 12 .. include:: ../nacldev/setup_web.inc |
| 13 |
| 14 |
| 15 Get the Code! |
| 16 ------------- |
| 17 |
| 18 Rather than start from nothing, for this codelab we've provided |
| 19 you with a zip file containing a starting point. |
| 20 |
| 21 Download the codelab:: |
| 22 |
| 23 geturl https://nacltools.storage.googleapis.com/cds2014/cds2014_python.zip cds
2014_python.zip |
| 24 |
| 25 Unzip it:: |
| 26 |
| 27 unzip cds2014_python.zip |
| 28 |
| 29 Go into the codelab directory:: |
| 30 |
| 31 cd cds2014_python |
| 32 |
| 33 Create a new local git repo:: |
| 34 |
| 35 git init |
| 36 |
| 37 Add everything:: |
| 38 |
| 39 git add . |
| 40 |
| 41 Commit it:: |
| 42 |
| 43 git commit -am "initial" |
| 44 |
| 45 While working, you can see what you've changed by running:: |
| 46 |
| 47 git diff |
| 48 |
| 49 |
| 50 Your challenge, should you choose to accept it... |
| 51 ------------------------------------------------- |
| 52 |
| 53 Javascript has many wonderful features out of the box. |
| 54 Unfortunately, generating textual diffs is not one of them. |
| 55 Python on the other hand has the |difflib| module in its standard library. |
| 56 |
| 57 The starting point you've just extracted contains the shell |
| 58 of a web app using Portable Native Client Python to generate a diff. |
| 59 Just one thing is missing, that whole diffing thing... |
| 60 |
| 61 To see where things stand, deploy the sample like this:: |
| 62 |
| 63 make |
| 64 |
| 65 This will copy the sample to /tmp/differ (clobbering whatever is already |
| 66 there). It will also attempt to open the sample, but will be blocked by |
| 67 a popup blocker. Click on the URL to accept the popup. |
| 68 |
| 69 As you can see, this isn't quite what we're going for. |
| 70 |
| 71 You'll want to modify diff.py, using the editor you selected earlier. |
| 72 You'll probably want to consult the |difflib| documentation. |
| 73 I would suggest you check out the HtmlDiff class and make use of |
| 74 the make_file member function. I would also suggest the splitlines |
| 75 function may come in handy. |
| 76 |
| 77 You can test diff.py manually as you would in a normal UNIX environment. |
| 78 It can be run like this:: |
| 79 |
| 80 ./diff.py before.txt after.txt out.html |
| 81 |
| 82 Once everything is working diff.html will contain an html diff. |
| 83 Run `make` again to deploy and test the full app. |
| 84 |
| 85 Now get to it, and good luck! |
| 86 |
| 87 |
| 88 What you've learned |
| 89 ------------------- |
| 90 |
| 91 While the details of building and packaging Python have been |
| 92 insulated from you for the purpose of this exercise, the key take-home lesson |
| 93 is how easy it is to leverage Python using PNaCl. |
| 94 As you've likely experienced, the initial start time is non-trivial. |
| 95 We're working on improving this, both by improving PNaCl, |
| 96 and our Python port. |
| 97 |
| 98 The same approach to deploying Python apps can be used for the other |
| 99 interpreted languages that have been ported to PNaCl. |
| 100 |
| 101 Check out the range of interpreters, libraries, and tools |
| 102 `already ported to PNaCl and ready to be integrated with your Web App |
| 103 <https://code.google.com/p/naclports/wiki/PortList>`_. |
| 104 |
| 105 While our in-browser environment is rapidly evolving |
| 106 to become a complete development solution, |
| 107 for the broadest range of development options, check out the |
| 108 `NaCl SDK |
| 109 <https://developer.chrome.com/native-client/sdk/download>`_. |
| 110 |
| 111 For questions, concerns, and help contact us at |
| 112 `native-client-discuss@googlegroups.com |
| 113 <https://groups.google.com/forum/#!forum/native-client-discuss>`_. |
| 114 |
| 115 Bring your interpreted app to PNaCl today! |
| 116 |
| 117 .. include:: ../nacldev/cleanup_web.inc |
OLD | NEW |