rabin vor 6 Jahren
Ursprung
Commit
bcc10cb14c
2 geänderte Dateien mit 23 neuen und 5 gelöschten Zeilen
  1. 2 3
      core.py
  2. 21 2
      db.py

+ 2 - 3
core.py

@@ -14,8 +14,6 @@ import getopt
 import json
 import ConfigParser
 import subprocess
-import urllib2
-from tornado.web import Finish
 class Demeter(object):
 	path = ''
 	config = {}
@@ -25,7 +23,6 @@ class Demeter(object):
 	request = False
 
 	def __new__(self, *args, **kwargs):
-		print 'error'
 		sys.exit()
 
 	def __init__(self):
@@ -258,12 +255,14 @@ class Demeter(object):
 
 	@classmethod
 	def curl(self, url):
+		import urllib2
 		req = urllib2.Request(url)
 		response = urllib2.urlopen(req)
 		return response.read()
 
 	@classmethod
 	def error(self, string):
+		from tornado.web import Finish
 		if self.request:
 			self.request.out(string)
 			#self.request.finish()

+ 21 - 2
db.py

@@ -5,8 +5,6 @@
     name:db.py
     author:rabin
 """
-from influxdb import InfluxDBClient
-import psycopg2
 
 class Influxdb(object):
 	instance = None
@@ -16,6 +14,8 @@ class Influxdb(object):
 		return Influxdb.instance
 
 	def __init__(self, config):
+		influxdb = __import__('influxdb')
+		InfluxDBClient = getattr(influxdb, 'InfluxDBClient')
 		self.connect = InfluxDBClient(config['host'], config['port'], config['username'], config['password'], config['dbname'])
 		self.create(config['dbname'])
 
@@ -35,6 +35,7 @@ class Postgresql(object):
 		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'])
 
 	def get(self):
@@ -43,4 +44,22 @@ class Postgresql(object):
 	def create(self, name):
 		'psql -U postgres'
 		sql = 'CREATE DATABASE '+name+' WITH OWNER = postgres ENCODING = "UTF8"'
+		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=config['port'], user=config['username'], password=config['password'], database=config['dbname'])
+
+	def get(self):
+		return self.connect
+
+	def create(self, name):
+		sql = 'CREATE DATABASE '+name+' ENCODING = "UTF8"'
 		return sql