2015-01-12 02:03:45 +01:00
|
|
|
import logging, os, sys, time
|
|
|
|
import threading
|
2015-03-11 16:25:29 +01:00
|
|
|
from Config import config
|
2015-01-12 02:03:45 +01:00
|
|
|
|
2015-03-11 16:25:29 +01:00
|
|
|
if config.debug: # Only load pyfilesytem if using debug mode
|
|
|
|
try:
|
|
|
|
from fs.osfs import OSFS
|
|
|
|
pyfilesystem = OSFS("src")
|
version 0.2.7, plugin system, multiuser plugin for zeroproxies, reworked imports, cookie parse, stats moved to plugin, usermanager class, dont generate site auth on listing, multiline notifications, allow server side prompt from user, update script keep plugins disabled status
2015-03-24 01:33:09 +01:00
|
|
|
pyfilesystem_plugins = OSFS("plugins")
|
2015-03-11 16:25:29 +01:00
|
|
|
except Exception, err:
|
|
|
|
logging.debug("%s: For autoreload please download pyfilesystem (https://code.google.com/p/pyfilesystem/)" % err)
|
|
|
|
pyfilesystem = False
|
|
|
|
else:
|
2015-01-12 02:03:45 +01:00
|
|
|
pyfilesystem = False
|
|
|
|
|
|
|
|
class DebugReloader:
|
|
|
|
def __init__ (self, callback, directory = "/"):
|
version 0.2.0, new lib for bitcoin ecc, dont display or track notify errors, dont reload again within 1 sec, null peer ip fix, signingmoved to ContentManager, content.json include support, content.json multisig ready, content.json proper bitcoincore compatible signing, content.json include permissions, multithreaded publish, publish timeout 60s, no exception on invalid bitcoin address, testcase for new lib, bip32 based persite privatekey generation, multiuser ready, simple json database query command, websocket api fileGet, wrapper loading title stuck bugfix
2015-02-09 02:09:02 +01:00
|
|
|
self.last_chaged = 0
|
2015-01-12 02:03:45 +01:00
|
|
|
if pyfilesystem:
|
|
|
|
self.directory = directory
|
|
|
|
self.callback = callback
|
|
|
|
logging.debug("Adding autoreload: %s, cb: %s" % (directory, callback))
|
|
|
|
thread = threading.Thread(target=self.addWatcher)
|
|
|
|
thread.daemon = True
|
|
|
|
thread.start()
|
|
|
|
|
|
|
|
|
|
|
|
def addWatcher(self, recursive=True):
|
|
|
|
try:
|
|
|
|
time.sleep(1) # Wait for .pyc compiles
|
|
|
|
pyfilesystem.add_watcher(self.changed, path=self.directory, events=None, recursive=recursive)
|
version 0.2.7, plugin system, multiuser plugin for zeroproxies, reworked imports, cookie parse, stats moved to plugin, usermanager class, dont generate site auth on listing, multiline notifications, allow server side prompt from user, update script keep plugins disabled status
2015-03-24 01:33:09 +01:00
|
|
|
pyfilesystem_plugins.add_watcher(self.changed, path=self.directory, events=None, recursive=recursive)
|
2015-01-12 02:03:45 +01:00
|
|
|
except Exception, err:
|
|
|
|
print "File system watcher failed: %s (on linux pyinotify not gevent compatible yet :( )" % err
|
|
|
|
|
|
|
|
|
|
|
|
def changed(self, evt):
|
version 0.2.0, new lib for bitcoin ecc, dont display or track notify errors, dont reload again within 1 sec, null peer ip fix, signingmoved to ContentManager, content.json include support, content.json multisig ready, content.json proper bitcoincore compatible signing, content.json include permissions, multithreaded publish, publish timeout 60s, no exception on invalid bitcoin address, testcase for new lib, bip32 based persite privatekey generation, multiuser ready, simple json database query command, websocket api fileGet, wrapper loading title stuck bugfix
2015-02-09 02:09:02 +01:00
|
|
|
if not evt.path or evt.path.endswith("pyc") or time.time()-self.last_chaged < 1: return False # Ignore *.pyc changes and no reload within 1 sec
|
2015-01-12 02:03:45 +01:00
|
|
|
#logging.debug("Changed: %s" % evt)
|
|
|
|
time.sleep(0.1) # Wait for lock release
|
|
|
|
self.callback()
|
version 0.2.0, new lib for bitcoin ecc, dont display or track notify errors, dont reload again within 1 sec, null peer ip fix, signingmoved to ContentManager, content.json include support, content.json multisig ready, content.json proper bitcoincore compatible signing, content.json include permissions, multithreaded publish, publish timeout 60s, no exception on invalid bitcoin address, testcase for new lib, bip32 based persite privatekey generation, multiuser ready, simple json database query command, websocket api fileGet, wrapper loading title stuck bugfix
2015-02-09 02:09:02 +01:00
|
|
|
self.last_chaged = time.time()
|