当前位置: 首页>>代码示例>>Python>>正文


Python Store.flush方法代码示例

本文整理汇总了Python中storm.locals.Store.flush方法的典型用法代码示例。如果您正苦于以下问题:Python Store.flush方法的具体用法?Python Store.flush怎么用?Python Store.flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在storm.locals.Store的用法示例。


在下文中一共展示了Store.flush方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Sale

# 需要导入模块: from storm.locals import Store [as 别名]
# 或者: from storm.locals.Store import flush [as 别名]
for description, price, date in [
    ('Cup of coffee', 2.04, today - datetime.timedelta(1)),
    ('Chocolate bar', 1.85, today - datetime.timedelta(40)),
    ('Candy',         0.99, today - datetime.timedelta(30)),
    ('Grape Juice',   3.38, today - datetime.timedelta(23)),
    ('Ice tea',       1.25, today - datetime.timedelta(10)),
    ('Cookies',       0.85, today - datetime.timedelta(5)),
    ('Noogies',       1.45, today - datetime.timedelta(2)),
    ('Chocolate bar', 1.85, today)]:

    s = Sale()
    s.description=unicode(description)
    s.price=price
    s.date=date
    store.add(s)
    store.flush()


class PurchaseViewer(gtk.Window):
    def __init__(self):
        gtk.Window.__init__(self)
        self.set_title('Purchases')
        self.search = SearchContainer(self.get_columns())
        self.search.set_summary_label('price')
        self.add(self.search)
        self._setup_searching()
        self._create_filters()

    def _setup_searching(self):
        self.query = StormQueryExecuter(store)
        self.search.set_query_executer(self.query)
开发者ID:gxela,项目名称:kiwi-gtk,代码行数:33,代码来源:search_storm.py

示例2: IssuesLog

# 需要导入模块: from storm.locals import Store [as 别名]
# 或者: from storm.locals.Store import flush [as 别名]

#.........这里部分代码省略.........

    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:
            values = 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 values:
                db_ilog = self._assign_values(db_ilog, f[0], v[0])
        return db_ilog

    def _get_dbissues_object(self, issue_name, tracker_id):
        """
        Abstract method for inserting extra data related to a change
        """
        raise NotImplementedError

    def _copy_standard_values(self, issue, issue_log):
        """
        Copy the standard values from the issue object to the issue_log object
        """
        issue_log.issue_id = issue.id
        issue_log.type = issue.type
        issue_log.summary = issue.summary
        issue_log.description = issue.description
        issue_log.status = issue.status
        issue_log.resolution = issue.resolution
        issue_log.priority = issue.priority
        issue_log.submitted_by = issue.submitted_by
        issue_log.date = issue.submitted_on
        issue_log.assigned_to = issue.assigned_to
        return issue_log

    def _print_final_msg(self):
        """
        Abstract method for inserting extra data related to a change
        """
        raise NotImplementedError

    def _get_changes(self, issue_id):
        aux = self.store.execute("SELECT id, field, new_value, changed_by, \
        changed_on FROM changes where issue_id=%s" % (issue_id))
        return aux

    def _post_history(self, issue_id):
        """
        Abstract method for inserting extra data usign full issue history
        """
        pass

    def run(self):
        ndone = 0
        issues = self.store.find(DBIssue)
        total = str(issues.count())
        print ("[IssuesLog] Total issues to analyze: " + str(issues.count()))
        for i in issues:
            if (ndone % 1000 == 0):
                print ("[IssuesLog] Analyzed " + str(ndone) + "/" + str(total))
            db_ilog = self._get_dbissues_object(i.issue, i.tracker_id)
            db_ilog = self._copy_standard_values(i, db_ilog)
            final_status = db_ilog.status

            db_ilog = self._build_initial_state(db_ilog)

            self.store.add(db_ilog)
            self.store.flush()

            # the code below gets all the changes and insert a row per change
            changes = self._get_changes(db_ilog.issue_id)

            for ch in changes:
                change_id = ch[0]
                field = ch[1]
                new_value = ch[2]
                changed_by = ch[3]
                date = ch[4]
                # we need a new object to be inserted in the database
                db_ilog = self._copy_issue(db_ilog)
                db_ilog.date = date
                db_ilog.change_id = change_id
                db_ilog.changed_by = changed_by
                db_ilog = self._assign_values(db_ilog, field, new_value)

                try:
                    self.store.add(db_ilog)
                    self.store.flush()
                except:
                    # self.store.rollback() # is this useful in this context?
                    traceback.print_exc()
            self._post_history(db_ilog, final_status)
            self.store.commit()
            ndone += 1
        self._print_final_msg()
开发者ID:brainwane,项目名称:Bicho,代码行数:104,代码来源:issues_log.py

示例3: StormStorageBackend

# 需要导入模块: from storm.locals import Store [as 别名]
# 或者: from storm.locals.Store import flush [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."""
#.........这里部分代码省略.........
开发者ID:LarsDietrich,项目名称:buddycloud-server-python,代码行数:103,代码来源:__init__.py


注:本文中的storm.locals.Store.flush方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。