예제 #1
0
파일: plugin.py 프로젝트: Zharktas/ytp
    def receive_data(self, operation, queue, **params):
        '''Receive notification from ckan-archiver that a resource has been
        archived.
        '''
        if not operation == 'archived':
            return
        resource_id = params['resource_id']

        resource = model.Resource.get(resource_id)
        assert resource

        lib.create_qa_update_task(resource, queue=queue)
예제 #2
0
    def receive_data(self, operation, queue, **params):
        '''Receive notification from ckan-archiver that a resource has been
        archived.
        '''
        if not operation == 'archived':
            return
        resource_id = params['resource_id']

        resource = model.Resource.get(resource_id)
        assert resource

        lib.create_qa_update_task(resource, queue=queue)
예제 #3
0
    def update(self):
        from ckan import model
        from ckanext.qa import lib
        packages = []
        resources = []
        if len(self.args) > 1:
            for arg in self.args[1:]:
                # try arg as a group id/name
                group = model.Group.get(arg)
                if group:
                    packages.extend(group.packages())
                    if not self.options.queue:
                        self.options.queue = 'bulk'
                    continue
                # try arg as a package id/name
                pkg = model.Package.get(arg)
                if pkg:
                    packages.append(pkg)
                    if not self.options.queue:
                        self.options.queue = 'priority'
                    continue
                # try arg as a resource id
                res = model.Resource.get(arg)
                if res:
                    resources.append(res)
                    if not self.options.queue:
                        self.options.queue = 'priority'
                    continue
                else:
                    self.log.error('Could not recognize as a group, package '
                                   'or resource: %r', arg)
                    sys.exit(1)
        else:
            # all packages
            pkgs = model.Session.query(model.Package)\
                        .filter_by(state='active')\
                        .order_by('name').all()
            packages.extend(pkgs)
            if not self.options.queue:
                self.options.queue = 'bulk'

        if packages:
            self.log.info('Datasets to QA: %d', len(packages))
        if resources:
            self.log.info('Resources to QA: %d', len(resources))
        if not (packages or resources):
            self.log.error('No datasets or resources to process')
            sys.exit(1)

        self.log.info('Queue: %s', self.options.queue)
        for package in packages:
            lib.create_qa_update_package_task(package, self.options.queue)
            self.log.info('Queuing dataset %s (%s resources)',
                          package.name, len(package.resources))

        for resource in resources:
            package = resource.resource_group.package
            self.log.info('Queuing resource %s/%s', package.name, resource.id)
            lib.create_qa_update_task(resource, self.options.queue)

        self.log.info('Completed queueing')
예제 #4
0
    def update(self):
        from ckan import model
        from ckanext.qa import lib
        packages = []
        resources = []
        if len(self.args) > 1:
            for arg in self.args[1:]:
                # try arg as a group id/name
                group = model.Group.get(arg)
                if group and group.is_organization:
                    # group.packages() is unreliable for an organization -
                    # member objects are not definitive whereas owner_org, so
                    # get packages using owner_org
                    query = model.Session.query(model.Package)\
                        .filter(
                            or_(model.Package.state == 'active',
                                model.Package.state == 'pending'))\
                        .filter_by(owner_org=group.id)
                    packages.extend(query.all())
                    if not self.options.queue:
                        self.options.queue = 'bulk'
                    continue
                elif group:
                    packages.extend(group.packages())
                    if not self.options.queue:
                        self.options.queue = 'bulk'
                    continue
                # try arg as a package id/name
                pkg = model.Package.get(arg)
                if pkg:
                    packages.append(pkg)
                    if not self.options.queue:
                        self.options.queue = 'priority'
                    continue
                # try arg as a resource id
                res = model.Resource.get(arg)
                if res:
                    resources.append(res)
                    if not self.options.queue:
                        self.options.queue = 'priority'
                    continue
                else:
                    self.log.error(
                        'Could not recognize as a group, package '
                        'or resource: %r', arg)
                    sys.exit(1)
        else:
            # all packages
            pkgs = model.Session.query(model.Package)\
                        .filter_by(state='active')\
                        .order_by('name').all()
            packages.extend(pkgs)
            if not self.options.queue:
                self.options.queue = 'bulk'

        if packages:
            self.log.info('Datasets to QA: %d', len(packages))
        if resources:
            self.log.info('Resources to QA: %d', len(resources))
        if not (packages or resources):
            self.log.error('No datasets or resources to process')
            sys.exit(1)

        self.log.info('Queue: %s', self.options.queue)
        for package in packages:
            lib.create_qa_update_package_task(package, self.options.queue)
            self.log.info('Queuing dataset %s (%s resources)', package.name,
                          len(package.resources))

        for resource in resources:
            package = resource.resource_group.package
            self.log.info('Queuing resource %s/%s', package.name, resource.id)
            lib.create_qa_update_task(resource, self.options.queue)

        self.log.info('Completed queueing')