def setup_class(cls): dest_dir = config.get('ckanext.packagezip.destination_dir') if not os.path.isdir(dest_dir): os.mkdir(dest_dir) cls.config = config['__file__'] archiver_model.init_tables(model.meta.engine) packagezip_model.init_tables(model.meta.engine)
def command(self): """ Parse command line arguments and call appropriate method. """ if not self.args or self.args[0] in ['--help', '-h', 'help']: print self.usage sys.exit(1) cmd = self.args[0] self._load_config() self.log = logging.getLogger(__name__) if cmd == 'init': import ckan.model as model from ckanext.packagezip.model import init_tables init_tables(model.meta.engine) self.log.info('Package Zip tables are initialized') elif cmd == 'create-zip': import ckan.model as model from ckan.lib.celery_app import celery datasets = [] for name in self.args[1:]: name_ = name_stripped_of_url(name) dataset = model.Package.get(name_) assert dataset, 'Could not find dataset: %s' % name datasets.append(dataset) assert datasets, 'No datasets to zip!' ckan_ini_filepath = os.path.abspath(config['__file__']) task_id = str(uuid.uuid4()) queue = 'priority' for dataset in datasets: celery.send_task('packagezip.create_zip', args=[ckan_ini_filepath, dataset.id, queue], task_id=task_id, queue=queue) self.log.info(u'Queued %s' % dataset.name) else: self.log.error('Command %s not recognized' % (cmd, ))
def command(self): """ Parse command line arguments and call appropriate method. """ if not self.args or self.args[0] in ['--help', '-h', 'help']: print self.usage sys.exit(1) cmd = self.args[0] self._load_config() self.log = logging.getLogger(__name__) if cmd == 'init': import ckan.model as model from ckanext.packagezip.model import init_tables init_tables(model.meta.engine) self.log.info('Package Zip tables are initialized') elif cmd == 'create-zip': import ckan.model as model from ckan.lib.celery_app import celery datasets = [] for name in self.args[1:]: name_ = name_stripped_of_url(name) dataset = model.Package.get(name_) assert dataset, 'Could not find dataset: %s' % name datasets.append(dataset) assert datasets, 'No datasets to zip!' ckan_ini_filepath = os.path.abspath(config['__file__']) task_id = str(uuid.uuid4()) queue = 'priority' for dataset in datasets: celery.send_task('packagezip.create_zip', args=[ckan_ini_filepath, dataset.id, queue], task_id=task_id, queue=queue) self.log.info(u'Queued %s' % dataset.name) else: self.log.error('Command %s not recognized' % (cmd,))