コード例 #1
0
ファイル: database.py プロジェクト: gustavi/prewikka
    def apply(self):
        log.getLogger().info("%s: please standby while %s is applied",
                             self._full_module_name, text_type(self))

        self.run()

        if self.type == "install":
            env.db.upsert(
                "Prewikka_Module_Registry", ("module", "branch", "version"),
                ((self._full_module_name, self.branch, self.version), ),
                pkey=("module", ))

        elif self.type == "update":
            self.db.query(
                "UPDATE Prewikka_Module_Registry SET version=%s WHERE module=%s%s"
                % (self.db.escape(
                    self.version), self.db.escape(self._full_module_name),
                   self.db._chknull("branch", self.branch)))

        elif self.type == "branch":
            self.db.query(
                "UPDATE Prewikka_Module_Registry SET branch=%s, version=%s, enabled=1 WHERE module=%s",
                self.branch, self.version, self._full_module_name)

        self.db._update_state(self.version, self.branch)
コード例 #2
0
ファイル: database.py プロジェクト: gustavi/prewikka
    def _get_schema_list(self, **kwargs):
        from_version = to_version = None

        if "from_version" in kwargs:
            from_version = pkg_resources.parse_version(
                kwargs.pop("from_version"))

        if "to_version" in kwargs:
            to_version = pkg_resources.parse_version(kwargs.pop("to_version"))

        dirnames = self._get_update_directories()

        for importer, package_name, _ in pkgutil.iter_modules(dirnames):
            try:
                mod = importer.find_module(package_name).load_module(
                    package_name).SQLUpdate(self)
            except Exception as e:
                log.getLogger().exception(
                    "[%s]: error loading SQL update '%s' : %s" %
                    (self._full_module_name, package_name, e))
                continue

            if any(kwargs[k] != getattr(mod, k) for k in kwargs.keys()):
                continue

            version = pkg_resources.parse_version(mod.version)
            if (not from_version or
                (version >= from_version)) and (not to_version or
                                                (version <= to_version)):
                yield mod
コード例 #3
0
ファイル: database.py プロジェクト: gustavi/prewikka
 def _get_update_directories(self):
     for i in pkg_resources.iter_entry_points("prewikka.updatedb",
                                              self._module_name):
         try:
             yield i.load().__path__[0]
         except Exception as e:
             log.getLogger().exception(
                 "[%s]: error loading SQL updates: %s",
                 self._full_module_name, e)
コード例 #4
0
ファイル: database.py プロジェクト: 4sp1r3/prewikka
    def apply(self, transaction=True):
        log.getLogger().info("%s: please standby while %s is applied", self._module_name, str(self))

        if not transaction:
            return self.__apply()

        else:
            self.db.transactionStart()
            try:
                self.__apply()
            except Exception as e:
                self.db.transactionAbort()
                raise e

            self.db.transactionEnd()
コード例 #5
0
ファイル: database.py プロジェクト: 4sp1r3/prewikka
    def _resolve_branch_switch(self, curbranch, curversion, outstack=[]):

        for upd in self._list(from_branch=(curbranch, curversion), type="branch"):
            if upd.branch == self._reqbranch and pkg_resources.parse_version(upd.version) <= pkg_resources.parse_version(self._reqversion):
                return outstack + [upd]

            elif upd in outstack:
                log.getLogger().warning("cyclic branch dependencies detected: %s",  " -> ".join(str(i) for i in outstack + [upd]))
                continue

            else:
                ret = self._resolve_branch_switch(upd.branch, upd.version, outstack=outstack[:] + [upd])
                if ret:
                    return ret

        return []
コード例 #6
0
ファイル: database.py プロジェクト: gustavi/prewikka
    def _resolve_branch_switch(self, curbranch, curversion, outstack=[]):

        for upd in self._list(from_branch=(curbranch, curversion),
                              type="branch"):
            if upd.branch == self._reqbranch and pkg_resources.parse_version(
                    upd.version) <= pkg_resources.parse_version(
                        self._reqversion):
                return outstack + [upd]

            elif upd in outstack:
                log.getLogger().warning(
                    "cyclic branch dependencies detected: %s",
                    " -> ".join(text_type(i) for i in outstack + [upd]))
                continue

            else:
                ret = self._resolve_branch_switch(upd.branch,
                                                  upd.version,
                                                  outstack=outstack[:] + [upd])
                if ret:
                    return ret

        return []
コード例 #7
0
ファイル: database.py プロジェクト: 4sp1r3/prewikka
    def _get_schema_list(self, **kwargs):
        from_version = to_version = None

        if "from_version" in kwargs:
            from_version = pkg_resources.parse_version(kwargs.pop("from_version"))

        if "to_version" in kwargs:
            to_version = pkg_resources.parse_version(kwargs.pop("to_version"))

        dirname = pkg_resources.resource_filename(self._module_name, "sql")
        for importer, package_name, _ in pkgutil.iter_modules([dirname]):
            try:
                mod = importer.find_module(package_name).load_module(package_name).SQLUpdate(self)
            except Exception as e:
                log.getLogger().exception("[%s]: error loading SQL update '%s' : %s" % (self._module_name, package_name, e))
                continue

            if any(kwargs[k] != getattr(mod, k) for k in kwargs.keys()):
                continue

            version = pkg_resources.parse_version(mod.version)
            if (not from_version or (version >= from_version)) and (not to_version or (version <= to_version)):
                    yield mod
コード例 #8
0
import pkg_resources
import prelude
import pytz
from prewikka import log, utils

if sys.version_info >= (3, 0):
    import builtins
else:
    import __builtin__ as builtins

try:
    from babel.dates import format_timedelta as _format_timedelta
except ImportError:
    from prewikka.compat.babelcompat import format_timedelta as _format_timedelta

logger = log.getLogger(__name__)


class TranslationProxy(object):
    def __init__(self):
        self._data = local()
        self._catalogs = {}
        self._catalogs_lock = Lock()

        self._domains_lock = Lock()
        self._domains = utils.OrderedDict([
            ("prewikka", pkg_resources.resource_filename(__name__, "locale"))
        ])

    def addDomain(self, domain, locale_dir):
        with self._domains_lock:
コード例 #9
0
ファイル: view.py プロジェクト: 4sp1r3/prewikka
#
# This program 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 this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

import operator, json, time
from copy import copy
from prewikka import pluginmanager, template, usergroup, error, log, utils, env


logger = log.getLogger(__name__)


class ParameterError(Exception):
        pass

class InvalidParameterError(error.PrewikkaUserError):
    def __init__(self, name):
        error.PrewikkaUserError.__init__(self, _("Parameters Normalization failed"),
                                               _("Parameter '%s' is not valid") % name, log_priority=log.WARNING)


class InvalidParameterValueError(error.PrewikkaUserError):
    def __init__(self, name, value):
        error.PrewikkaUserError.__init__(self, _("Parameters Normalization failed"),
                                               _("Invalid value '%(value)s' for parameter '%(name)s'") % {'value':value, 'name':name}, log_priority=log.WARNING)
コード例 #10
0
ファイル: database.py プロジェクト: Prelude-SIEM/prewikka
 def _get_update_directories(self):
     for i in pkg_resources.iter_entry_points("prewikka.updatedb", self._module_name):
         try:
             yield i.load().__path__[0]
         except Exception as e:
             log.getLogger().exception("[%s]: error loading SQL updates: %s", self._module_name, e)