/
README.txt
320 lines (224 loc) · 10.1 KB
/
README.txt
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
http://cardstories.org/
Copyright (C) 2010,2011 Xavier Antoviaque <xavier@antoviaque.org> (gameplay and specifications)
Copyright (C) 2010,2011 David Blanchard <david@blanchard.name> (gameplay and specifications)
Copyright (C) 2010,2011 tartarugafeliz <contact@tartarugafeliz.com> (artwork)
Copyright (C) 2011 Loic Dachary <loic@dachary.org> (software)
A player (who we will call the author) creates a new game.
He chooses a card, picks a word or a sentence to describe it
and invites players to participate.
Each players is given seven cards and are required to pick
one that best matches the author's sentence.
Once enough players have chosen a card, the author displays all chosen
cards and the players try to figure out which one is the author's.
The author wins if at least one of the players guesses right, but not all
of them do. The winners are the author and the players who guessed right.
If the author loses, all the other players win.
####################################
Setting up a development environment
####################################
The following are instructions to set up a contained development environment
on a recent installation of Ubuntu or Debian.
First, install the following packages.
$ sudo apt-get install postfix python-twisted python-lxml \
python-httplib2 python-pip sqlite3
[Optional] Create a virtual environment for Card Stories, to avoid
dependencies conflict with other software installed on your system:
$ mkvirtualenv cardstories
Now install the remaining python dependencies with pip:
$ pip install -r requirements.txt
Now, make sure you are at the root of the cardstories checkout. At this point,
create the default database structure for the website, but first, create a
local configuration file containing the following:
$ vim website/local_settings.py
-------------------
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': '/tmp/website.sqlite',
'USER': '',
'PASSWORD': '',
'HOST': '',
'PORT': '',
}
}
DEFAULT_FROM_EMAIL='Card Stories <feedback@farsides.com>'
BASE_URL='http://local.cardstories.org:8000'
-------------------
Now, create the database:
$ website/manage.py syncdb
$ website/manage.py migrate
Note that for local Facebook development, you must also add an entry to
/etc/hosts that matches the domain name in your Django site configuration. It
is recommended when running the above syncdb command to chose
"local.cardstories.org" as the domain name, and then to add a line in
/etc/hosts like the following:
127.0.0.1 local.cardstories.org
If for any reason you need to run the website dev server on a different host or
port, these files that must be modified accordingly (and the cardstories web
service restarted if it's already running):
* tests/djangoauth/djangoauth.xml
* tests/mail/mail.xml
Create the log folder:
$ mkdir log/
On one terminal window, run the cardstories web service. Under default
configuration, the following command assumes you have postfix configured
properly for relaying emails sent to 'localhost' (otherwise invitations won't
be sent out):
$ PYTHONPATH=.:etc/cardstories twistd --nodaemon cardstories \
--static $(pwd)/static --port 5000 --interface 0.0.0.0 \
--db /tmp/cardstories.sqlite \
--plugins-dir plugins \
--plugins-libdir /tmp \
--plugins-logdir log/ \
--plugins-confdir tests \
--plugins 'djangoauth chat activity table mail' \
--plugins-pre-process 'djangoauth chat'
--plugins-post-process 'table'
On a second terminal window, still from the root of the checkout, run the
website development server, which by default binds to localhost and port 8000.
However, for local Facebook redirection to work (which you set up above in
/etc/hosts), you must run the server on port 80 as root:
$ sudo website/manage.py runserver 0.0.0.0:80
Now simply access http://local.cardstories.org/, and code away!
###########################
Enabling Open Web Analytics
###########################
To use OWA, first you must get it up and running somewhere. To do so, follow
the installation steps here:
http://wiki.openwebanalytics.com/index.php?title=Installation
Once it's configured and running, for example at http://localhost:8080/, log in
and obtain your Site ID. With this information in hand, start by setting the
correct values in website/settings.py:
$ vim website/settings.py
----------
OWA_ENABLE = True
OWA_URL = 'http://localhost:8080/'
OWA_SITE_ID = '<your_site_id>'
----------
Once this is done, all relevant page views should be logged. Game state
changes will be artificially logged as page views with URLs in the following
format, where <skin_name> refers to an existing skin in the game.
http://local.cardstories.org/?skin=<skin_name>
You can then proceed to set up goals in OWA accordingly.
#################################
Deploying cardstories with Apache
#################################
In order to deploy cardstories with Apache, the following additional packages
must be installed:
$ sudo apt-get install apache2 libapache2-mod-wsgi
From the root of your cardstories checkout, install cardstories to the default
locations with:
$ sudo python setup.py install
Then, from cardstories root, copy the apache configuration file to the proper
location on the file system, and enable it. You may need to edit it depending
on your site characteristics (particularly the location of django's admin
media):
$ sudo cp website/apache/apache2.conf /etc/apache2/sites-available/cardstories
$ sudo a2ensite cardstories
Now enable the required apache mods, and restart the server:
$ a2enmod wsgi
$ a2enmod proxy_http
$ sudo /etc/init.d/apache2 restart
Don't forget to create the default database for the website and run the
cardstories web service as described in the previous section.
Finally, to future deployments, you can create a separate local_settings.py
containing just the stuff you want applied locally (such as Facebook app id,
OWA url, etc) in:
/usr/share/cardstories/website/local_settings.py
To disable specific email notifications, after deployment edit
/etc/cardstories/plugins/mail/mail.xml so that it contains only the "allow"
nodes you need (valid options are 'invite', 'pick', 'voting', 'vote',
'complete'):
<mail ...>
<allow>invite</allow>
<allow>vote</allow>
</mail>
If NO notifications are to be sent, create an empty allow node (for backward
compatibility, if there aren't any allow nodes, mail will be sent for all
events):
<mail ...>
<allow></allow>
</mail>
##############
Usage examples
##############
To display the cardstories web service usage information:
$ PYTHONPATH=.:etc/cardstories twistd cardstories --help
To run the webservice without mail or djangoauth:
$ PYTHONPATH=.:etc/cardstories twistd --nodaemon cardstories \
--static $(pwd)/static --port 5000 --interface 0.0.0.0 \
--db /tmp/cardstories.sqlite \
--plugins-dir plugins \
--plugins-libdir /tmp \
--plugins-confdir tests \
--plugins-logdir log \
--plugins 'auth chat' \
--plugins-pre-process 'auth chat activity' \
To check if the webservice replies, run the following (requires curl). The
following must return the [{"games": [], "type": "tabs", "modified": 0}, {"type": "players_info}"]
string:
$ curl --silent 'http://localhost:5000/resource?action=state&type=tabs=player_id=0'
#############
Extra plugins
#############
* Bot plugin:
- See ./plugins/bot/README.txt for installation instructions
#################
Running the tests
#################
First install the dependencies:
$ sudo apt-get install python-coverage jscoverage
Running the Python tests (Twisted and Django):
$ make -f maintain.mk clean
$ make -f maintain.mk check
Running the Javascript tests - using your browser, go to:
- http://local.cardstories.org:8000/static/test/index.html
- http://local.cardstories.org:8000/static/test/audio.html
- http://local.cardstories.org:8000/static/test/chat.html
- http://local.cardstories.org:8000/static/test/owa.html
- http://local.cardstories.org:8000/static/test/table.html
- http://local.cardstories.org:8000/static/test/tabs.html
######################
Packaging instructions
######################
To create a source distribution use:
$ v=2.0.0 ; python setup.py sdist --dist-dir .. ; mv ../cardstories-$v.tar.gz ../cardstories_$v.orig.tar.gz
To create the Debian GNU/Linux package use:
$ dpkg-buildpackage -S -uc -us
##########
Migrations
##########
A) Upgrading the webservice DB
==============================
When upgrading, if there has been alteration to the webservice database schema,
migration files will be added to the migrations/ folder. Just run them, in numerical
order, using a command like:
$ sqlite3 /tmp/cardstories.org.sqlite < migrations/001_add_tabs_table.sql
B) Upgrading Django's DB (v2.2+)
================================
You will also need to make sure there hasn't been any DB alteration in django - run
the following commands to ensure you're up to date:
$ ./website/manage.py syncdb
$ ./website/manage.py migrate
B') Upgrading Django's DB (from before v2.2)
============================================
Prior to version 2.2, django wasn't using south to handle migrations. So if you have
a database from before 2.2, run the following commands to avoid having south trying
to recreate the database from scratch (if you ran syncdb on the 2.1 version, make
sure you drop the cardstories_usercard table, as the migration will attempt to
create it)
$ ./website/manage.py syncdb
$ ./website/manage.py migrate cardstories 0001 --fake
B) Developers - Automatically generating Django migrations
==========================================================
For the webservice, you will have to create the SQL migration files manually in the
migrations/ folder, but for django south will take care of it automatically for you,
based on alterations you make to the models.py file. Simply run the following
command:
$ ./website/manage.py schemamigration cardstories --auto
$ ./website/manage.py migrate cardstories
######################
Additional information
######################
As of Apr, 26th 2011 there are 321 LOC of JavaScript, 687 LOC of Python = 1008 LOC
As of Jun, 19th 2011 there are 473 LOC of JavaScript, 896 LOC of Python = 1369 LOC