-
Notifications
You must be signed in to change notification settings - Fork 1
/
common.py
76 lines (63 loc) · 1.29 KB
/
common.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import sys
import os
import cPickle
import time
import urllib2
import signal
import commands
import errno
import zlib, fcntl
import multiprocessing
try:
import MySQLdb as sqldb
except:
import pymysql as sqldb
from datetime import datetime
import re
from urlparse import urlparse, urljoin
from functools import wraps
from logger import *
from config import *
logger= logging.getLogger("logging")
#logger.debug("Register guard %s,%s",nid,self.tb_guards[nid].__dict__)
def run_sql_no_return(sql,conn):
"""
Execute a SQL statement; no value returns
"""
cur=conn.cursor()
try:
cur.execute(sql)
conn.commit()
except Exception, e:
logger.error("SQL ERROR: %s",e)
cur.close()
conn.close()
def run_sql_bulk_no_return(sql, param,conn):
"""
Execute a set of SQL statements; no values return
"""
cur=conn.cursor()
try:
cur.executemany(sql,param)
conn.commit()
except Exception, e:
logger.error("SQL ERROR: %s",e)
cur.close()
conn.close()
def run_sql_with_return(sql,conn):
"""
Execute a SQL statement and get return values
"""
cur=conn.cursor()
cur.execute(sql)
res=cur.fetchall()
cur.close()
return res
def export_res(res,dst_file):
f=open(dst_file,"w")
cPickle.dump(res,f)
f.close()
def import_res(src_file):
return cPickle.load(open(src_file))
if __name__ == '__main__':
pass