First release, remove not used lines from gitignore
This commit is contained in:
parent
c0bfb3b062
commit
d28e1cb4a6
85 changed files with 7205 additions and 50 deletions
22
src/Debug/DebugHook.py
Normal file
22
src/Debug/DebugHook.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
import gevent, sys
|
||||
|
||||
last_error = None
|
||||
def handleError(*args):
|
||||
global last_error
|
||||
if not args: # Get last error
|
||||
args = sys.exc_info()
|
||||
silent = True
|
||||
else:
|
||||
silent = False
|
||||
print "Error catched", args
|
||||
last_error = args
|
||||
if not silent: sys.__excepthook__(*args)
|
||||
|
||||
OriginalGreenlet = gevent.Greenlet
|
||||
class ErrorhookedGreenlet(OriginalGreenlet):
|
||||
def _report_error(self, exc_info):
|
||||
handleError(exc_info[0], exc_info[1], exc_info[2])
|
||||
|
||||
sys.excepthook = handleError
|
||||
gevent.Greenlet = gevent.greenlet.Greenlet = ErrorhookedGreenlet
|
||||
reload(gevent)
|
60
src/Debug/DebugMedia.py
Normal file
60
src/Debug/DebugMedia.py
Normal file
|
@ -0,0 +1,60 @@
|
|||
import os, subprocess, re, logging, time
|
||||
from Config import config
|
||||
|
||||
# Find files with extension in path
|
||||
def findfiles(path, find_ext):
|
||||
for root, dirs, files in os.walk(path, topdown = False):
|
||||
for file in sorted(files):
|
||||
file_path = root+"/"+file
|
||||
file_ext = file.split(".")[-1]
|
||||
if file_ext in find_ext and not file.startswith("all."): yield file_path
|
||||
|
||||
|
||||
# Generates: all.js: merge *.js, compile coffeescript, all.css: merge *.css, vendor prefix features
|
||||
def merge(merged_path):
|
||||
merge_dir = os.path.dirname(merged_path)
|
||||
s = time.time()
|
||||
ext = merged_path.split(".")[-1]
|
||||
if ext == "js": # If merging .js find .coffee too
|
||||
find_ext = ["js", "coffee"]
|
||||
else:
|
||||
find_ext = [ext]
|
||||
|
||||
# If exits check the other files modification date
|
||||
if os.path.isfile(merged_path):
|
||||
merged_mtime = os.path.getmtime(merged_path)
|
||||
changed = False
|
||||
for file_path in findfiles(merge_dir, find_ext):
|
||||
if os.path.getmtime(file_path) > merged_mtime:
|
||||
changed = True
|
||||
break
|
||||
if not changed: return # Assets not changed, nothing to do
|
||||
|
||||
# Merge files
|
||||
parts = []
|
||||
for file_path in findfiles(merge_dir, find_ext):
|
||||
parts.append("\n\n/* ---- %s ---- */\n\n" % file_path)
|
||||
if file_path.endswith(".coffee"): # Compile coffee script
|
||||
if not config.coffeescript_compiler:
|
||||
logging.error("No coffeescript compiler definied, skipping compiling %s" % merged_path)
|
||||
return False # No coffeescript compiler, skip this file
|
||||
command = config.coffeescript_compiler % file_path.replace("/", "\\")
|
||||
s = time.time()
|
||||
compiler = subprocess.Popen(command, shell=True, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||
logging.debug("Running: %s (Done in %.2fs)" % (command, time.time()-s))
|
||||
source = compiler.stdout.read()
|
||||
if source:
|
||||
parts.append(source)
|
||||
else:
|
||||
error = compiler.stderr.read()
|
||||
parts.append("alert('%s compile error: %s');" % (file_path, re.escape(error)) )
|
||||
else: # Add to parts
|
||||
parts.append(open(file_path).read())
|
||||
|
||||
merged = "\n".join(parts)
|
||||
if ext == "css": # Vendor prefix css
|
||||
from lib.cssvendor import cssvendor
|
||||
merged = cssvendor.prefix(merged)
|
||||
merged = merged.replace("\r", "")
|
||||
open(merged_path, "wb").write(merged)
|
||||
logging.debug("Merged %s (%.2fs)" % (merged_path, time.time()-s))
|
35
src/Debug/DebugReloader.py
Normal file
35
src/Debug/DebugReloader.py
Normal file
|
@ -0,0 +1,35 @@
|
|||
import logging, os, sys, time
|
||||
import threading
|
||||
|
||||
try:
|
||||
from fs.osfs import OSFS
|
||||
pyfilesystem = OSFS("src")
|
||||
except Exception, err:
|
||||
logging.info("%s: For autoreload please download pyfilesystem (https://code.google.com/p/pyfilesystem/)" % err)
|
||||
pyfilesystem = False
|
||||
|
||||
|
||||
class DebugReloader:
|
||||
def __init__ (self, callback, directory = "/"):
|
||||
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)
|
||||
except Exception, err:
|
||||
print "File system watcher failed: %s (on linux pyinotify not gevent compatible yet :( )" % err
|
||||
|
||||
|
||||
def changed(self, evt):
|
||||
if not evt.path or evt.path.endswith("pyc"): return False # Ignore *.pyc changes
|
||||
#logging.debug("Changed: %s" % evt)
|
||||
time.sleep(0.1) # Wait for lock release
|
||||
self.callback()
|
1
src/Debug/__init__.py
Normal file
1
src/Debug/__init__.py
Normal file
|
@ -0,0 +1 @@
|
|||
from DebugReloader import DebugReloader
|
Loading…
Add table
Add a link
Reference in a new issue