| OLD | NEW |
| 1 # Copyright (c) 2010 Chris Moyer http://coredumped.org/ | 1 # Copyright (c) 2010 Chris Moyer http://coredumped.org/ |
| 2 # | 2 # |
| 3 # Permission is hereby granted, free of charge, to any person obtaining a | 3 # Permission is hereby granted, free of charge, to any person obtaining a |
| 4 # copy of this software and associated documentation files (the | 4 # copy of this software and associated documentation files (the |
| 5 # "Software"), to deal in the Software without restriction, including | 5 # "Software"), to deal in the Software without restriction, including |
| 6 # without limitation the rights to use, copy, modify, merge, publish, dis- | 6 # without limitation the rights to use, copy, modify, merge, publish, dis- |
| 7 # tribute, sublicense, and/or sell copies of the Software, and to permit | 7 # tribute, sublicense, and/or sell copies of the Software, and to permit |
| 8 # persons to whom the Software is furnished to do so, subject to the fol- | 8 # persons to whom the Software is furnished to do so, subject to the fol- |
| 9 # lowing conditions: | 9 # lowing conditions: |
| 10 # | 10 # |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 self.__class__.__name__, | 190 self.__class__.__name__, |
| 191 self.id, | 191 self.id, |
| 192 self.domain_name, | 192 self.domain_name, |
| 193 self.fnc.__module__, self.fnc.__name__, | 193 self.fnc.__module__, self.fnc.__name__, |
| 194 self.val) | 194 self.val) |
| 195 | 195 |
| 196 | 196 |
| 197 def _connect(self): | 197 def _connect(self): |
| 198 """Connect to our domain""" | 198 """Connect to our domain""" |
| 199 if not self._db: | 199 if not self._db: |
| 200 import boto |
| 201 sdb = boto.connect_sdb() |
| 200 if not self.domain_name: | 202 if not self.domain_name: |
| 201 import boto | |
| 202 sdb = boto.connect_sdb() | |
| 203 self.domain_name = boto.config.get("DB", "sequence_db", boto.con
fig.get("DB", "db_name", "default")) | 203 self.domain_name = boto.config.get("DB", "sequence_db", boto.con
fig.get("DB", "db_name", "default")) |
| 204 try: | 204 try: |
| 205 self._db = sdb.get_domain(self.domain_name) | 205 self._db = sdb.get_domain(self.domain_name) |
| 206 except SDBResponseError, e: | 206 except SDBResponseError, e: |
| 207 if e.status == 400: | 207 if e.status == 400: |
| 208 self._db = sdb.create_domain(self.domain_name) | 208 self._db = sdb.create_domain(self.domain_name) |
| 209 else: | 209 else: |
| 210 raise | 210 raise |
| 211 return self._db | 211 return self._db |
| 212 | 212 |
| 213 db = property(_connect) | 213 db = property(_connect) |
| 214 | 214 |
| 215 def next(self): | 215 def next(self): |
| 216 self.val = self.fnc(self.val, self.last_value) | 216 self.val = self.fnc(self.val, self.last_value) |
| 217 return self.val | 217 return self.val |
| 218 | 218 |
| 219 def delete(self): | 219 def delete(self): |
| 220 """Remove this sequence""" | 220 """Remove this sequence""" |
| 221 self.db.delete_attributes(self.id) | 221 self.db.delete_attributes(self.id) |
| 222 | |
| 223 def __del__(self): | |
| 224 self.delete() | |
| OLD | NEW |