rabin 7 years ago
parent
commit
2cfe1d59c6

+ 1 - 1
demeter/admin/page/__init__.py

@@ -1,3 +1,3 @@
 # -*- coding: utf-8 -*-
 from demeter.web import *
-Web.init(__file__, globals())
+Web.init(__file__)

+ 1 - 1
demeter/admin/page/admin.py

@@ -4,7 +4,7 @@
     name:admin.py
     author:rabin
 """
-from __load__ import *
+from .__load__ import *
 
 class admin_path(Load):
 	@Web.auth

+ 1 - 1
demeter/admin/page/main.py

@@ -4,7 +4,7 @@
     name:main.py
     author:rabin
 """
-from __load__ import *
+from .__load__ import *
 
 class index_path(Load):
 	@Web.auth

+ 1 - 1
demeter/admin/page/upload.py

@@ -4,7 +4,7 @@
     name:upload.py
     author:rabin
 """
-from __load__ import *
+from .__load__ import *
 from datetime import *
 import os
 import uuid

+ 1 - 1
demeter/admin/page/user.py

@@ -4,7 +4,7 @@
     name:user.py
     author:rabin
 """
-from __load__ import *
+from .__load__ import *
 
 class login_path(Load):
 	def get(self):

+ 5 - 5
demeter/core.py

@@ -30,7 +30,7 @@ class Demeter(object):
 
 	@staticmethod
 	def checkPy3():
-		if sys.version > 3:
+		if sys.version > '3':
 			state = True
 		else:
 			state = False
@@ -40,11 +40,11 @@ class Demeter(object):
 	def getConfig(self):
 		state = self.checkPy3()
 		if state:
-			module = 'ConfigParser'
+			import configparser
+			return configparser.ConfigParser()
 		else:
-			module = 'configparser'
-		module = __import__(module)
-		return getattr(module, 'ConfigParser')
+			import ConfigParser
+			return ConfigParser.ConfigParser()
 
 	@staticmethod
 	def isset(v): 

+ 6 - 2
demeter/db.py

@@ -6,11 +6,13 @@
 """
 
 class Influxdb(object):
+	"""
 	instance = None
 	def __new__(cls, *args, **kwd):
 		if Influxdb.instance is None:
 			Influxdb.instance = object.__new__(cls, *args, **kwd)
 		return Influxdb.instance
+	"""
 
 	def __init__(self, config):
 		influxdb = __import__('influxdb')
@@ -27,12 +29,13 @@ class Influxdb(object):
 
 
 class Postgresql(object):
+	"""
 	instance = None
 	def __new__(cls, *args, **kwd):
 		if Postgresql.instance is None:
 			Postgresql.instance = object.__new__(cls, *args, **kwd)
 		return Postgresql.instance
-		
+	"""
 	def __init__(self, config):
 		psycopg2 = __import__('psycopg2')
 		self.connect = psycopg2.connect(host=config['host'], port=config['port'], user=config['username'], password=config['password'], database=config['dbname'])
@@ -46,12 +49,13 @@ class Postgresql(object):
 		return sql
 
 class Mysql(object):
+	"""
 	instance = None
 	def __new__(cls, *args, **kwd):
 		if Mysql.instance is None:
 			Mysql.instance = object.__new__(cls, *args, **kwd)
 		return Mysql.instance
-		
+	"""
 	def __init__(self, config):
 		pymysql = __import__('pymysql')
 		self.connect = pymysql.connect(host=config['host'], port=int(config['port']), user=config['username'], password=config['password'], database=config['dbname'], charset=config['charset'])

+ 11 - 3
demeter/model.py

@@ -137,7 +137,12 @@ class Model(object):
 		self._attr = {}
 		self._bind = {}
 		self._key = {}
-		col = (int, str, long, float, unicode, bool, uuid.UUID)
+		if Demeter.checkPy3():
+			col = (int, str, float, bool, uuid.UUID)
+			code = (str,)
+		else:
+			col = (int, str, long, float, unicode, bool, uuid.UUID)
+			code = (str, unicode)
 		for field in fields:
 			if isinstance(fields[field], Fields):
 				self._attr[field] = fields[field]
@@ -173,7 +178,7 @@ class Model(object):
 							val = val[0]
 					if insert and self._attr[field].md5:
 						val = self.createMd5(val)
-					if self._attr[field].type == 'boolean' and isinstance(val, (str, unicode)):
+					if self._attr[field].type == 'boolean' and isinstance(val, code):
 						val = Demeter.bool(val, self._type)
 					if type(val) == list:
 						val = tuple(val)
@@ -445,13 +450,14 @@ class Fields(object):
 
 class Counter(object):
 	num = 0
+	"""
 	instance = None
 
 	def __new__(cls, *args, **kwd):
 		if Counter.instance is None:
 			Counter.instance = object.__new__(cls, *args, **kwd)
 		return Counter.instance
-
+	"""
 	def inc(self):
 		self.num = self.num + 1
 		return self.num
@@ -465,11 +471,13 @@ class Counter(object):
 		return self.num
 
 class Sql(object):
+	"""
 	instance = None
 	def __new__(cls, *args, **kwd):
 		if Sql.instance is None:
 			Sql.instance = object.__new__(cls, *args, **kwd)
 		return Sql.instance
