########################################################################## # # pgAdmin 4 - PostgreSQL Tools # # Copyright (C) 2013 - 2016, The pgAdmin Development Team # This software is released under the PostgreSQL Licence # ########################################################################## """A blueprint module implementing the maintenance tool for vacuum""" import json from flask import url_for, Response, render_template, request, current_app from flask.ext.babel import gettext as _ from flask.ext.security import login_required from config import PG_DEFAULT_DRIVER from pgadmin.misc.bgprocess.processes import BatchProcess, IProcessDesc from pgadmin.model import Server from pgadmin.utils import PgAdminModule, html from pgadmin.utils.ajax import bad_request, make_json_response from pgadmin.utils.driver import get_driver MODULE_NAME = 'maintenance' class MaintenanceModule(PgAdminModule): """ class MaintenanceModule(PgAdminModule) A module class for maintenance tools of vacuum which is derived from PgAdminModule. Methods: ------- * get_own_javascripts() - Method is used to load the required javascript files for maintenance tool module * get_own_stylesheets() - Returns the list of CSS file used by Maintenance module """ LABEL = _('Maintenance') def get_own_javascripts(self): scripts = list() for name, script in [ ['pgadmin.tools.maintenance', 'js/maintenance'] ]: scripts.append({ 'name': name, 'path': url_for('maintenance.index') + script, 'when': None }) return scripts def get_own_stylesheets(self): """ Returns: list: the stylesheets used by this module. """ stylesheets = [ url_for('maintenance.static', filename='css/maintenance.css') ] return stylesheets blueprint = MaintenanceModule(MODULE_NAME, __name__) class Message(IProcessDesc): def __init__(self, _sid, _data, _query): self.sid = _sid self.data = _data self.query = _query @property def message(self): res = _("Maintenance ({0})") if self.data['op'] == "VACUUM": return res.format(_('Vacuum')) if self.data['op'] == "ANALYZE": return res.format(_('Analyze')) if self.data['op'] == "REINDEX": return res.format(_('Reindex')) if self.data['op'] == "CLUSTER": return res.format(_('Cluster')) def details(self, cmd, args): res = None if self.data['op'] == "VACUUM": res = _('VACUUM ({0})') opts = [] if self.data['vacuum_full']: opts.append(_('FULL')) if self.data['vacuum_freeze']: opts.append(_('FREEZE')) if self.data['verbose']: opts.append(_('VERBOSE')) res = res.format(', '.join(str(x) for x in opts)) if self.data['op'] == "ANALYZE": res = _('ANALYZE') if self.data['verbose']: res += '(' + _('VERBOSE') + ')' if self.data['op'] == "REINDEX": if 'schema' in self.data and self.data['schema']: return _('REINDEX TABLE') res = _('REINDEX') if self.data['op'] == "CLUSTER": res = _('CLUSTER') res = '