Skip to content

Commit

Permalink
global: invenio.config deprecation
Browse files Browse the repository at this point in the history
* Replaces usage of invenio.config with invenio.base.globals:cfg.
  (closes inveniosoftware#3106)

Signed-off-by: Leonardo Rossi <[email protected]>
  • Loading branch information
Leonardo Rossi committed May 8, 2015
1 parent f69898e commit c76cdba
Show file tree
Hide file tree
Showing 14 changed files with 201 additions and 206 deletions.
20 changes: 10 additions & 10 deletions invenio/base/i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ def square(x, ln=CFG_SITE_LANG):

from flask_babel import gettext, lazy_gettext

from invenio.base.globals import cfg

# Placemark for the i18n function
_ = lazy_gettext

Expand All @@ -62,34 +64,32 @@ def wash_language(ln):
Return it in case of success, return the default language otherwise.
"""
from invenio.config import CFG_SITE_LANG, CFG_SITE_LANGS
if not ln:
return CFG_SITE_LANG
return cfg['CFG_SITE_LANG']
if isinstance(ln, list):
ln = ln[0]
ln = ln.replace('-', '_')
if ln in CFG_SITE_LANGS:
if ln in cfg['CFG_SITE_LANGS']:
return ln
elif ln[:2] in CFG_SITE_LANGS:
elif ln[:2] in cfg['CFG_SITE_LANGS']:
return ln[:2]
else:
return CFG_SITE_LANG
return cfg['CFG_SITE_LANG']


def wash_languages(lns):
"""Check in the languages list if there's at least one of the allowed langs.
Return it in case of success, return the default language otherwise.
"""
from invenio.config import CFG_SITE_LANG, CFG_SITE_LANGS
for ln in lns:
if ln:
ln = ln.replace('-', '_')
if ln in CFG_SITE_LANGS:
if ln in cfg['CFG_SITE_LANGS']:
return ln
elif ln[:2] in CFG_SITE_LANGS:
elif ln[:2] in cfg['CFG_SITE_LANGS']:
return ln[:2]
return CFG_SITE_LANG
return cfg['CFG_SITE_LANG']


def language_list_long(enabled_langs_only=True):
Expand All @@ -103,7 +103,7 @@ def language_list_long(enabled_langs_only=True):
translations in webdoc sources or bibformat templates.
"""
if enabled_langs_only:
from invenio.config import CFG_SITE_LANGS
CFG_SITE_LANGS = cfg['CFG_SITE_LANGS']
else:
from invenio.base.config import CFG_SITE_LANGS

Expand Down
7 changes: 5 additions & 2 deletions invenio/base/scripts/demosite.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ def populate(packages=[], default_data=True, files=None,
packages = ['invenio_demosite.base']

from werkzeug.utils import import_string
from invenio.config import CFG_PREFIX
from invenio.base.globals import cfg
CFG_PREFIX = cfg['CFG_PREFIX']

map(import_string, packages)

from invenio.ext.sqlalchemy import db
Expand All @@ -98,7 +100,8 @@ def populate(packages=[], default_data=True, files=None,
bibupload_flags = '-i -r --force'
for f in files:
job_id += 1
for cmd in ["%s/bin/bibupload -u admin %s %s" % (CFG_PREFIX, bibupload_flags, f),
for cmd in ["%s/bin/bibupload -u admin %s %s" % (CFG_PREFIX,
bibupload_flags, f),
"%s/bin/bibupload %d" % (CFG_PREFIX, job_id)]:
if os.system(cmd):
print("ERROR: failed execution of", cmd)
Expand Down
4 changes: 2 additions & 2 deletions invenio/ext/email/backends/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

__revision__ = "$Id$"

from invenio.config import CFG_SITE_ADMIN_EMAIL
from invenio.base.globals import cfg


def adminonly_class(Backend):
Expand All @@ -40,7 +40,7 @@ def process_message(m):
#%s
#--------------------------------------------------------------
#%s""" % (','.join(m.recipients()), m.body)
m.to = [CFG_SITE_ADMIN_EMAIL]
m.to = [cfg['CFG_SITE_ADMIN_EMAIL']]
m.cc = []
m.bcc = []
if 'Cc' in m.extra_headers:
Expand Down
19 changes: 10 additions & 9 deletions invenio/ext/login/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ def login_user(user, *args, **kwargs):
def reset_password(email, ln=None):
"""Reset user password."""
from datetime import timedelta
from invenio.config import CFG_SITE_SUPPORT_EMAIL, CFG_SITE_NAME, \
CFG_SITE_NAME_INTL, CFG_WEBSESSION_RESET_PASSWORD_EXPIRE_IN_DAYS
from invenio.base.globals import cfg

# create the reset key
if ln is None:
ln = g.ln
from invenio.modules.access.mailcookie import mail_cookie_create_pw_reset
reset_key = mail_cookie_create_pw_reset(email, cookie_timeout=timedelta(
days=CFG_WEBSESSION_RESET_PASSWORD_EXPIRE_IN_DAYS))
days=cfg['CFG_WEBSESSION_RESET_PASSWORD_EXPIRE_IN_DAYS']))
if reset_key is None:
return False # reset key could not be created

Expand All @@ -59,12 +59,13 @@ def reset_password(email, ln=None):
# finally send the email
from invenio.ext.email import send_email
from invenio.base.i18n import _
if not send_email(CFG_SITE_SUPPORT_EMAIL, email, "%s %s"
% (_("Password reset request for"),
CFG_SITE_NAME_INTL.get(ln, CFG_SITE_NAME)),
websession_templates.
tmpl_account_reset_password_email_body(
email, reset_key, request.remote_addr, ln)):
if not send_email(
cfg['CFG_SITE_SUPPORT_EMAIL'], email, "%s %s"
% (_("Password reset request for"),
cfg['CFG_SITE_NAME_INTL'].get(ln, cfg['CFG_SITE_NAME'])),
websession_templates.
tmpl_account_reset_password_email_body(
email, reset_key, request.remote_addr, ln)):
return False # mail could not be sent

return True # password reset email send successfully
Expand Down
4 changes: 2 additions & 2 deletions invenio/ext/script/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def check_for_software_updates(flash_message=False):
:return: True if you have latest version, else False if you need to upgrade
or None if server was not reachable.
"""
from invenio.config import CFG_VERSION
from invenio.base.globals import cfg
from invenio.base.i18n import _
try:
find = re.compile('Invenio v[0-9]+.[0-9]+.[0-9]+(\-rc[0-9])?'
Expand Down Expand Up @@ -134,7 +134,7 @@ def check_for_software_updates(flash_message=False):
version1 = submatch.search(version)
web_version = version1.group().split(".")

local_version = CFG_VERSION.split(".")
local_version = cfg['CFG_VERSION'].split(".")

if (web_version[0] > local_version[0] or
web_version[0] == local_version[0] and
Expand Down
14 changes: 6 additions & 8 deletions invenio/ext/sqlalchemy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,7 @@ def test_sqla_connection():
inspector.get_table_names()
except OperationalError as err:
from invenio.utils.text import wrap_text_in_a_box
from invenio.config import CFG_DATABASE_HOST, \
CFG_DATABASE_PORT, CFG_DATABASE_NAME, CFG_DATABASE_USER, \
CFG_DATABASE_PASS
from invenio.base.globals import cfg
print(" [ERROR]")
print(wrap_text_in_a_box("""\
DATABASE CONNECTIVITY ERROR:
Expand All @@ -211,11 +209,11 @@ def test_sqla_connection():
If the problem is of different nature, then please inspect
the above error message and fix the problem before continuing.""" % {
'errmsg': err.args[0],
'dbname': CFG_DATABASE_NAME,
'dbhost': CFG_DATABASE_HOST,
'dbport': CFG_DATABASE_PORT,
'dbuser': CFG_DATABASE_USER,
'dbpass': CFG_DATABASE_PASS,
'dbname': cfg['CFG_DATABASE_NAME'],
'dbhost': cfg['CFG_DATABASE_HOST'],
'dbport': cfg['CFG_DATABASE_PORT'],
'dbuser': cfg['CFG_DATABASE_USER'],
'dbpass': cfg['CFG_DATABASE_PASS'],
'webhost': (CFG_DATABASE_HOST == 'localhost' and 'localhost' or
os.popen('hostname -f', 'r').read().strip()),
}))
Expand Down
Loading

0 comments on commit c76cdba

Please sign in to comment.