本文整理汇总了Python中storm.locals.Store.find方法的典型用法代码示例。如果您正苦于以下问题:Python Store.find方法的具体用法?Python Store.find怎么用?Python Store.find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类storm.locals.Store
的用法示例。
在下文中一共展示了Store.find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: NCBITaxonomySelector
# 需要导入模块: from storm.locals import Store [as 别名]
# 或者: from storm.locals.Store import find [as 别名]
class NCBITaxonomySelector(object):
def __init__(self):
self.__init_database()
def __init_database(self):
"""
creates the sqlite database instance and checks if the database exists in biodb.
"""
database= create_database("sqlite:%s" % biodb_sql_db_path)
print "Created storm database from %s." % biodb_sql_db_path
self.store= Store(database)
def getTaxaByDivisionID(self, div_id):
return self.store.find(BioDB, \
(NCBITaxonomyDivision.taxonID == BioDB.id) & \
(NCBITaxonomyDivision.divisionID == div_id))
def getDivisionIDByTaxonID(self, tax_id):
return self.store.find(NCBITaxonomyDivision, NCBITaxonomyDivision.taxonID == tax_id).one().divisionID
def getDivisionNameByID(self, div_id):
return self.store.find(NCBIDivision, NCBIDivision.id == div_id).one().name
示例2: do_statspollute
# 需要导入模块: from storm.locals import Store [as 别名]
# 或者: from storm.locals.Store import find [as 别名]
def do_statspollute(dbfile):
# source
gl_database = create_database("sqlite:%s" % dbfile)
source_store = Store(gl_database)
stats = source_store.find(models.Stats)
counter = 0
for s in stats:
source_store.remove(s)
counter += 1
print "removed %d entry in stats" % counter
counter = 0
# 21 days in the past
for past_hours in xrange(24 * 7 * 3):
past_hours += 4
when = utc_past_date(hours=past_hours)
newstat = models.Stats()
newstat.freemb = randint(1000, 1050)
newstat.year = when.isocalendar()[0]
newstat.week = when.isocalendar()[1]
level = round((randint(0, 1000) / 240.0), 1) - 2
def random_pollution():
return int(randint(0,11) + (5 * level))
activity_fake = {
'successfull_logins': random_pollution(),
'failed_logins': random_pollution(),
'started_submissions': random_pollution(),
'completed_submissions': random_pollution(),
'uploaded_files': int(randint(0,11) + (5 * level)),
'appended_files': random_pollution(),
'wb_comments': random_pollution(),
'wb_messages': random_pollution(),
'receiver_comments': random_pollution(),
'receiver_messages': random_pollution()
}
for k, v in activity_fake.iteritems():
if v < 0:
activity_fake[k] = 0
newstat.start = when
newstat.summary = activity_fake
counter += 1
source_store.add(newstat)
print "Committing %d stats" % counter
source_store.commit()
示例3: testCreate
# 需要导入模块: from storm.locals import Store [as 别名]
# 或者: from storm.locals.Store import find [as 别名]
def testCreate(self):
"""Test creation of new MusicTrack"""
store = Store(self.db)
musictrack = models.MusicTrack()
musictrack.title = u"The Beautiful Ones"
store.add(musictrack)
store.commit()
self.assertTrue(Store.of(musictrack) is store)
musictrack_from_database = store.find(models.MusicTrack, models.MusicTrack.title == u"The Beautiful Ones").one()
self.assertTrue(musictrack is musictrack_from_database)
示例4: insert_data
# 需要导入模块: from storm.locals import Store [as 别名]
# 或者: from storm.locals.Store import find [as 别名]
def insert_data(self, scheme):
"""
Return the SQL syntax needed to insert the data already present
in the table.
"""
if scheme is not None:
store = Store(create_database(config.Database().uri[scheme]))
else:
store = Store(create_database(config.Database().uri))
registers = []
rows = store.find(self.model.__class__)
fields = [
r._detect_attr_name(self.model.__class__) for r in
self.model._storm_columns.keys()
]
for r in rows:
tmp_row = {}
for field in fields:
tmp_row[field] = getattr(r, field)
registers.append(tmp_row)
if self.__class__.__name__ == 'MySQL':
commas = '`'
else:
commas = "'"
query = ''
for register in registers:
query += ('INSERT INTO {}{}{} ({}) VALUES ({});\n'.format(
commas,
self.model.__storm_table__,
commas,
', '.join(register.keys()),
', '.join([(
str(field) if type(field) is not unicode
else "'{}'".format(field))
for field in register.values()
])
))
return query
示例5: TestMigrationRegression
# 需要导入模块: from storm.locals import Store [as 别名]
# 或者: from storm.locals.Store import find [as 别名]
class TestMigrationRegression(unittest.TestCase):
def _initStartDB(self, target_ver):
helpers.init_glsettings_for_unit_tests()
GLSettings.db_path = os.path.join(GLSettings.ramdisk_path, 'db_test')
os.mkdir(GLSettings.db_path)
db_name = 'glbackend-%d.db' % target_ver
db_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'db', 'populated', db_name)
shutil.copyfile(db_path, os.path.join(GLSettings.db_path, db_name))
self.db_file = os.path.join(GLSettings.db_path, db_name)
GLSettings.db_uri = GLSettings.make_db_uri(self.db_file)
self.store = Store(create_database(GLSettings.db_uri))
def test_check_field_constraints(self):
# This test case asserts that a migration from db ver 32 up to 34 with
# fields that fail the constraints still functions.
self._initStartDB(32)
field_dict = helpers.get_dummy_field()
field_dict['instance'] = 'reference'
field_dict['step_id'] = None
field_dict['field_id'] = None
db_create_field(self.store, field_dict, u'en')
field_dict = helpers.get_dummy_field()
field_dict['instance'] = 'instance'
db_create_field(self.store, field_dict, u'en')
field_dict = helpers.get_dummy_field()
field_dict['instance'] = 'template'
field_dict['step_id'] = None
fld_grp_id = self.store.find(Field, Field.fieldgroup_id is not None)[0].fieldgroup_id
field_dict['field_id'] = fld_grp_id
db_create_field(self.store, field_dict, u'en')
self.store.commit()
ret = perform_system_update()
shutil.rmtree(GLSettings.db_path)
self.assertNotEqual(ret, -1)
def test_check_unmodifiable_strings(self):
# This test case asserts that data migration updates unmodifiable l10n strings
self._initStartDB(34)
notification_l10n = NotificationL10NFactory(self.store)
t0 = notification_l10n.get_val('export_template', 'ar')
#print notification_l10n.get_val('export_template', 'ar')
notification_l10n.set_val('export_template', 'ar', '')
t1 = notification_l10n.get_val('export_template', 'ar')
self.assertEqual(t1, '')
self.store.commit()
# place a dummy version in the current db
store = Store(create_database(GLSettings.db_uri))
prv = config.PrivateFactory(store)
self.dummy_ver = '2.XX.XX'
prv.set_val('version', self.dummy_ver)
self.assertEqual(prv.get_val('version'), self.dummy_ver)
store.commit()
store.close()
migration.perform_data_update(self.db_file)
# place a dummy version in the current db
store = Store(create_database(GLSettings.db_uri))
notification_l10n = NotificationL10NFactory(store)
t2 = notification_l10n.get_val('export_template', 'ar')
self.assertEqual(t2, t0)
store.commit()
store.close()
shutil.rmtree(GLSettings.db_path)
示例6: IssuesLog
# 需要导入模块: from storm.locals import Store [as 别名]
# 或者: from storm.locals.Store import find [as 别名]
class IssuesLog():
def __init__(self, backend_name):
self.backend_name = backend_name
self.connect()
self.create_db()
def connect(self):
opts = Config()
self.database = create_database('mysql://' + opts.db_user_out + ':'
+ opts.db_password_out + '@'
+ opts.db_hostname_out + ':'
+ opts.db_port_out + '/'
+ opts.db_database_out)
self.store = Store(self.database)
def create_db(self):
print("self.backend_name = %s" % (self.backend_name))
if self.backend_is_bugzilla():
self.store.execute(__sql_table_bugzilla__)
elif self.backend_is_jira():
self.store.execute(__sql_table_jira__)
def copy_issue(self, db_ilog):
"""
This method creates a copy of DBBugzilla/JiraIssuesLog object
"""
if self.backend_is_bugzilla():
aux = DBBugzillaIssuesLog(db_ilog.issue, db_ilog.tracker_id)
aux.issue_id = db_ilog.issue_id
aux.type = db_ilog.type
aux.summary = db_ilog.summary
aux.description = db_ilog.description
aux.status = db_ilog.status
aux.resolution = db_ilog.resolution
aux.priority = db_ilog.priority
aux.submitted_by = db_ilog.submitted_by
aux.date = db_ilog.date
aux.assigned_to = db_ilog.assigned_to
#aux = DBBugzillaIssuesLog (db_ilog.issue_id)
aux.alias = db_ilog.alias
aux.delta_ts = db_ilog.delta_ts
aux.reporter_accessible = db_ilog.reporter_accessible
aux.cclist_accessible = db_ilog.cclist_accessible
aux.classification_id = db_ilog.classification_id
aux.classification = db_ilog.classification
aux.product = db_ilog.product
aux.component = db_ilog.component
aux.version = db_ilog.version
aux.rep_platform = db_ilog.rep_platform
aux.op_sys = db_ilog.op_sys
aux.dup_id = db_ilog.dup_id
aux.bug_file_loc = db_ilog.bug_file_loc
aux.status_whiteboard = db_ilog.status_whiteboard
aux.target_milestone = db_ilog.target_milestone
aux.votes = db_ilog.votes
aux.everconfirmed = db_ilog.everconfirmed
aux.qa_contact = db_ilog.qa_contact
aux.estimated_time = db_ilog.estimated_time
aux.remaining_time = db_ilog.remaining_time
aux.actual_time = db_ilog.actual_time
aux.deadline = db_ilog.deadline
aux.keywords = db_ilog.keywords
aux.cc = db_ilog.cc
aux.group_bugzilla = db_ilog.group_bugzilla
aux.flag = db_ilog.flag
return aux
elif self.backend_is_jira():
aux = DBJiraIssuesLog(db_ilog.issue, db_ilog.tracker_id)
aux.issue_id = db_ilog.issue_id
aux.type = db_ilog.type
aux.summary = db_ilog.summary
aux.description = db_ilog.description
aux.status = db_ilog.status
aux.resolution = db_ilog.resolution
aux.priority = db_ilog.priority
aux.submitted_by = db_ilog.submitted_by
aux.date = db_ilog.date
aux.assigned_to = db_ilog.assigned_to
aux.link = db_ilog.link
aux.component = db_ilog.component
aux.version = db_ilog.version
aux.issue_key = db_ilog.issue_key
aux.environment = db_ilog.environment
aux.project = db_ilog.project
aux.project_key = db_ilog.project_key
aux.security = db_ilog.security
return aux
def get_people_id(self, email, tracker_id):
"""
Gets the id of an user
"""
p = self.store.find(DBPeople, DBPeople.email == email).one()
#.........这里部分代码省略.........
示例7: __init__
# 需要导入模块: from storm.locals import Store [as 别名]
# 或者: from storm.locals.Store import find [as 别名]
#.........这里部分代码省略.........
#
# print "Requested version %d of %s need to be collected in the past" %\
# (version, table_name)
while version >= 0:
if self.table_history[table_name][table_index]:
# print ".. returning %s = %s" %\
# ( table_name, self.table_history[table_name][table_index] )
return self.table_history[table_name][table_index]
table_index -= 1
# This never want happen
return None
def get_right_sql_version(self, model_name, version):
"""
@param model_name:
@param version:
@return:
The SQL right for the stuff we've
"""
modelobj = self.get_right_model(model_name, version)
if not modelobj:
return None
right_query = generateCreateQuery(modelobj)
return right_query
def _perform_copy_list(self, table_name):
print "%s default %s migration assistant: #%d" % (
self.debug_info, table_name,
self.store_old.find(self.get_right_model(table_name, self.start_ver)).count())
old_objects = self.store_old.find(self.get_right_model(table_name, self.start_ver))
for old_obj in old_objects:
new_obj = self.get_right_model(table_name, self.start_ver + 1)()
# Storm internals simply reversed
for k, v in new_obj._storm_columns.iteritems():
setattr(new_obj, v.name, getattr(old_obj, v.name) )
self.store_new.add(new_obj)
self.store_new.commit()
def _perform_copy_single(self, table_name):
print "%s default %s migration assistant" % (self.debug_info, table_name)
old_obj = self.store_old.find(self.get_right_model(table_name, self.start_ver)).one()
new_obj = self.get_right_model(table_name, self.start_ver + 1)()
# Storm internals simply reversed
for k, v in new_obj._storm_columns.iteritems():
setattr(new_obj, v.name, getattr(old_obj, v.name) )
self.store_new.add(new_obj)
self.store_new.commit()
def migrate_Context(self):
self._perform_copy_list("Context")
def migrate_Node(self):
self._perform_copy_single("Node")
示例8: StormStorageBackend
# 需要导入模块: from storm.locals import Store [as 别名]
# 或者: from storm.locals.Store import find [as 别名]
class StormStorageBackend(StorageBackend):
"""Storage back-end based on the Storm ORM framework."""
def __init__(self):
self.store = None
def set_config(self, **kwargs):
"""Set the configuration of this back-end."""
uri = kwargs['uri']
database = create_database(uri)
self.store = Store(database)
self.logger = logging.getLogger('StormStorageBackend')
handler = logging.StreamHandler()
formatter = logging.Formatter(kwargs['log_format'])
handler.setFormatter(formatter)
self.logger.addHandler(handler)
self.logger.setLevel(
logging.__getattribute__(kwargs['log_level']))
def create_node(self, node, jid, node_config):
"""Create a PubSub node with the given configuration.
Creates the Node, NodeConfig, Affiliation and Subscription model for
the given node.
"""
self.logger.debug('Creating node %s for jid %s with config %s' %
(node, jid, node_config))
new_node = Node(node)
self.store.add(new_node)
config = copy.deepcopy(DEFAULT_CONFIG)
config.update(node_config)
for key, value in config.items():
new_node_config = NodeConfig(node, key, value)
new_node_config.updated = datetime.utcnow()
self.store.add(new_node_config)
affiliation = Affiliation(node, jid, u'owner', datetime.utcnow())
self.store.add(affiliation)
subscription = Subscription(node, jid, jid, u'subscribed',
datetime.utcnow())
self.store.add(subscription)
def create_channel(self, jid):
"""Create a channel for the given JID.
Creates all the required PubSub nodes that constitute a channel, with
the appropriate permissions.
"""
self.logger.debug('Creating channel for %s' % jid)
creation_date = unicode(datetime.utcnow().isoformat())
self.create_node(u'/user/%s/posts' % jid, jid,
{u'channelType': u'personal',
u'creationDate': creation_date,
u'defaultAffiliation': u'publisher',
u'description': u'buddycloud channel for %s' % jid,
u'title': jid})
self.create_node(u'/user/%s/geo/current' % jid, jid,
{u'creationDate': creation_date,
u'description': u'Where %s is at now' % jid,
u'title': u'%s Current Location' % jid})
self.create_node(u'/user/%s/geo/next' % jid, jid,
{u'creationDate': creation_date,
u'description': u'Where %s intends to go' % jid,
u'title': u'%s Next Location' % jid})
self.create_node(u'/user/%s/geo/previous' % jid, jid,
{u'creationDate': creation_date,
u'description': u'Where %s has been before' % jid,
u'title': u'%s Previous Location' % jid})
self.create_node(u'/user/%s/status' % jid, jid,
{u'creationDate': creation_date,
u'description': u'M000D',
u'title': u'%s status updates' % jid})
self.create_node(u'/user/%s/subscriptions' % jid, jid,
{u'creationDate': creation_date,
u'description': u'Browse my interests',
u'title': u'%s subscriptions' % jid})
self.store.commit()
def get_node(self, node):
"""Get the requested PubSub node."""
self.logger.debug('Getting node %s' % node)
the_node = self.store.get(Node, node)
self.logger.debug('Returning node %s' % the_node)
return the_node
def get_nodes(self):
"""Get a list of all the available PubSub nodes."""
self.logger.debug('Getting list of available nodes.')
node_list = self.store.find(Node)
self.logger.debug('Returning list of available node %s' % node_list)
return node_list
def add_item(self, node, item_id, item):
"""Add an item to the requested PubSub node."""
new_item = Item(node, unicode(item_id), datetime.utcnow(), item)
self.store.add(new_item)
self.store.commit()
def shutdown(self):
"""Shut down this storage module - flush, commit and close the
store."""
#.........这里部分代码省略.........
示例9: TableReplacer
# 需要导入模块: from storm.locals import Store [as 别名]
# 或者: from storm.locals.Store import find [as 别名]
#.........这里部分代码省略.........
if version > DATABASE_VERSION:
raise ValueError('Version supplied must be less or equal to {}'.format(
DATABASE_VERSION))
if self.table_history[table_name][table_index]:
return self.table_history[table_name][table_index]
# else, it's none, and we've to take the previous valid version
while version >= 0:
if self.table_history[table_name][table_index]:
return self.table_history[table_name][table_index]
table_index -= 1
# This never want happen
return None
def get_right_sql_version(self, model_name, version):
"""
@param model_name:
@param version:
@return:
The SQL right for the stuff we've
"""
modelobj = self.get_right_model(model_name, version)
if not modelobj:
return None
right_query = generateCreateQuery(modelobj)
return right_query
def _perform_copy_list(self, table_name):
objs_count = self.store_old.find(
self.get_right_model(table_name, self.start_ver)
).count()
log.msg('{} default {} migration assistant: #{}'.format(
self.debug_info, table_name, objs_count))
old_objects = self.store_old.find(self.get_right_model(table_name, self.start_ver))
for old_obj in old_objects:
new_obj = self.get_right_model(table_name, self.start_ver + 1)()
# Storm internals simply reversed
for _, v in new_obj._storm_columns.iteritems():
setattr(new_obj, v.name, getattr(old_obj, v.name))
self.store_new.add(new_obj)
self.store_new.commit()
def _perform_copy_single(self, table_name):
log.msg('{} default {} migration assistant'.format(self.debug_info, table_name))
old_obj = self.store_old.find(self.get_right_model(table_name, self.start_ver)).one()
new_obj = self.get_right_model(table_name, self.start_ver + 1)()
# Storm internals simply reversed
for _, v in new_obj._storm_columns.iteritems():
setattr(new_obj, v.name, getattr(old_obj, v.name))
self.store_new.add(new_obj)
self.store_new.commit()
def migrate_Context(self):
示例10: TestChangeTracker
# 需要导入模块: from storm.locals import Store [as 别名]
# 或者: from storm.locals.Store import find [as 别名]
class TestChangeTracker(object):
class A(object):
__storm_table__ = 'testob'
changehistory = ChangeHistory.configure("history")
clt = ChangeTracker(changehistory)
id = Int(primary=1)
textval = Unicode(validator=clt)
intval = Int(validator=clt)
def setUp(self):
database = create_database('sqlite:')
self.store = Store(database)
self.store.execute("""
CREATE table history (
id INTEGER PRIMARY KEY AUTOINCREMENT,
ref_class VARCHAR(200),
ref_pk VARCHAR(200),
ref_attr VARCHAR(200),
new_value VARCHAR(200),
ctime DATETIME,
cuser INT
)
""")
self.store.execute("""
CREATE TABLE testob (
id INTEGER PRIMARY KEY AUTOINCREMENT,
textval VARCHAR(200),
intval INT,
dateval DATETIME
)""")
def tearDown(self):
self.store.rollback()
def test_calls_next_validator(self):
clt = ChangeTracker(ChangeHistory.configure("history"), next_validator = lambda ob, attr, v: v*2)
class B(self.A):
textval = Unicode(validator=clt)
b = B()
b.textval = u'bork'
assert b.textval == u'borkbork'
def test_adds_log_entries(self):
class B(self.A):
clt = ChangeTracker(ChangeHistory.configure("history"))
textval = Unicode(validator=clt)
b = self.store.add(B())
b.textval = u'pointless'
b.textval = u'aimless'
changes = list(self.store.find(b.clt.change_cls))
assert_equal(len(changes), 2)
assert_equal(changes[0].new_value, 'pointless')
assert_equal(changes[1].new_value, 'aimless')
def test_value_type_preserved(self):
a = self.store.add(self.A())
a.textval = u'one'
a.intval = 1
changes = list(self.store.find(a.clt.change_cls))
assert_equal(type(changes[0].new_value), unicode)
assert_equal(type(changes[1].new_value), int)
def test_ctime_set(self):
start = datetime.now()
a = self.store.add(self.A())
a.textval = u'x'
changes = list(self.store.find(a.clt.change_cls))
assert_equal(type(changes[0].ctime), datetime)
assert start < changes[0].ctime < datetime.now()
def test_cuser_set(self):
def getuser():
return u'Fred'
history = ChangeHistory.configure("history", getuser=getuser, usertype=Unicode)
class B(self.A):
textval = Unicode(validator=ChangeTracker(history))
b = self.store.add(B())
b.textval = u'foo'
changes = self.store.find(history)
assert_equal(changes[0].cuser, u'Fred')
def test_changes_for_returns_change_history(self):
a = self.store.add(self.A())
b = self.store.add(self.A())
a.id = 1
a.textval = u'one'
a.textval = u'two'
b.id = 2
b.textval = u'ein'
b.textval = u'zwei'
#.........这里部分代码省略.........
示例11: loadClassFromFile
# 需要导入模块: from storm.locals import Store [as 别名]
# 或者: from storm.locals.Store import find [as 别名]
name VARCHAR,
age INTEGER
)''')
# Loading a table
def loadClassFromFile( class_, store, fileHandle ):
# Guess the appropriate CSV dialect by reading the first 5 lines
dialect = csv.Sniffer().sniff(
'\n'.join( fileHandle.readlines()[0:2] )
)
fileHandle.seek(0)
reader = csv.DictReader(fileHandle, dialect=dialect)
for line in reader:
store.add( Person.from_dict(line) )
with open( 'persons.csv', 'rb' ) as f:
loadClassFromFile( Person, store, f )
for person in store.find(Person, Person.age <= 30):
print person
# Optional file cleaning method
def clean():
import glob
import os
for fname in glob.glob( '*.csv' ):
os.remove( fname )
clean() # Comment if you want to keep the files
示例12: __repr__
# 需要导入模块: from storm.locals import Store [as 别名]
# 或者: from storm.locals.Store import find [as 别名]
x = self.x,
y = self.y
)
def __repr__( self ):
return '<Point2D x:%s, y:%s>' % (
self.x,
self.y
)
database = create_database('sqlite://:memory:')
store = Store(database)
store.execute('''CREATE TABLE point2d (
id INTEGER PRIMARY KEY,
x INTEGER,
y INTEGER
)''')
p1 = Point2D(10,10)
p2 = Point2D(10,20)
p3 = Point2D(20,20)
p4 = Point2D(20,10)
store.add( p1 )
store.add( p2 )
store.add( p3 )
store.add( p4 )
points = store.find(Point2D, Point2D.x == 10)
print points[0] + points[1]
示例13: StormORM
# 需要导入模块: from storm.locals import Store [as 别名]
# 或者: from storm.locals.Store import find [as 别名]
class StormORM(ORM):
"""
Storm implementation of ORM super class.
"""
def __init__(self, uri=None, store=None):
'''
@param uri: Database URI following storm rules.
@param store: Storm store.
If uri is given a new store is instanciated and it is used
to execute the statements.
If both parameters are given the early created store overrides
the store given.
'''
from storm.locals import create_database, Store
self.uri = uri
self.store = store
if self.uri:
database = create_database(self.uri)
self.store = Store(database)
if not self.store:
raise Exception('None storm store')
self.attrParser = StormAttributeParser()
def _getObject(self, csvType, csvStatement):
"""
Retrieves the object to be used at statement execution.
@param csvType: The CSVType
@param csvStatement: The CSVStatement
@return: The object early instanciated (for insert statement) or
retrieved from database (for update or delete statements).
"""
typo = csvType.type
keys = csvType.keys
attributes = csvStatement.attributes
if csvStatement.action in [DELETE, UPDATE]:
if csvType.hasPrimaryKey:
return self.store.get(typo, attributes[ csvType.primaryKey[0] ])
else:
pred = And([Eq(typo, key, attributes[i]) for i,key in keys.iteritems()])
result = self.store.find(typo, pred)
if result.count() == 0:
return None
elif result.count() == 1:
return result.one()
else:
return [r for r in result]
elif csvStatement.action is INSERT:
return typo()
def executeStatement(self, csvType, csvStatement):
"""
Executes csv statements matched by the pair csvType, csvStatement.
@param csvType: The CSVType
@param csvStatement: The CSVStatement
@return: Total statements executed or raises a ValueError if the object retrieved with
the pair csvType, csvStatement is None.
"""
obj = self._getObject(csvType, csvStatement)
if not obj:
msg = 'Statement return None in line %d: %s' % (csvStatement.lineNumber, csvStatement.lineContent)
raise ValueError(msg)
objs = []
if type(obj) is list:
objs += obj
else:
objs.append(obj)
i = 0
for _obj in objs:
self._executeStatement(_obj, csvType, csvStatement)
i += 1
return i
def _executeStatement(self, obj, csvType, csvStatement):
"""
Executes a single csv statement
@param csvType: The CSVType
@param csvStatement: The CSVStatement
"""
keys = csvType.keys
attributes = csvType.attributes
values = csvStatement.attributes
if csvStatement.action is INSERT:
pairs = [(key, values[i]) for i,key in keys.iteritems()]
pairs += [(key, values[i]) for i,key in attributes.iteritems()]
for key, value in pairs:
setattr(obj, key, value)
self.store.add(obj)
elif csvStatement.action is UPDATE:
pairs = [(key, values[i]) for i,key in attributes.iteritems()]
#.........这里部分代码省略.........
示例14: __init__
# 需要导入模块: from storm.locals import Store [as 别名]
# 或者: from storm.locals.Store import find [as 别名]
class IssuesLog:
def __init__(self, backend_name):
self.backend_name = backend_name
self.connect()
self.create_db()
def connect(self):
opts = Config()
self.database = create_database(
"mysql://"
+ opts.db_user_out
+ ":"
+ opts.db_password_out
+ "@"
+ opts.db_hostname_out
+ ":"
+ opts.db_port_out
+ "/"
+ opts.db_database_out
)
self.store = Store(self.database)
def create_db(self):
self.store.execute(__sql_table__)
def copy_issue(self, db_ilog):
"""
This method is create a copy of a DBIssueLog object
"""
aux = DBIssuesLog(db_ilog.issue, db_ilog.tracker_id)
aux.issue_id = db_ilog.issue_id
aux.type = db_ilog.type
aux.summary = db_ilog.summary
aux.description = db_ilog.description
aux.status = db_ilog.status
aux.resolution = db_ilog.resolution
aux.priority = db_ilog.priority
aux.submitted_by = db_ilog.submitted_by
aux.date = db_ilog.date
aux.assigned_to = db_ilog.assigned_to
return aux
def build_initial_state(self, db_ilog):
"""
This method gets the first changes of every field in
order to get the initial state of the bug
"""
fields = self.store.execute("SELECT DISTINCT(field) FROM changes where issue_id=%s" % (db_ilog.issue_id))
for f in fields:
value = self.store.execute(
'SELECT old_value FROM changes WHERE issue_id=%s AND field="%s" ORDER BY changed_on LIMIT 1'
% (db_ilog.issue_id, f[0])
)
for v in value:
# Bugzilla section
#
if f[0] in bg_issues_links:
table_field = bg_issues_links[f[0]]
if table_field == "summary":
db_ilog.summary = v[0]
elif table_field == "priority":
db_ilog.priority = v[0]
elif table_field == "assigned_to":
db_ilog.assigned_to = v[0]
elif table_field == "status":
db_ilog.status = v[0]
elif table_field == "resolution":
db_ilog.resolution = v[0]
return db_ilog
def run(self):
issues = self.store.find(DBIssue)
for i in issues:
db_ilog = DBIssuesLog(i.issue, i.tracker_id)
db_ilog.issue_id = i.id
db_ilog.type = i.type
db_ilog.summary = i.summary
db_ilog.description = i.description
db_ilog.status = i.status
db_ilog.resolution = i.resolution
db_ilog.priority = i.priority
db_ilog.submitted_by = i.submitted_by
db_ilog.date = i.submitted_on
db_ilog.assigned_to = i.assigned_to
db_ilog = self.build_initial_state(db_ilog)
self.store.add(db_ilog)
# the code below gets all the changes and insert a row per change
changes = self.store.execute(
"SELECT field, new_value, changed_by, changed_on FROM changes where issue_id=%s" % (db_ilog.issue_id)
)
for ch in changes:
field = ch[0]
new_value = ch[1]
changed_by = ch[2]
#.........这里部分代码省略.........
示例15: IssuesLog
# 需要导入模块: from storm.locals import Store [as 别名]
# 或者: from storm.locals.Store import find [as 别名]
class IssuesLog():
def __init__(self):
self._connect()
# it is not incremental so we first drop the table
self._drop_db()
self._create_db()
def _connect(self):
opts = Config()
self.database = create_database('mysql://' + opts.db_user_out + ':'
+ opts.db_password_out + '@'
+ opts.db_hostname_out + ':'
+ opts.db_port_out + '/'
+ opts.db_database_out)
self.store = Store(self.database)
def _create_db(self):
self.store.execute(self._get_sql_create())
def _drop_db(self):
self.store.execute(self._get_sql_drop())
def _get_people_id(self, email):
"""
Gets the id of an user
"""
try:
p = self.store.find(DBPeople, DBPeople.email == email).one()
return p.id
except (AttributeError, NotOneError):
p = self.store.find(DBPeople, DBPeople.user_id == email).one()
try:
return p.id
except AttributeError:
# no person was found in People with the email above, so
# we include it
printdbg("Person not found. Inserted with email %s " % (email))
dp = DBPeople(email)
self.store.add(dp)
self.store.commit()
return dp.id
def _get_sql_drop(self):
"""
Abstract method for inserting extra data related to a change
"""
raise NotImplementedError
def _get_sql_create(self):
"""
Abstract method for inserting extra data related to a change
"""
raise NotImplementedError
def _get_tracker_id(self, issue_id):
"""
Returns tracker id from issues
"""
result = self.store.find(DBIssue.tracker_id,
DBIssue.id == issue_id).one()
return result
def _copy_issue_ext(self, aux, db_ilog):
"""
Abstract method for inserting extra data related to a change
"""
raise NotImplementedError
# TODO: reuse _copy_standard_values
def _copy_issue(self, db_ilog):
"""
This method returns a copy of the DB*Log object
"""
aux = self._get_dbissues_object(db_ilog.issue, db_ilog.tracker_id)
aux.issue_id = db_ilog.issue_id
aux.change_id = db_ilog.change_id
aux.changed_by = db_ilog.changed_by
aux.type = db_ilog.type
aux.summary = db_ilog.summary
aux.description = db_ilog.description
aux.status = db_ilog.status
aux.resolution = db_ilog.resolution
aux.priority = db_ilog.priority
aux.submitted_by = db_ilog.submitted_by
aux.date = db_ilog.date
aux.assigned_to = db_ilog.assigned_to
aux = self._copy_issue_ext(aux, db_ilog)
return aux
def _assign_values(self, db_ilog, field, value):
"""
Abstract method for inserting extra data related to a change
"""
raise NotImplementedError
def _build_initial_state(self, db_ilog):
"""
This method gets the first changes of every field in
#.........这里部分代码省略.........