mirror of
https://github.com/lucaspalomodevelop/indico-plugins.git
synced 2026-03-12 23:27:22 +00:00
parent
58af8a2992
commit
03cdb34c0e
80
livesync/indico_livesync/zodbimport.py
Normal file
80
livesync/indico_livesync/zodbimport.py
Normal file
@ -0,0 +1,80 @@
|
||||
# This file is part of Indico.
|
||||
# Copyright (C) 2002 - 2014 European Organization for Nuclear Research (CERN).
|
||||
#
|
||||
# Indico is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License as
|
||||
# published by the Free Software Foundation; either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# Indico is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Indico; if not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
|
||||
from indico.core.db import db
|
||||
from indico.util.console import cformat
|
||||
from indico.util.struct.iterables import committing_iterator
|
||||
from indico_zodbimport import Importer, convert_to_unicode
|
||||
|
||||
from indico_livesync.plugin import LiveSyncPlugin
|
||||
from indico_livesync.models.agents import LiveSyncAgent
|
||||
|
||||
|
||||
class LiveSyncImporter(Importer):
|
||||
plugins = {'livesync'}
|
||||
|
||||
def pre_check(self):
|
||||
return self.check_plugin_schema('livesync')
|
||||
|
||||
def has_data(self):
|
||||
return LiveSyncAgent.find().count()
|
||||
|
||||
def migrate(self):
|
||||
# noinspection PyAttributeOutsideInit
|
||||
self.livesync_root = self.zodb_root['plugins']['livesync']._storage
|
||||
print dict(self.livesync_root)
|
||||
with LiveSyncPlugin.instance.plugin_context():
|
||||
self.migrate_settings()
|
||||
self.migrate_agents()
|
||||
print cformat('%{cyan!}Note: The old queue is not preserved!%{reset}')
|
||||
|
||||
def migrate_settings(self):
|
||||
print cformat('%{white!}migrating settings')
|
||||
LiveSyncPlugin.settings.delete_all()
|
||||
opts = self.zodb_root['plugins']['livesync']._PluginBase__options
|
||||
LiveSyncPlugin.settings.set('excluded_categories', [{'id': x} for x in opts['excludedCategories'].getValue()])
|
||||
db.session.commit()
|
||||
|
||||
def migrate_agents(self):
|
||||
print cformat('%{white!}migrating agents')
|
||||
for old_agent in committing_iterator(self.livesync_root['agent_manager']._agents.itervalues()):
|
||||
if not old_agent._active:
|
||||
print cformat('%{yellow}skipping inactive agent {} ({})%{reset}').format(old_agent._id, old_agent._name)
|
||||
continue
|
||||
|
||||
agent = LiveSyncAgent(name=convert_to_unicode(old_agent._name), initial_data_exported=True)
|
||||
old_agent_class = old_agent.__class__.__name__
|
||||
if old_agent_class == 'InvenioBatchUploaderAgent':
|
||||
agent.backend_name = 'invenio'
|
||||
agent.settings = {
|
||||
'invenio_url': old_agent._url
|
||||
}
|
||||
elif old_agent_class == 'CERNSearchUploadAgent':
|
||||
agent.backend_name = 'cernsearch'
|
||||
agent.settings = {
|
||||
'service_url': old_agent._url,
|
||||
'service_username': old_agent._username,
|
||||
'service_password': old_agent._password,
|
||||
}
|
||||
else:
|
||||
print cformat('%{red!}skipping unknown agent type: {}%{reset}').format(old_agent_class)
|
||||
continue
|
||||
|
||||
print cformat('- %{cyan}{} ({})').format(agent.name, agent.backend_name)
|
||||
db.session.add(agent)
|
||||
@ -40,5 +40,6 @@ setup(
|
||||
'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)',
|
||||
'Programming Language :: Python :: 2.7'
|
||||
],
|
||||
entry_points={'indico.plugins': {'livesync = indico_livesync.plugin:LiveSyncPlugin'}}
|
||||
entry_points={'indico.plugins': {'livesync = indico_livesync.plugin:LiveSyncPlugin'},
|
||||
'indico.zodb_importers': {'livesync = indico_livesync.zodbimport:LiveSyncImporter'}}
|
||||
)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user