+	"""
 
 	def __init__(self, type):
 		self.type = type

+ 12 - 9
demeter/web.py

@@ -26,7 +26,7 @@ class Base(tornado.web.RequestHandler):
 			self.page()
 			self.cookie()
 			self.setting()
-		except Exception, e:
+		except Exception as e:
 			return
 
 	def get_current_user(self):
@@ -209,20 +209,23 @@ class Web(object):
 			try:
 				result = method(self, *args, **kwargs)
 				return result
-			except Exception, e:
-				print e
-				return self.out('404')
-				return self.view('404.html')
+			except Exception as e:
+				Demeter.echo(e)
+				try:
+					return self.view('404.html')
+				except Exception as e:
+					return self.out('404')
 			#return gevent.spawn(method, self, *args, **kwargs)
 		return callback
 
 	@classmethod
-	def init(self, file, local):
+	def init(self, file):
 		path = os.path.split(os.path.realpath(file))[0] + '/'
+		sys.path.append(path)
 		files = self.file(path)
 		url = []
 		for key in files:
-			module = __import__(key, local)
+			module = __import__(key)
 			url = self.url(module, key, url)
 		Demeter.route = Demeter.route + url
 
@@ -259,7 +262,7 @@ class Web(object):
 	@staticmethod
 	def start():
 		if 'route' in Demeter.config['setting']:
-			print(Demeter.route)
+			Demeter.echo(Demeter.route)
 		config = Demeter.config[Demeter.web]
 		cookie = False
 		if 'xsrf_cookies' in config:
@@ -296,7 +299,7 @@ class Web(object):
 			server.bind(settings['port'])
 			server.start(settings['process'])
 			try:		
-				print 'running on port %s' % settings['port']
+				Demeter.echo('running on port %s' % settings['port'])
 				tornado.ioloop.IOLoop.instance().start()
 
 			except KeyboardInterrupt:

+ 2 - 3
demos/helloworld/admin/main.py

@@ -1,6 +1,5 @@
 # -*- coding: utf-8 -*-
 from demeter.web import *
 from demeter.admin.page import *
-from page import *
-Web.start()
-print Demeter.route
+from .page import *
+Web.start()

+ 1 - 1
demos/helloworld/admin/page/__init__.py

@@ -1,3 +1,3 @@
 # -*- coding: utf-8 -*-
 from demeter.web import *
-Web.init(__file__, globals())
+Web.init(__file__)

+ 1 - 1
demos/helloworld/admin/page/site.py

@@ -4,7 +4,7 @@
     name:site.py 站点相关
     author:rabin
 """
-from __load__ import *
+from .__load__ import *
 
 class site_path(Load):
 	@Web.auth

+ 1 - 1
demos/helloworld/front/main.py

@@ -1,4 +1,4 @@
 # -*- coding: utf-8 -*-
 from demeter.web import *
-from page import *
+from .page import *
 Web.start()

+ 1 - 1
demos/helloworld/front/page/__init__.py

@@ -1,3 +1,3 @@
 # -*- coding: utf-8 -*-
 from demeter.web import *
-Web.init(__file__, globals())
+Web.init(__file__)

+ 1 - 1
demos/helloworld/front/page/main.py

@@ -5,7 +5,7 @@
     name:work.py
     author:rabin
 """
-from __load__ import *
+from .__load__ import *
 
 class index_path(Load):
 	#权限控制,需要在Load类中自行做判断

+ 1 - 1
demos/helloworld/install.py

@@ -21,4 +21,4 @@ def manage():
 
 manage()
 
-print 'install success!'
+Demeter.echo('install success!')

+ 0 - 5
demos/helloworld/model/__init__.py

@@ -1,6 +1 @@
-#!/usr/bin/env python
 # -*- coding: utf-8 -*-
-"""
-    demeter init
-    author:rabin
-"""

+ 0 - 2
demos/helloworld/model/__load__.py

@@ -1,9 +1,7 @@
-#!/usr/bin/env python
 # -*- coding: utf-8 -*-
 """
     demeter database
     name:__load__.py
-    author:rabin
 """
 from demeter.model import *
 from demeter.core import *

+ 1 - 2
demos/helloworld/model/manage_admin.py

@@ -1,11 +1,10 @@
-#!/usr/bin/env python
 # -*- coding: utf-8 -*-
 """
     demeter database
     name:manage_admin.py
     author:rabin
 """
-from __load__ import *
+from .__load__ import *
 
 class Manage_admin(Model):
 	__table__ = 'manage_admin'

+ 1 - 3
demos/helloworld/model/manage_log.py

@@ -1,11 +1,9 @@
-#!/usr/bin/env python
 # -*- coding: utf-8 -*-
 """
     demeter database
     name:manage_log.py
-    author:rabin
 """
-from __load__ import *
+from .__load__ import *
 
 class Manage_log(Model):
 	__table__ = 'manage_log'

+ 1 - 3
demos/helloworld/model/manage_role.py

@@ -1,11 +1,9 @@
-#!/usr/bin/env python
 # -*- coding: utf-8 -*-
 """
     demeter database
     name:manage_role.py
-    author:rabin
 """
-from __load__ import *
+from .__load__ import *
 
 class Manage_role(Model):
 	__table__ = 'manage_role'

+ 1 - 2
demos/helloworld/model/order.py

@@ -2,9 +2,8 @@
 """
     demeter database
     name:order.py
-    author:rabin
 """
-from __load__ import *
+from .__load__ import *
 
 class Order(Model):
 	__table__ = 'order'

+ 1 - 2
demos/helloworld/model/product.py

@@ -2,9 +2,8 @@
 """
     demeter database
     name:product.py
-    author:rabin
 """
-from __load__ import *
+from .__load__ import *
 
 class Product(Model):
 	__table__ = 'product'

+ 1 - 2
demos/helloworld/model/site.py

@@ -2,9 +2,8 @@
 """
     demeter database
     name:site.py
-    author:rabin
 """
-from __load__ import *
+from .__load__ import *
 
 class Site(Model):
 	__table__ = 'site'