dever 6 years ago
parent
commit
fb4b4812bc
3 changed files with 23 additions and 5 deletions
  1. 14 3
      demeter/core.py
  2. 7 1
      demeter/web.py
  3. 2 1
      requirements.txt

+ 14 - 3
demeter/core.py

@@ -7,6 +7,7 @@
 import time
 import os
 import signal
+import shutil
 import re
 import sys
 import json
@@ -522,9 +523,15 @@ class File(object):
 	def rename(old, new):
 		return os.rename(old, new)
 
-	@staticmethod
-	def remove(file):
-		return os.remove(file)
+	@classmethod
+	def remove(self, file):
+		if isinstance(file, str) and self.exists(file):
+			if os.path.isfile(file):
+				return os.remove(file)
+			else:
+				# 删除非空目录
+				return shutil.rmtree(file)
+		return False
 
 	@staticmethod
 	def mkdir(path):
@@ -542,6 +549,10 @@ class File(object):
 	def ext(path):
 		return os.path.splitext(path)[1]
 
+	@classmethod
+	def runtime(self, path = 'data'):
+		return self.mkdir(self.path() + 'runtime/' + path + '/')
+
 class Shell(object):
 	@staticmethod
 	def popen(command, sub=False, bg=False, timeout=0):

+ 7 - 1
demeter/web.py

@@ -11,6 +11,8 @@ import functools
 
 import os
 import json
+import threading
+import asyncio
 from demeter.core import *
 import tornado.web
 import tornado.ioloop
@@ -264,6 +266,10 @@ class Web(object):
 		return url
 	@classmethod
 	def start(self, application=[]):
+		t = threading.Thread(target=lambda: self.start_server(application))
+		t.start()
+	@classmethod
+	def start_server(self, application=[]):
 		self.init(application)
 		if 'route' in Demeter.config['setting']:
 			Demeter.echo(Demeter.route)
@@ -303,7 +309,7 @@ class Web(object):
 
 		application_setting()
 		application = tornado.web.Application(handlers=handlers, **settings)
-		
+		asyncio.set_event_loop(asyncio.new_event_loop())
 		if settings['debug'] == True:
 			application.listen(settings['port'])
 			tornado.ioloop.IOLoop.instance().start()

+ 2 - 1
requirements.txt

@@ -4,4 +4,5 @@ celery
 short_url
 requests
 logging
-watchdog
+watchdog
+asyncio