def rollback(self): if self.conn: try: self.conn.rollback() #except MySQLdb.OperationalError: except OperationalError, e: logging.getLogger().warn('execute insert sql: %s' % e) self.conn = None
def update(self, *a, **kw): cursor = None try: cursor = self.execute(*a, **kw) self.commit() row_count = cursor.rowcount return row_count #except MySQLdb.OperationalError: except OperationalError, e: logging.getLogger().warn('execute insert sql: %s' % e) self.rollback()
def insert(self, *a, **kw): cursor = None try: cursor = self.execute(*a, **kw) row_id = cursor.lastrowid self.commit() return row_id #except MySQLdb.IntegrityError: except IntegrityError, e: logging.getLogger().warn('execute insert sql: %s' % e) self.rollback()
def connect_db(cfg): try: conn = MySQLdb.connect(host=cfg['DB_HOST'], port=cfg['DB_PORT'], user=cfg['DB_USER'], passwd=cfg['DB_PASS'], db=cfg['DB_NAME'], use_unicode=True, charset="utf8") return conn except Exception, e: logging.getLogger().critical('connect db: %s' % e) return None
def connect_db(cfg): try: conn = MySQLdb.connect( host=cfg['DB_HOST'], port=cfg['DB_PORT'], user=cfg['DB_USER'], passwd=cfg['DB_PASS'], db=cfg['DB_NAME'], use_unicode=True, charset="utf8") return conn except Exception, e: logging.getLogger().critical('connect db: %s' % e) return None
def connect_db(cfg): try: if postgresql: conn = psycopg2.connect(host=cfg['DB_HOST'], port=cfg['DB_PORT'], user=cfg['DB_USER'], password=cfg['DB_PASS'], database=cfg['DB_NAME'], client_encoding="UTF-8") if mysql: conn = MySQLdb.connect(host=cfg['DB_HOST'], port=cfg['DB_PORT'], user=cfg['DB_USER'], passwd=cfg['DB_PASS'], db=cfg['DB_NAME'], use_unicode=True, charset="utf8") return conn except Exception, e: logging.getLogger().critical('connect db: %s' % e) return None
# Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. __author__ = 'Ulric Qin' from rrd import app from rrd import config from flask import render_template, request, g from rrd.model.portal.host_group import HostGroup from rrd.utils.logger import logging log = logging.getLogger(__file__) @app.route('/portal/hostgroup', methods=["GET",]) def home_get(): page = int(request.args.get('p', 1)) limit = int(request.args.get('limit', 10)) query = request.args.get('q', '').strip() mine = request.args.get('mine', '0') me = g.user.name if mine == '1' else None vs, total = HostGroup.query(page, limit, query, me) log.debug(vs) return render_template( 'portal/group/index.html', data={ 'vs': vs, 'total': total,
# limitations under the License. import json import requests from flask import g, redirect, session, abort, request from functools import wraps from rrd import config from rrd import corelib from rrd.utils import randbytes from rrd.model.user import User, UserToken from rrd.utils.logger import logging log = logging.getLogger(__file__) def remote_ip(): if not request.headers.getlist("X-Forward-For"): return request.remote_addr else: return request.headers.getlist("X-Forward-For")[0] def require_login(redir="/auth/login"): def _(f): @wraps(f) def __(*a, **kw): if not g.user: return redirect(redir or "/auth/login") return f(*a, **kw) return __