コード例 #1
0
ファイル: test_database_tools.py プロジェクト: f3at/feat
 def setUp(self):
     yield common.AgencyTestHelper.setUp(self)
     self.db = self.agency._database
     self.connection = self.db.get_connection()
     r = applications.get_initial_data_registry()
     snapshot = r.get_snapshot()
     self.addCleanup(r.reset, snapshot)
     r.reset([])
コード例 #2
0
ファイル: tools.py プロジェクト: f3at/feat
 def body(connection):
     documents = applications.get_initial_data_registry().itervalues()
     log.info('script', "I will push %d documents.",
              len(list(documents)))
     d = create_db(connection)
     d.addCallback(defer.drop_param, push_initial_data, connection,
                   opts.force)
     if opts.migration:
         d.addCallback(defer.drop_param, migration_script, connection)
     return d
コード例 #3
0
ファイル: tools.py プロジェクト: zaheerm/feat
def push_initial_data(connection, overwrite=False):
    documents = applications.get_initial_data_registry().itervalues()
    for doc in documents:
        try:
            yield connection.save_document(doc)
        except ConflictError:
            if not overwrite:
                log.error('script', 'Document with id %s already exists!',
                          doc.doc_id)
            else:

                yield _update_old(connection, doc)

    design_docs = view.generate_design_docs()
    for design_doc in design_docs:
        try:
            yield connection.save_document(design_doc)
        except ConflictError:
            yield _update_old(connection, design_doc)
コード例 #4
0
ファイル: tools.py プロジェクト: f3at/feat
def push_initial_data(connection, overwrite=False, push_design_docs=True):
    documents = applications.get_initial_data_registry().itervalues()
    for doc in documents:
        try:
            yield connection.save_document(doc)
        except ConflictError:
            fetched = yield connection.get_document(doc.doc_id)
            if fetched.compare_content(doc):
                continue
            if not overwrite:
                log.warning('script', 'Document with id %s already exists! '
                            'Use --force, Luck!', doc.doc_id)
            else:
                log.info('script', 'Updating old version of the document, '
                         'id: %s', doc.doc_id)
                rev = yield connection.get_revision(doc.doc_id)
                doc.rev = rev
                yield connection.save_document(doc)

    if not push_design_docs:
        return
    design_docs = view.generate_design_docs()
    for design_doc in design_docs:
        try:
            yield connection.save_document(design_doc)
        except ConflictError:
            fetched = yield connection.get_document(design_doc.doc_id)
            if fetched.compare_content(design_doc):
                continue

            log.warning('script', 'The design document %s changed. '
                        'Use "feat-service upgrade" to push the new revisions '
                        'and restart the service in organised manner.',
                        design_doc.doc_id)

            # calculate a diff for debugging purpose
            diffs = dict()
            for what in ('views', 'filters'):
                diffs[what] = dict()
                a = getattr(design_doc, what)
                b = getattr(fetched, what)
                diff = set(a.keys()) - set(b.keys())
                for key in diff:
                    diffs[what][key] = (a[key], None)
                diff = set(b.keys()) - set(a.keys())
                for key in diff:
                    diffs[what][key] = (None, b[key])

                for name in set(a.keys()).intersection(set(b.keys())):
                    if a[name] != b[name]:
                        diffs[what][name] = (a[name], b[name])

            def strcode(x):
                if not x:
                    return ''
                if isinstance(x, (str, unicode)):
                    return x
                return "\n".join("%s: %s" % t for t in x.items())

            for what in diffs:
                for name in diffs[what]:
                    log.info('script',
                             '%s code changed. \nOLD: \n%s\n\nNEW:\n%s\n',
                             what, strcode(diffs[what][name][1]),
                             strcode(diffs[what][name][0]))
コード例 #5
0
ファイル: tools.py プロジェクト: f3at/feat
def get_current_initials():
    return applications.get_initial_data_registry().get_snapshot()
コード例 #6
0
ファイル: tools.py プロジェクト: f3at/feat
def reset_documents(snapshot):
    applications.get_initial_data_registry().reset(snapshot)