1
=== modified file 'docs/install.rst'
2
--- old/docs/install.rst 2010-09-26 22:55:15 +0000
3
+++ new/docs/install.rst 2012-07-10 00:33:03 +0000
4
@@ -50,7 +50,7 @@ Python Libraries:
5
* `Twisted framework <http://twistedmatrix.com/>`_ (core sources)
6
* Twisted Words (IRC, XMPP)
7
* `Wokkel <http://wokkel.ik.nu/>`_. (XMPP)
8
-* `SQLAlchemy <http://www.sqlalchemy.org/>`_ 0.5 preferred, 0.4 compatible.
9
+* `SQLAlchemy <http://www.sqlalchemy.org/>`_ 0.6 or later.
10
* `ConfigObj <http://www.voidspace.org.uk/python/configobj.html>`_ >= 4.7.0
11
* `python-dateutil <http://labix.org/python-dateutil>`_
12
* `SOAPpy <http://pywebsvcs.sourceforge.net/>`_ [#soappy-install]_
14
=== modified file 'ibid/core.py'
15
--- old/ibid/core.py 2011-02-27 11:03:47 +0000
16
+++ new/ibid/core.py 2012-07-10 00:33:03 +0000
17
@@ -14,7 +14,7 @@ from twisted.internet import reactor, th
18
from twisted.python.modules import getModule
19
from sqlalchemy import create_engine
20
from sqlalchemy.orm import sessionmaker, scoped_session
21
-from sqlalchemy.exceptions import IntegrityError
22
+from sqlalchemy.exc import IntegrityError
25
from ibid.event import Event
26
@@ -342,39 +342,47 @@ class DatabaseManager(dict):
27
assert_unicode=True, echo=echo
31
- if uri.startswith(u'mysql://'):
33
- uri += u'?charset=utf8'
35
- params = parse_qs(uri.split(u'?', 1)[1])
36
- if u'charset' not in params:
37
- uri += u'&charset=utf8'
38
+ elif uri.startswith(u'mysql://'):
41
+ params = parse_qs(uri.split(u'?', 1)[1])
42
+ if u'charset' not in params:
43
+ uri += u'&charset=utf8'
44
+ if u'sql_mode' not in params:
45
+ uri += u'&sql_mode=ANSI_QUOTES'
46
+ # As recommended by SQLAlchemy due to a memory leak:
47
+ # http://www.sqlalchemy.org/trac/wiki/DatabaseNotes
48
+ if u'use_unicode' not in params:
49
+ uri += u'&use_unicode=0'
51
engine = create_engine(uri, encoding='utf-8',
52
- convert_unicode=True, assert_unicode=True, echo=echo)
53
+ convert_unicode=True, assert_unicode=True, echo=echo,
54
+ # MySQL closes 8hr old connections:
57
+ class MySQLModeListener(object):
58
+ def connect(self, dbapi_con, con_record):
59
+ mysql_engine = ibid.config.get('mysql_engine', 'InnoDB')
60
+ c = dbapi_con.cursor()
61
+ c.execute("SET SESSION storage_engine=%s;"
63
+ c.execute("SET SESSION time_zone='+0:00';")
65
+ engine.pool.add_listener(MySQLModeListener())
67
- if uri.startswith('mysql://'):
68
- class MySQLModeListener(object):
69
- def connect(self, dbapi_con, con_record):
70
- dbapi_con.set_sql_mode("ANSI")
71
- mysql_engine = ibid.config.get('mysql_engine', 'InnoDB')
72
- c = dbapi_con.cursor()
73
- c.execute("SET storage_engine=%s;" % mysql_engine)
74
- c.execute("SET time_zone='+0:00';")
76
- engine.pool.add_listener(MySQLModeListener())
78
- engine.dialect.use_ansiquotes = True
80
- elif uri.startswith('postgres://'):
81
- class PGSQLModeListener(object):
82
- def connect(self, dbapi_con, con_record):
83
- c = dbapi_con.cursor()
84
- c.execute("SET TIME ZONE UTC")
86
+ elif uri.startswith('postgres://'):
87
+ engine = create_engine(uri, encoding='utf-8',
88
+ convert_unicode=True, assert_unicode=True, echo=echo,
89
+ # Ensure decoded unicode values are returned:
90
+ use_native_unicode=False)
92
+ class PGSQLModeListener(object):
93
+ def connect(self, dbapi_con, con_record):
94
+ c = dbapi_con.cursor()
95
+ c.execute("SET TIME ZONE UTC")
98
- engine.pool.add_listener(PGSQLModeListener())
99
+ engine.pool.add_listener(PGSQLModeListener())
101
self[name] = scoped_session(sessionmaker(bind=engine))
104
=== modified file 'ibid/db/__init__.py'
105
--- old/ibid/db/__init__.py 2011-01-24 11:38:54 +0000
106
+++ new/ibid/db/__init__.py 2012-07-10 00:33:03 +0000
108
# Released under terms of the MIT/X/Expat Licence. See COPYING for details.
109
import warnings as _warnings
111
-from ibid.db.types import TypeDecorator, Integer, DateTime, Boolean, \
112
+from ibid.db.types import Integer, DateTime, Boolean, \
113
IbidUnicode, IbidUnicodeText
115
from sqlalchemy import Table, Column, ForeignKey, Index, UniqueConstraint, \
116
@@ -11,7 +11,7 @@ from sqlalchemy.orm import eagerload, re
117
from sqlalchemy.sql import func
118
from sqlalchemy.ext.declarative import declarative_base as _declarative_base
120
-from sqlalchemy.exceptions import IntegrityError, SADeprecationWarning
121
+from sqlalchemy.exc import IntegrityError, SADeprecationWarning
123
metadata = _MetaData()
124
Base = _declarative_base(metadata=metadata)
125
@@ -19,9 +19,6 @@ Base = _declarative_base(metadata=metada
126
from ibid.db.versioned_schema import VersionedSchema, SchemaVersionException, \
127
schema_version_check, upgrade_schemas
129
-# We use SQLAlchemy 0.4 compatible .save_or_update() functions
130
-_warnings.filterwarnings('ignore', 'Use session.add\(\)', SADeprecationWarning)
132
def get_regexp_op(session):
133
"Return a regexp operator"
134
if session.bind.engine.name in ('postgres', 'postgresql'):
136
=== modified file 'ibid/db/types.py'
137
--- old/ibid/db/types.py 2010-01-17 20:28:33 +0000
138
+++ new/ibid/db/types.py 2012-07-10 00:33:03 +0000
140
-# Copyright (c) 2009-2010, Stefano Rivera
141
+# Copyright (c) 2009-2011, Stefano Rivera
142
# Released under terms of the MIT/X/Expat Licence. See COPYING for details.
144
-from sqlalchemy.types import TypeDecorator, Integer, DateTime, Boolean, \
145
+from sqlalchemy.types import Integer, DateTime, Boolean, \
146
Unicode as _Unicode, UnicodeText as _UnicodeText
148
-class _CIDecorator(TypeDecorator):
149
- "Abstract class for collation aware columns"
151
- def __init__(self, length=None, case_insensitive=False):
152
- self.case_insensitive = case_insensitive
153
- super(_CIDecorator, self).__init__(length=length)
155
+ import sqlalchemy.dialects.postgresql
156
+ sqlalchemy.dialects.postgresql.dialect.ischema_names['citext'] = IbidUnicodeText
157
+ def postgres_visit_IBID_VARCHAR(self, type_):
158
+ if type_.case_insensitive:
161
+ return self.visit_VARCHAR(type_)
162
+ sqlalchemy.dialects.postgresql.dialect.type_compiler.visit_IBID_VARCHAR = postgres_visit_IBID_VARCHAR
163
+ def postgres_visit_IBID_TEXT(self, type_):
164
+ if type_.case_insensitive:
167
+ return self.visit_TEXT(type_)
168
+ sqlalchemy.dialects.postgresql.dialect.type_compiler.visit_IBID_TEXT = postgres_visit_IBID_TEXT
170
- def load_dialect_impl(self, dialect):
171
- if hasattr(dialect, 'name'):
172
- self.dialect = dialect.name
176
- 'SQLiteDialect': 'sqlite',
177
- 'PGDialect': 'postgres',
178
- 'MySQLDialect': 'mysql',
179
- }[dialect.__class__.__name__]
181
- return dialect.type_descriptor(self.impl)
183
- def get_col_spec(self):
184
- colspec = self.impl.get_col_spec()
185
- if hasattr(self, 'case_insensitive'):
187
- if self.dialect == 'mysql':
188
- if self.case_insensitive:
189
- collation = 'utf8_general_ci'
191
- collation = 'utf8_bin'
192
- elif self.dialect == 'sqlite':
193
- if self.case_insensitive:
194
- collation = 'NOCASE'
196
- collation = 'BINARY'
197
- elif self.dialect == 'postgres' and self.case_insensitive:
200
- if collation is not None:
201
- return colspec + ' COLLATE ' + collation
203
+ import sqlalchemy.dialects.sqlite
204
+ def sqlite_visit_IBID_VARCHAR(self, type_):
205
+ if type_.case_insensitive:
206
+ collation = 'NOCASE'
208
+ collation = 'BINARY'
209
+ return self.visit_VARCHAR(type_) + ' COLLATE ' + collation
210
+ sqlalchemy.dialects.sqlite.dialect.type_compiler.visit_IBID_VARCHAR = sqlite_visit_IBID_VARCHAR
211
+ def sqlite_visit_IBID_TEXT(self, type_):
212
+ if type_.case_insensitive:
213
+ collation = 'NOCASE'
215
+ collation = 'BINARY'
216
+ return self.visit_TEXT(type_) + ' COLLATE ' + collation
217
+ sqlalchemy.dialects.sqlite.dialect.type_compiler.visit_IBID_TEXT = sqlite_visit_IBID_TEXT
219
+ import sqlalchemy.dialects.mysql
220
+ def mysql_visit_IBID_VARCHAR(self, type_):
221
+ if type_.case_insensitive:
222
+ collation = 'utf8_general_ci'
224
+ collation = 'utf8_bin'
225
+ return self.visit_VARCHAR(type_) + ' COLLATE ' + collation
226
+ sqlalchemy.dialects.mysql.dialect.type_compiler.visit_IBID_VARCHAR = sqlite_visit_IBID_VARCHAR
227
+ def mysql_visit_IBID_TEXT(self, type_):
228
+ if type_.case_insensitive:
229
+ collation = 'utf8_general_ci'
231
+ collation = 'utf8_bin'
232
+ return self.visit_TEXT(type_) + ' COLLATE ' + collation
233
+ sqlalchemy.dialects.mysql.dialect.type_compiler.visit_IBID_TEXT = sqlite_visit_IBID_TEXT
235
-class IbidUnicode(_CIDecorator):
236
+class IbidUnicode(_Unicode):
237
"Collaiton aware Unicode"
240
+ __visit_name__ = 'IBID_VARCHAR'
242
- def __init__(self, length, **kwargs):
243
+ def __init__(self, length, case_insensitive=False, **kwargs):
244
+ self.case_insensitive = case_insensitive
245
super(IbidUnicode, self).__init__(length, **kwargs)
247
-class IbidUnicodeText(_CIDecorator):
248
+class IbidUnicodeText(_UnicodeText):
249
"Collation aware UnicodeText"
251
- impl = _UnicodeText
252
+ __visit_name__ = 'IBID_TEXT'
254
- def __init__(self, index_length=8, **kwargs):
255
+ def __init__(self, index_length=8, case_insensitive=False, **kwargs):
256
+ self.case_insensitive = case_insensitive
257
self.index_length = index_length
258
- super(IbidUnicodeText, self).__init__(length=None, **kwargs)
259
+ super(IbidUnicodeText, self).__init__(**kwargs)
263
# vi: set et sta sw=4 ts=4:
265
=== modified file 'ibid/db/versioned_schema.py'
266
--- old/ibid/db/versioned_schema.py 2010-06-22 00:04:13 +0000
267
+++ new/ibid/db/versioned_schema.py 2012-07-10 00:33:03 +0000
272
-from sqlalchemy import Column, Index, UniqueConstraint, MetaData, \
273
- __version__ as _sqlalchemy_version
274
-from sqlalchemy.exceptions import InvalidRequestError, OperationalError, \
275
+from sqlalchemy import Column, Index, CheckConstraint, UniqueConstraint, \
276
+ MetaData, __version__ as _sqlalchemy_version
277
+from sqlalchemy.exc import InvalidRequestError, OperationalError, \
278
ProgrammingError, InternalError
279
-if _sqlalchemy_version < '0.5':
280
- NoResultFound = InvalidRequestError
282
- from sqlalchemy.orm.exc import NoResultFound
283
+from sqlalchemy.orm.exc import NoResultFound
285
from ibid.db.types import Integer, IbidUnicodeText, IbidUnicode
287
@@ -19,6 +16,11 @@ from ibid.db import metadata
289
log = logging.getLogger('ibid.db.versioned_schema')
291
+if _sqlalchemy_version < '0.6':
292
+ pg_engine = 'postgres'
294
+ pg_engine = 'postgresql'
296
class VersionedSchema(object):
297
"""For an initial table schema, set
298
table.versioned_schema = VersionedSchema(__table__, 1)
299
@@ -77,7 +79,7 @@ class VersionedSchema(object):
302
schema = Schema(unicode(self.table.name), self.version)
303
- session.save_or_update(schema)
304
+ session.add(schema)
306
Schema.__table__ = self._get_reflected_model()
308
@@ -91,7 +93,7 @@ class VersionedSchema(object):
311
schema = Schema(unicode(self.table.name), self.version)
312
- session.save_or_update(schema)
313
+ session.add(schema)
315
elif self.version > schema.version:
316
for version in range(schema.version + 1, self.version + 1):
317
@@ -103,7 +105,7 @@ class VersionedSchema(object):
318
getattr(self, 'upgrade_%i_to_%i' % (version - 1, version))()
320
schema.version = version
321
- session.save_or_update(schema)
322
+ session.add(schema)
324
self.upgrade_reflected_model = \
325
MetaData(session.bind, reflect=True)
326
@@ -126,7 +128,7 @@ class VersionedSchema(object):
328
if session.bind.engine.name == 'sqlite':
329
return 'ix_%s_%s' % (self.table.name, col.name)
330
- elif session.bind.engine.name == 'postgres':
331
+ elif session.bind.engine.name == pg_engine:
332
return '%s_%s_key' % (self.table.name, col.name)
333
elif session.bind.engine.name == 'mysql':
335
@@ -175,6 +177,8 @@ class VersionedSchema(object):
336
('constraints', old_constraints),
337
('indexes', old_indexes)):
338
for constraint in old_list:
339
+ if isinstance(constraint, CheckConstraint):
341
if any(True for column in constraint.columns
342
if isinstance(column.type, IbidUnicodeText)):
344
@@ -248,7 +252,7 @@ class VersionedSchema(object):
345
query = 'ALTER TABLE "%s" ADD %s INDEX "%s" ("%s"(%i));' % (
346
self.table.name, col.unique and 'UNIQUE' or '',
347
self._index_name(col), col.name, col.type.index_length)
348
- elif engine == 'postgres':
349
+ elif engine == pg_engine:
350
# SQLAlchemy hangs if it tries to do this, because it forgets the ;
351
query = 'CREATE %s INDEX "%s" ON "%s" ("%s")' % (
352
col.unique and 'UNIQUE' or '',self._index_name(col),
353
@@ -271,7 +275,7 @@ class VersionedSchema(object):
356
except ProgrammingError, e:
357
- if engine == 'postgres' and u'already exists' in unicode(e):
358
+ if engine == pg_engine and u'already exists' in unicode(e):
362
@@ -296,21 +300,13 @@ class VersionedSchema(object):
365
except ProgrammingError, e:
366
- if engine == 'postgres' and u'does not exist' in unicode(e):
367
+ if engine == pg_engine and u'does not exist' in unicode(e):
369
- # In SQLAlchemy 0.4, the InternalError below is a ProgrammingError
370
- # and can't be executed in the upgrade transaction:
371
- if engine == 'postgres' and u'requires' in unicode(e):
372
- self.upgrade_session.bind.execute(
373
- 'ALTER TABLE "%s" DROP CONSTRAINT "%s"' % (
374
- self.table.name, self._index_name(col)))
378
# Postgres constraints can be attached to tables and can't be dropped
380
except InternalError, e:
381
- if engine == 'postgres':
382
+ if engine == pg_engine:
383
self.upgrade_session.execute(
384
'ALTER TABLE "%s" DROP CONSTRAINT "%s"' % (
385
self.table.name, self._index_name(col)))
387
=== modified file 'ibid/plugins/codecontest.py'
388
--- old/ibid/plugins/codecontest.py 2011-10-30 17:19:07 +0000
389
+++ new/ibid/plugins/codecontest.py 2012-07-10 00:33:03 +0000
390
@@ -239,7 +239,7 @@ class Usaco(Processor):
391
usaco_account[0].value = usaco_user
393
account.attributes.append(Attribute('usaco_account', usaco_user))
394
- event.session.save_or_update(account)
395
+ event.session.add(account)
396
event.session.commit()
398
event.addresponse(u'Done')
400
=== modified file 'ibid/plugins/factoid.py'
401
--- old/ibid/plugins/factoid.py 2011-08-12 10:04:25 +0000
402
+++ new/ibid/plugins/factoid.py 2012-07-10 00:33:03 +0000
403
@@ -82,7 +82,7 @@ class FactoidName(Base):
404
.filter(FactoidName.name.like('%#_#%%', escape='#')) \
407
- self.upgrade_session.save_or_update(row)
408
+ self.upgrade_session.add(row)
409
def upgrade_7_to_8(self):
410
self.drop_index(self.table.c._name)
411
self.alter_column(Column('name',
412
@@ -401,7 +401,7 @@ class Forget(Processor):
414
name = FactoidName(unicode(target), event.identity)
415
factoid.names.append(name)
416
- event.session.save_or_update(factoid)
417
+ event.session.add(factoid)
418
event.session.commit()
419
event.addresponse(True)
420
log.info(u"Added name '%s' to factoid %s (%s) by %s/%s (%s)",
421
@@ -607,7 +607,7 @@ class Set(Processor):
423
fname = FactoidName(unicode(name), event.identity)
424
factoid.names.append(fname)
425
- event.session.save_or_update(factoid)
426
+ event.session.add(factoid)
427
event.session.flush()
428
log.info(u"Creating factoid %s with name '%s' by %s", factoid.id, fname.name, event.identity)
430
@@ -615,7 +615,7 @@ class Set(Processor):
431
value = '%s %s' % (verb, value)
432
fvalue = FactoidValue(unicode(value), event.identity)
433
factoid.values.append(fvalue)
434
- event.session.save_or_update(factoid)
435
+ event.session.add(factoid)
436
event.session.commit()
437
self.last_set_factoid=factoid.names[0].name
438
log.info(u"Added value '%s' to factoid %s (%s) by %s/%s (%s)",
439
@@ -676,7 +676,7 @@ class Modify(Processor):
441
oldvalue = factoid[2].value
442
factoid[2].value += suffix
443
- event.session.save_or_update(factoid[2])
444
+ event.session.add(factoid[2])
445
event.session.commit()
447
log.info(u"Appended '%s' to value %s (%s) of factoid %s (%s) by %s/%s (%s)",
448
@@ -778,7 +778,7 @@ class Modify(Processor):
449
event.addresponse(u"That operation makes no sense. Try something like y/abcdef/ABCDEF/")
452
- event.session.save_or_update(factoid[2])
453
+ event.session.add(factoid[2])
454
event.session.commit()
456
log.info(u"Applying '%s' to value %s (%s) of factoid %s (%s) by %s/%s (%s)",
458
=== modified file 'ibid/plugins/feeds.py'
459
--- old/ibid/plugins/feeds.py 2011-04-05 00:31:49 +0000
460
+++ new/ibid/plugins/feeds.py 2012-07-10 00:33:03 +0000
461
@@ -147,7 +147,7 @@ class Manage(Processor):
464
feed = Feed(unicode(name), unicode(url), event.identity)
465
- event.session.save(feed)
466
+ event.session.add(feed)
467
event.session.commit()
468
event.addresponse(True)
469
log.info(u"Added feed '%s' by %s/%s (%s): %s (Found %s entries)",
471
=== modified file 'ibid/plugins/fun.py'
472
--- old/ibid/plugins/fun.py 2011-03-11 21:59:06 +0000
473
+++ new/ibid/plugins/fun.py 2012-07-10 00:33:03 +0000
474
@@ -393,7 +393,7 @@ class Item(Base):
475
raise EmptyBucketException
478
- session.save_or_update(item)
483
@@ -503,7 +503,7 @@ class ExchangeMessage(Processor):
487
- event.session.save_or_update(item)
488
+ event.session.add(item)
490
if kind == 'owned' and yours and yours != 'your':
491
item.determiner = yours
492
@@ -623,6 +623,6 @@ def exchange(event, determiner, object,
494
item = Item(object, None, event.identity)
496
- event.session.save_or_update(item)
497
+ event.session.add(item)
499
# vi: set et sta sw=4 ts=4:
501
=== modified file 'ibid/plugins/identity.py'
502
--- old/ibid/plugins/identity.py 2011-03-16 21:41:51 +0000
503
+++ new/ibid/plugins/identity.py 2012-07-10 00:33:03 +0000
504
@@ -54,7 +54,7 @@ class Accounts(Processor):
507
account = Account(username)
508
- event.session.save_or_update(account)
509
+ event.session.add(account)
510
event.session.commit()
511
log.info(u"Created account %s (%s) by %s/%s (%s)",
512
account.id, account.username, event.account, event.identity, event.sender['connection'])
513
@@ -64,14 +64,14 @@ class Accounts(Processor):
514
.filter_by(identity=username, source=event.source).first()
516
identity.account_id = account.id
517
- event.session.save_or_update(identity)
518
+ event.session.add(identity)
519
event.session.commit()
520
log.info(u"Attached identity %s (%s on %s) to account %s (%s)",
521
identity.id, identity.identity, identity.source, account.id, account.username)
523
identity = event.session.query(Identity).get(event.identity)
524
identity.account_id = account.id
525
- event.session.save_or_update(identity)
526
+ event.session.add(identity)
527
event.session.commit()
528
log.info(u"Attached identity %s (%s on %s) to account %s (%s)",
529
identity.id, identity.identity, identity.source, account.id, account.username)
530
@@ -132,7 +132,7 @@ class Accounts(Processor):
531
oldname = account.username
532
account.username = newname
534
- event.session.save_or_update(account)
535
+ event.session.add(account)
536
event.session.commit()
537
identify_cache.clear()
539
@@ -183,12 +183,12 @@ class Identities(Processor):
542
account = Account(username)
543
- event.session.save_or_update(account)
544
+ event.session.add(account)
546
currentidentity = event.session.query(Identity) \
548
currentidentity.account_id = account.id
549
- event.session.save_or_update(currentidentity)
550
+ event.session.add(currentidentity)
552
identify_cache.clear()
554
@@ -250,7 +250,7 @@ class Identities(Processor):
556
ident = Identity(source, identity)
557
ident.account_id = account.id
558
- event.session.save_or_update(ident)
559
+ event.session.add(ident)
560
event.session.commit()
562
identify_cache.clear()
563
@@ -276,7 +276,7 @@ class Identities(Processor):
565
identity = Identity(source, user)
566
identity.account_id = account_id
567
- event.session.save_or_update(identity)
568
+ event.session.add(identity)
569
identify_cache.clear()
571
del self.tokens[token]
572
@@ -308,7 +308,7 @@ class Identities(Processor):
573
event.addresponse(u"I don't know about that identity")
575
identity.account_id = None
576
- event.session.save_or_update(identity)
577
+ event.session.add(identity)
578
event.session.commit()
580
identify_cache.clear()
581
@@ -344,7 +344,7 @@ class Attributes(Processor):
584
account.attributes.append(Attribute(name, value))
585
- event.session.save_or_update(account)
586
+ event.session.add(account)
587
event.session.commit()
589
event.addresponse(True)
590
@@ -467,7 +467,7 @@ class Identify(Processor):
593
identity = Identity(event.source, event.sender['id'])
594
- event.session.save_or_update(identity)
595
+ event.session.add(identity)
597
event.session.commit()
598
log.info(u'Created identity %s for %s on %s', identity.id, identity.identity, identity.source)
599
@@ -546,7 +546,7 @@ class AddAuth(Processor):
600
credential = password
602
credential = Credential(method, credential, source, account.id)
603
- event.session.save_or_update(credential)
604
+ event.session.add(credential)
605
event.session.commit()
606
log.info(u"Added %s credential %s for account %s (%s) on %s by account %s",
607
method, credential.credential, account.id, account.username, source, event.account)
608
@@ -605,7 +605,7 @@ class Permissions(Processor):
611
permission.value = value
612
- event.session.save_or_update(permission)
613
+ event.session.add(permission)
615
event.session.commit()
616
ibid.auth.drop_caches()
618
=== modified file 'ibid/plugins/karma.py'
619
--- old/ibid/plugins/karma.py 2011-01-23 13:19:55 +0000
620
+++ new/ibid/plugins/karma.py 2012-07-10 00:33:03 +0000
621
@@ -133,7 +133,7 @@ class Set(Processor):
623
event.session.delete(karma)
625
- event.session.save_or_update(karma)
626
+ event.session.add(karma)
627
event.session.commit()
629
log.info(u"%s karma for '%s' by %s/%s (%s) because: %s",
630
@@ -168,11 +168,18 @@ class Get(Processor):
632
@match(r'^(reverse\s+)?karmaladder$')
633
def ladder(self, event, reverse):
634
- karmas = event.session.query(Karma) \
635
- .order_by(reverse and Karma.value.asc() or Karma.value.desc()) \
637
+ karmas = event.session.query(Karma)
639
+ karmas = karmas.order_by(Karma.value.asc())
641
+ karmas = karmas.order_by(Karma.value.desc())
642
+ karmas = karmas.limit(30).all()
645
- event.addresponse(', '.join(['%s: %s (%s)' % (karmas.index(karma), karma.subject, karma.value) for karma in karmas]))
646
+ event.addresponse(u', '.join(
648
+ % (karmas.index(karma), karma.subject, karma.value)
649
+ for karma in karmas))
651
event.addresponse(u"I don't really care about anything")
654
=== modified file 'ibid/plugins/memo.py'
655
--- old/ibid/plugins/memo.py 2011-03-23 16:11:13 +0000
656
+++ new/ibid/plugins/memo.py 2012-07-10 00:33:03 +0000
657
@@ -118,7 +118,7 @@ class Tell(Processor):
658
event.addresponse(u'I am not connected to %s', source)
660
to = Identity(source, who)
661
- event.session.save(to)
662
+ event.session.add(to)
663
event.session.commit()
665
log.info(u"Created identity %s for %s on %s", to.id, to.identity,
666
@@ -133,7 +133,7 @@ class Tell(Processor):
668
memo = Memo(event.identity, to.id, memo,
669
how.lower() in (u'pm', u'privmsg', u'msg'))
670
- event.session.save_or_update(memo)
671
+ event.session.add(memo)
673
event.session.commit()
674
log.info(u"Stored memo %s for %s (%s) from %s (%s): %s",
675
@@ -286,7 +286,7 @@ class Deliver(Processor):
676
event.addresponse(message)
678
memo.delivered = True
679
- event.session.save_or_update(memo)
680
+ event.session.add(memo)
681
event.session.commit()
682
log.info(u"Delivered memo %s to %s (%s)",
683
memo.id, event.identity, event.sender['connection'])
685
=== modified file 'ibid/plugins/seen.py'
686
--- old/ibid/plugins/seen.py 2010-03-27 15:50:58 +0000
687
+++ new/ibid/plugins/seen.py 2012-07-10 00:33:03 +0000
688
@@ -86,7 +86,7 @@ class See(Processor):
689
sighting.time = event.time
690
sighting.count = sighting.count + 1
692
- event.session.save_or_update(sighting)
693
+ event.session.add(sighting)
695
event.session.commit()
696
except IntegrityError:
698
=== modified file 'ibid/plugins/urlgrab.py'
699
--- old/ibid/plugins/urlgrab.py 2011-01-26 20:28:17 +0000
700
+++ new/ibid/plugins/urlgrab.py 2012-07-10 00:33:03 +0000
701
@@ -76,7 +76,7 @@ class Grab(Processor):
702
url = 'http://%s' % url
704
u = URL(url, event.channel, event.identity)
705
- event.session.save_or_update(u)
706
+ event.session.add(u)
708
if self.service and self.username:
709
self._post_url(event, url)
711
=== modified file 'ibid/test/__init__.py'
712
--- old/ibid/test/__init__.py 2011-08-14 15:26:08 +0000
713
+++ new/ibid/test/__init__.py 2012-07-10 00:33:39 +0000
714
@@ -10,6 +10,8 @@ import shutil
720
from twisted.python import log
721
from twisted.python.modules import getModule
722
from twisted.trial import unittest
723
@@ -103,6 +105,13 @@ class PluginTestCase(TestCase):
726
super(PluginTestCase, self).setUp()
727
+ if sqlalchemy.__version__ > '0.6.0':
728
+ raise unittest.SkipTest(
729
+ "PluginTestCase doesn't work with SQLAlchemy 0.6")
730
+ if self.network and os.getenv('IBID_NETWORKLESS_TEST') is not None:
731
+ raise unittest.SkipTest('test uses network')
733
+ ibid.config = FileConfig(locate_resource('ibid.test', 'test.ini'))
735
if self.load_configured is None:
736
self.load_configured = not self.load
737
@@ -127,7 +136,7 @@ class PluginTestCase(TestCase):
738
session = ibid.databases.ibid()
740
self.identity = Identity(self.source, self.username)
741
- session.save(self.identity)
742
+ session.add(self.identity)
744
self.identity = session.query(Identity) \
745
.filter_by(identity=self.username).one()
747
=== modified file 'scripts/ibid-factpack'
748
--- old/scripts/ibid-factpack 2010-02-16 09:41:11 +0000
749
+++ new/scripts/ibid-factpack 2012-07-10 00:33:03 +0000
750
@@ -85,7 +85,7 @@ if factpack:
753
factpack = Factpack(name)
754
-session.save(factpack)
755
+session.add(factpack)
759
@@ -102,7 +102,7 @@ for names, values in facts:
760
fvalue = FactoidValue(unicode(value), None, factpack=factpack.id)
761
factoid.values.append(fvalue)
762
if len(factoid.names) > 0:
763
- session.save(factoid)
764
+ session.add(factoid)
766
if existing and not options.skip:
767
print >> stderr, u'The following factoids already exist in the database. ' \
769
=== modified file 'scripts/ibid-knab-import'
770
--- old/scripts/ibid-knab-import 2011-02-20 18:31:50 +0000
771
+++ new/scripts/ibid-knab-import 2012-07-10 00:33:03 +0000
772
@@ -130,7 +130,7 @@ def identify(session, user, source, crea
774
identity = Identity(source, user)
775
identity.created = created
776
- session.save(identity)
777
+ session.add(identity)
779
elif identity.created > created:
780
identity.created = created
781
@@ -187,7 +187,7 @@ def import_factoids(knab, ibid, source):
782
fvalue.time = kfactoid.utc_time
784
factoid.values.append(fvalue)
785
- ibid.save_or_update(factoid)
790
@@ -297,7 +297,7 @@ if __name__ == '__main__':
791
config.merge(FileConfig('local.ini'))
793
ibidengine = create_engine(config.databases['ibid'], encoding='utf-8')
794
- IbidSession = sessionmaker(bind=ibidengine, transactional=False)
795
+ IbidSession = sessionmaker(bind=ibidengine, autocommit=True)
798
import_factoids(knab, ibid, source)
800
=== modified file 'scripts/ibid-plugin'
801
--- old/scripts/ibid-plugin 2011-03-15 09:56:25 +0000
802
+++ new/scripts/ibid-plugin 2012-07-10 00:33:03 +0000
803
@@ -102,7 +102,7 @@ session = ibid.databases.ibid()
804
identity = session.query(Identity).filter_by(identity=username, source=u'test_source').first()
806
identity = Identity(u'test_source',username)
807
- session.save(identity)
808
+ session.add(identity)
810
identity = session.query(Identity).filter_by(identity=username).first()
811
identity_id = identity.id
813
=== modified file 'scripts/ibid-setup'
814
--- old/scripts/ibid-setup 2011-02-25 23:43:15 +0000
815
+++ new/scripts/ibid-setup 2012-07-10 00:33:03 +0000
816
@@ -158,8 +158,8 @@ for permission in (u'accounts', u'source
817
credential = Credential(u'password', hash(unicode(pass1)))
818
account.credentials.append(credential)
820
-session.save_or_update(account)
821
-session.save_or_update(identity)
822
+session.add(account)
823
+session.add(identity)
828
=== modified file 'setup.py'
829
--- old/setup.py 2010-09-26 22:55:15 +0000
830
+++ new/setup.py 2012-07-10 00:33:03 +0000
831
@@ -18,7 +18,7 @@ install_requires=[
835
- 'SQLAlchemy>=0.5,<0.6a', # Works with >=0.4.6 except on OS X