Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a plugin for fedora #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions mirror/plugins/FedoraReport/mirror/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import pkg_resources
pkg_resources.declare_namespace(__name__)

2 changes: 2 additions & 0 deletions mirror/plugins/FedoraReport/mirror/plugins/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import pkg_resources
pkg_resources.declare_namespace(__name__)
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#
# Copyright (C) 2017 gaoliang <[email protected]>
#
#
# You may 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.
#
# mirror 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 mirror. If not, write to:
# The Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor
# Boston, MA 02110-1301, USA.
#
#

from mirror.plugininit import PluginInitBase


class MirrorPlugin(PluginInitBase):
enabled = True

def __init__(self, plugin_name):
from fedora_report import Plugin as _plugin_class
self._plugin_class = _plugin_class
super(MirrorPlugin, self).__init__(plugin_name)
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#
# Copyright (C) 2017 Gao Liang <[email protected]>
#
#
# You may 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.
#
# mirror 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 mirror. If not, write to:
# The Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor
# Boston, MA 02110-1301, USA.
#
#
import subprocess
import logging
import os

import mirror.component as component
from mirror.pluginbase import PluginBase

_plugin_name = "fedorareport"

log = logging.getLogger(_plugin_name)


class Plugin(PluginBase):
DEFAULT_CONFIG_FILE = '/etc/mirrormanager-client/report_mirror.conf'

def enable(self):
plugin_manager = component.get("PluginManager")
config = plugin_manager.config
try:
self.config_file = config[_plugin_name]["config_file"]
except:
self.config_file = self.DEFAULT_CONFIG_FILE
log.info(("Didn't set `config_file` in plugin.ini in `%s` section"
", use default one: %s"), _plugin_name, self.config_file)
if not os.path.isfile(self.config_file):
log.error("Can not find the config file `%s`. Plugin enable failed".format(self.config_file))

self.enabled = True
event_manager = component.get("EventManager")
event_manager.register_event_handler("TaskStopEvent",
self.__on_task_stop)

def disable(self):
pass

def __on_task_stop(self, taskname, pid, exitcode):
if taskname == "fedora" and exitcode == 0:
try:
out_bytes = subprocess.check_output(['report_mirror', '-c', self.config_file], stderr=subprocess.STDOUT)
log.info("report_mirror success ")
except subprocess.CalledProcessError as e:
log.warning("report_mirror returned (), failed: %s", e.returncode, e.output)
52 changes: 52 additions & 0 deletions mirror/plugins/FedoraReport/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#
# Copyright (C) 2017 Gao Liang <[email protected]>
#
#
# You may 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.
#
# mirror 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 mirror. If not, write to:
# The Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor
# Boston, MA 02110-1301, USA.
#
#

from setuptools import setup, find_packages

__plugin_name__ = "FedoraReport"
__author__ = "Gao Liang"
__author_email__ = "[email protected]"
__version__ = "0.1"
__url__ = "http://mirror.njupt.edu.cn"
__license__ = "GPLv3"
__description__ = "Plugin to reports fedora mirror content after sync data."
__long_description__ = """"""
__pkg_data__ = {'mirror.plugins.' + __plugin_name__.lower(): ["data/*"]}

setup(
name=__plugin_name__,
version=__version__,
description=__description__,
author=__author__,
author_email=__author_email__,
url=__url__,
license=__license__,
long_description=__long_description__ if __long_description__ else __description__,
packages=find_packages(),
namespace_packages=["mirror", "mirror.plugins"],
package_data=__pkg_data__,

entry_points="""
[mirror.plugin.mirrorplugin]
%s = mirror.plugins.%s:MirrorPlugin
""" % (__plugin_name__, __plugin_name__.lower())
)