def __init__(self, method): self.method = method self.instance = None self.debug = GLSettings.orm_debug if self.debug: tracer.debug(self.debug, sys.stdout)
def setupStore(): avatar_store.__init__(create_database(config['db'])) if config.get('trace'): import sys from storm.tracer import debug debug(True, stream=sys.stdout) # Only sqlite uses this now sqlBundle = getCreationSQL(avatar_store) if not sqlBundle: return tableExists = sql['tableExists'] = sqlBundle['tableExists'] for (table, creationSQL) in sqlBundle['creations']: if not tableExists(avatar_store, table): # Unlike log.message, this works during startup print "~~~ Creating Warp table '%s'" % table if not isinstance(creationSQL, tuple): creationSQL = [creationSQL] for sqlCmd in creationSQL: avatar_store.execute(sqlCmd) avatar_store.commit()
def create_and_run_worker(dsn, lock_timeout, update_timeout, retry_timeout, log_sql=False): """ Instantiates and starts a worker, returns the result of Worker.run() """ if log_sql: from storm.tracer import debug debug(True, stream=sys.stdout) from feedcache.worker import Worker # required for pp worker = Worker(dsn, lock_timeout, update_timeout, retry_timeout) return worker.run()
def __init__(self, database_file=None): if not self.instance: print "Initializing Config with saved arguments" else: print "Reconfiguring Config instance" self.debug = OD() # 'testing' is present, GUS are incremental cmdline_opt = sys.argv if 'testing' in cmdline_opt: self.debug.testing = True else: self.debug.testing = False # 'db' is present, Storm debug enabed if 'db' in cmdline_opt: debug(True, sys.stdout) else: debug(False, sys.stdout) # 'verbose' is present, show JSON receiver messages if 'verbose' in cmdline_opt: self.debug.verbose = True else: self.debug.verbose = False self.advanced = OD() self.advanced.debug = True self.main = OD() self.main.glclient_path = get_glclient_path() if self.advanced.debug: print "Serving GLClient from %s" % self.main.glclient_path # This is the zstorm store used for transactions if database_file: self.main.database_uri = 'sqlite:'+database_file else: self.main.database_uri = 'sqlite:'+get_db_file('glbackend.db') self.main.zstorm = ZStorm() self.main.zstorm.set_default_uri('main_store', self.main.database_uri) self.advanced.db_thread_pool_size = 1 self.advanced.scheduler_thread_pool_size = 10 self.advanced.data_dir = os.path.join(get_root_path(), '_gldata') self.advanced.submissions_dir = os.path.join(self.advanced.data_dir, 'submissions') self.advanced.delivery_dir = os.path.join(self.advanced.data_dir, 'delivery')
def __init__(self, filename, debug=False): if debug: import sys from storm.tracer import debug debug(True, stream=sys.stdout) self._filename = filename create = False if not os.path.exists(self._filename): create = True self._db = create_database('sqlite:%s' % self._filename) if create: self._create()
def init(cfg): global pool, database if 'debug' in cfg: debug = cfg.pop('debug') else: debug = False tracer.debug(debug) values = dict(driver = 'mysql', host = 'localhost', db = 'yaru_bot', user = '******', passwd = 'yaru_bot') values.update(cfg) uri = '%(driver)s://%(user)s:%(passwd)s@%(host)s/%(db)s' % values database = create_database(uri) pool = StorePool(database) return pool.start()
def setupStore(): avatar_store.__init__(create_database(config['db'])) if config.get('trace'): import sys from storm.tracer import debug debug(True, stream=sys.stdout) sqlBundle = getCreationSQL(avatar_store) tableExists = sql['tableExists'] = sqlBundle['tableExists'] for (table, creationSQL) in sqlBundle['creations']: if not tableExists(avatar_store, table): # Unlike log.message, this works during startup print "~~~ Creating Warp table '%s'" % table if not isinstance(creationSQL, tuple): creationSQL = [creationSQL] for sqlCmd in creationSQL: avatar_store.execute(sqlCmd) avatar_store.commit()
def init(cfg): global pool, database if 'debug' in cfg: debug = cfg.pop('debug') else: debug = False tracer.debug(debug) values = dict(driver='mysql', host='localhost', db='yaru_bot', user='******', passwd='yaru_bot') values.update(cfg) uri = '%(driver)s://%(user)s:%(passwd)s@%(host)s/%(db)s' % values database = create_database(uri) pool = StorePool(database) return pool.start()
def test_remove_debug(self): debug(True) debug(True) debug(False) self.assertEquals(get_tracers(), [])
def test_wb_install_debug_with_custom_stream(self): marker = object() debug(True, marker) [tracer] = get_tracers() self.assertEquals(tracer._stream, marker)
def test_install_debug(self): debug(True) debug(True) self.assertEquals([type(x) for x in get_tracers()], [DebugTracer])
from nsti import app import logging import datetime import storm.locals as SL import filters from flask import session from storm.tracer import debug import storm.store import storm.expr debug(False) # The flag enables or disables statement logging LIMIT = app.config.get('PERPAGE', 50) #~ Setup our DB connect string for Storm db_connect = '%s://%s:%s@%s:%s/%s' % (app.config.get('DB_TYPE'), app.config.get('DB_USER'), app.config.get('DB_PASS'), app.config.get('DB_HOST'), app.config.get('DB_PORT'), app.config.get('DB_NAME')) #~ Establish the database connection def database_monitor(): try: DATABASE = SL.create_database(db_connect) DB = SL.Store(DATABASE) except DisconnectionError:
def main(): ########################################################################### # Configure the parser ########################################################################### from optparse import OptionParser parser = OptionParser( usage="%prog [options]", version=__version__, description="""This script commits new tag to TSDB.""") parser.add_option( "--db", type="string", help="TSDB connection string in the form: 'sqlite:path'.") parser.add_option( "-i", "--input", type="string", help="Input file which contains string dictionary of tags to update.") # parse command line options, args = parser.parse_args() ########################################################################### # Prepare local logger ########################################################################### import logging log = logging.getLogger(parser.prog or os.path.basename(sys.argv[0])) log.setLevel(logging.INFO) # set the global stream handler from CondDBUI import LOG_FORMAT hndlr = logging.StreamHandler() hndlr.setFormatter(logging.Formatter(LOG_FORMAT)) logging.getLogger().handlers = [hndlr] ########################################################################### # Check and set options ########################################################################### db_ConnStr = options.db if db_ConnStr == None: parser.error("Please specify TSDB location. Try with --help.") file = options.input if not file: parser.error("Please specify an input file. Try with --help.") ########################################################################### # Update TSDB ########################################################################### # Open TSDB.db and commit new tag there from storm.tracer import debug debug(True, stream=sys.stdout) # Load tag entries to be updated f = open(file) tags_to_update = pickle.load(f) log.info("Connecting to TSDB ...") db = TagStatusDB(db_ConnStr) log.info("Modifying TSDB ...") for partition in tags_to_update.keys(): for tag in tags_to_update[partition]: tag_status = db.getTagStatus(tag["TagName"], unicode(partition), tag["Site"]) tag_status.time = tag["Time"] tag_status.status = tag["Status"] db.write() log.info("Done!")
def test_wb_install_debug_with_custom_stream(cleanup_tracers): marker = object() debug(True, marker) [tracer] = get_tracers() assert tracer._stream == marker
from nsti import app import logging import datetime import storm.locals as SL import filters from flask import session from storm.tracer import debug import storm.store import storm.expr debug(False) # The flag enables or disables statement logging LIMIT = app.config.get('PERPAGE', 50) #~ Setup our DB connect string for Storm db_connect = '%s://%s:%s@%s:%s/%s' % ( app.config.get('DB_TYPE'), app.config.get('DB_USER'), app.config.get('DB_PASS'), app.config.get('DB_HOST'), app.config.get('DB_PORT'), app.config.get('DB_NAME')) #~ Establish the database connection DATABASE = SL.create_database(db_connect) DB = SL.Store(DATABASE) class Snmptt(object): __storm_table__ = 'snmptt' id = SL.Int(primary=True) eventname = SL.Unicode() eventid = SL.Unicode()
# Configuration file do not contain GlobaLeaks Node information, like in the 0.1 # because all those infos are stored in the databased. # Config contains some system variables usable for debug, integration with APAF and # nothing in the common concern af a GlobaLeaks Node Admin import os from cyclone.util import ObjectDict as OD import transaction from storm.zope.zstorm import ZStorm from storm.tracer import debug import sys #Storm DB dump: debug(False, sys.stdout) from globaleaks.utils.singleton import Singleton from globaleaks.utils.singleton import Singleton class ConfigError(Exception): pass def get_root_path(): this_directory = os.path.dirname(__file__) root = os.path.join(this_directory, '..') root = os.path.abspath(root) return root def get_install_path():
import unittest from unittest import TestCase from storm.locals import * from webpy.dark import * from model.company import * from model.trans2 import * from model.users import * from model.report import Report import datetime from decimal import Decimal as Dec import sys from storm.tracer import debug debug(False, stream=sys.stdout) class TestReport(TestCase): def fstore(self, obj): """ Fake store so it's easy to delete all created objects """ self.objs.append(obj) x = self.store.add(obj) return x def setUp(self): self.store = get_store() self.objs = []
def setUp(self): super(TestFeatureFlags, self).setUp() if os.environ.get("STORM_TRACE", None): from storm.tracer import debug debug(True)
print "'OPTIONS' is one of:" print '' print 'create_user <email> <name> New user' print 'create_admin <email> <name> New admin' print 'create_vendor <email> <name> New vendor/salesperson' print 'create_customer <email> <name> New customer' print 'dbinit Execute the SQL, recreate the schema.' print 'dbexample Fill database with examples.' print 'test Execute tests' print '--sql Show sql commands' print '--console Enter console mode' print '' if '--sql' in sys.argv: debug(True, stream=sys.stdout) user_cmd = ['create_user', 'create_admin', 'create_vendor', 'create_customer'] user_create = [c for c in user_cmd if c in sys.argv] if user_create: option_index = sys.argv.index(user_create[0]) user = User() user.email = unicode(sys.argv[option_index+1]) user.name = unicode(sys.argv[option_index+2]) user.set_password(unicode(raw_input('password: '******'create_admin' in sys.argv: admin = Admin()
from webpy.dark import * from model.trans2 import * import sys from storm.locals import * from storm.tracer import debug from decimal import Decimal as Dec class Foo(Storm): __storm_table__ = 'foo' id = Int(primary=True) a = Decimal() debug(True, stream=sys.stdout) store = get_store() #store.execute('create table foo (id serial, a decimal)') blah = store.add(Foo()) blah.a = Dec('100.00') store.commit()
def test_install_debug(cleanup_tracers): debug(True) debug(True) assert [type(x) for x in get_tracers()] == [DebugTracer]
def test_remove_debug(cleanup_tracers): debug(True) debug(True) debug(False) assert get_tracers() == []