Skip to content

Commit

Permalink
fix autopush on python 2.6 finally.
Browse files Browse the repository at this point in the history
  • Loading branch information
benoitc committed May 8, 2011
1 parent 9df3ccb commit 45325d7
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 18 deletions.
19 changes: 7 additions & 12 deletions couchapp/autopush/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ def maybe_update(self):

diff = time.time() - self.last_update
if diff >= self.update_delay:
log.info("synchronize changes")
self.doc.push(self.dbs, noatomic=self.noatomic,
noindex=True)
self.last_update = None

def dispatch(self, ev):
log.info("got change")
if self.check_ignore(ev.src_path):
return

Expand Down Expand Up @@ -134,20 +134,15 @@ def run(self):
else:
log.info("Ignoring unknown signal: %s" % sig)
time.sleep(1)
except StopIteration:
self.halt()
except KeyboardInterrupt:
self.halt()
except (StopIteration, KeyboardInterrupt):
self.observer.stop()
return 0
except Exception, e:
log.info("unhandled exception in main loop:\n%s" %
traceback.format_exc())
sys.exit(-1)
return -1
self.observer.join()

def halt(self):
self.observer.stop()
sys.exit(0)

def autopush(conf, path, *args, **opts):
doc_path = None
dest = None
Expand All @@ -168,9 +163,9 @@ def autopush(conf, path, *args, **opts):
docid=opts.get('docid'))
dbs = conf.get_dbs(dest)

update_delay = opts.get('update_delay', DEFAULT_UPDATE_DELAY)
update_delay = int(opts.get('update_delay', DEFAULT_UPDATE_DELAY))
noatomic = opts.get('no_atomic', False)

watcher = CouchappWatcher(doc, dbs, update_delay=update_delay,
noatomic=onoatomic)
noatomic=noatomic)
watcher.run()
4 changes: 2 additions & 2 deletions couchapp/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


from couchapp import clone_app
from couchapp.autopush.command import autopush
from couchapp.autopush.command import autopush, DEFAULT_UPDATE_DELAY
from couchapp.errors import ResourceNotFound, AppError, BulkSaveError
from couchapp import generator
from couchapp.localdoc import document
Expand Down Expand Up @@ -432,7 +432,7 @@ def get_switch_str(opt):
"autopush":
(autopush,
[('', 'no-atomic', False, "send attachments one by one"),
('', 'update-delay', 60, "time between each update")],
('', 'update-delay', DEFAULT_UPDATE_DELAY, "time between each update")],
"[OPTION]... [COUCHAPPDIR] DEST"),
"help":
(usage, [], ""),
Expand Down
3 changes: 0 additions & 3 deletions couchapp/dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,3 @@ def parseopts(args, options, state):
state[name] = True

return args

if __name__ in ('__main__', 'couchapp.dispatch'):
run()
3 changes: 2 additions & 1 deletion resources/scripts/couchapp
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@

from couchapp.dispatch import run

run()
if __name__ == '__main__':
run()

0 comments on commit 45325d7

Please sign in to comment.