Skip to content

Commit

Permalink
Remove more ZODB stuff (mostly setup/deps)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThiefMaster authored and pferreir committed Apr 10, 2017
1 parent a16b488 commit 0d88a8c
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 202 deletions.
2 changes: 0 additions & 2 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ It's dangerous to go alone. Take these tips in case you need to fit Indico to yo
Use `indico db prepare` to create your tables based on the SQLAlchemy models and set the migration status to the most
recent alembic revision.

If you want to import data from ZODB, run `bin/migration/migrate_to_sqlalchemy.py` with the appropriate arguments.


## SQL Database migrations
Whenever you modify the database structure or want to perform data migrations, create an alembic revision.
Expand Down
1 change: 0 additions & 1 deletion doc/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ babel
repoze.sphinx.autointerface
flask
Flask-BabelEx
ZODB3==3.10.5
10 changes: 0 additions & 10 deletions etc/zdctl.conf.sample

This file was deleted.

15 changes: 0 additions & 15 deletions etc/zodb.conf.sample

This file was deleted.

22 changes: 0 additions & 22 deletions indico/MaKaC/consoleScripts/indicoCtl.py

This file was deleted.

7 changes: 3 additions & 4 deletions indico/MaKaC/consoleScripts/indicoInitialSetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
On RPM or windist based installations it can be made run automatically'''

import os, sys
import shutil, getopt
import getopt

from distutils.sysconfig import get_python_lib

from installBase import getIndicoInstallMode, setIndicoInstallMode, PWD_INDICO_CONF, indico_pre_install, indico_post_install, copyTreeSilently
from installBase import setIndicoInstallMode, indico_pre_install, indico_post_install, copyTreeSilently

# The directory where the egg is located
eggDir = os.path.join(os.path.dirname(__file__), '..', '..')


def copy_egg_datafiles_to_base(dstDir):
"""Copies bin, doc, etc & htdocs from egg's installation folder to dstDir
NOTE: the egg is always uncompressed because we make references to __file__ all over the place.
Expand Down Expand Up @@ -109,7 +109,6 @@ def main():
'..',
'common'),
eggDir,
force_no_db=(existingPath != None),
uid=wwwUid,
gid=wwwGid,
upgrade_config=upgrade_config)
Expand Down
113 changes: 12 additions & 101 deletions indico/MaKaC/consoleScripts/installBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@

globals()['INDICO_INSTALL'] = False

LOCALDATABASEDIR = '/opt/indico/db'

# Egg directory + etc/indico.conf
PWD_INDICO_CONF = os.path.abspath(os.path.join(
os.path.split(os.path.dirname(MaKaC.__file__))[0],'etc', 'indico.conf'
Expand Down Expand Up @@ -267,13 +265,10 @@ def _findApacheUserGroup(uid, gid):
return "apache", "apache"


def _checkDirPermissions(directories, dbInstalledBySetupPy=False, accessuser=None, accessgroup=None):
def _checkDirPermissions(directories, accessuser=None, accessgroup=None):
'''Makes sure that directories which need write access from Apache have
the correct permissions
- dbInstalledBySetupPy if True, means that the dbdir has been created by the setup
process and needs to be checked.
- uid and gid: if they are valid user_ids and group_ids they will be used to chown
the directories instead of the indico.conf ones.
'''
Expand All @@ -282,9 +277,6 @@ def _checkDirPermissions(directories, dbInstalledBySetupPy=False, accessuser=Non

if sys.platform == "linux2":
dirs2check = list(directories[x] for x in ['htdocs', 'log', 'tmp', 'cache', 'archive'] if directories.has_key(x))
if dbInstalledBySetupPy:
dirs2check.append(dbInstalledBySetupPy)

for dir in dirs2check:
stat_info = os.stat(dir)
if pwd.getpwuid(int(stat_info.st_uid)).pw_name != accessuser or os.path.basename(dir) == 'htdocs':
Expand Down Expand Up @@ -330,32 +322,14 @@ def _extractDirsFromConf(conf):
'htdocs': values['HtdocsDir'],
'tmp': values['UploadedFilesTempDir'],
'log': values['LogDir'],
'cache': values['XMLCacheDir'],
'db': LOCALDATABASEDIR}
'cache': values['XMLCacheDir']}

def _replacePrefixInConf(filePath, prefix):
fdata = open(filePath).read()
fdata = re.sub(r'/opt/indico', prefix, fdata)
fdata = re.sub(r"^#\s*SecretKey = ''", "SecretKey = {!r}".format(os.urandom(32)), fdata)
open(filePath, 'w').write(fdata)

def _updateDbConfigFiles(cfg_dir, uid=None, port=None, **kwargs):
"""
Update parameters inside DB config files
"""
kwargs['etc'] = cfg_dir

for fname in ['zodb.conf', 'zdctl.conf']:
with open(os.path.join(cfg_dir, fname), 'r+') as f:
fdata = f.read()
for dirname in ['db', 'log', 'tmp', 'etc']:
fdata = re.sub(r'\/opt\/indico\/{0}'.format(dirname), kwargs.get(dirname, dirname), fdata)
if uid:
fdata = re.compile(r'^(\s*user\s+)apache[^\S\n]*', re.MULTILINE).sub(r'\g<1>{0}'.format(uid), fdata)
if port is not None:
fdata = re.compile(r'^(\s*address\s+localhost:)\d+[^\S\n]*', re.MULTILINE).sub(r'\g<1>{0}'.format(port), fdata)
f.seek(0)
f.write(fdata)

def indico_pre_install(defaultPrefix, force_upgrade=False, existingConfig=None):
"""
Expand Down Expand Up @@ -458,18 +432,13 @@ def fresh_install(defaultPrefix):
updateIndicoConfPathInsideMaKaCConfig(indicoconfpath, activemakacconfig)

return dict((dirName, os.path.join(prefixDir, dirName))
for dirName in ['bin','doc','etc','htdocs','tmp','log','cache','db','archive'])
for dirName in ['bin','doc','etc','htdocs','tmp','log','cache','archive'])


def indico_post_install(targetDirs, sourceDirs, makacconfig_base_dir, package_dir, force_no_db=False, uid=None,
gid=None, dbDir=LOCALDATABASEDIR, upgrade_config=True):
def indico_post_install(targetDirs, sourceDirs, makacconfig_base_dir, package_dir, uid=None,
gid=None, upgrade_config=True):
from indico.core.config import Config

if 'db' in targetDirs:
# we don't want that the db directory be created
dbDir = targetDirs['db']
del targetDirs['db']

print "Creating directories for resources... ",
# Create the directories where the resources will be installed
createDirs(targetDirs)
Expand All @@ -492,48 +461,12 @@ def indico_post_install(targetDirs, sourceDirs, makacconfig_base_dir, package_di
print "done!"

# change MaKaCConfig.py to include the config
updateIndicoConfPathInsideMaKaCConfig(newConf,
os.path.join(makacconfig_base_dir, 'MaKaCConfig.py'))

# copy the db config files
for f in [xx for xx in ('%s/zdctl.conf' % targetDirs['etc'],
'%s/zodb.conf' % targetDirs['etc'],
'%s/logging.conf' %targetDirs['etc']) if not os.path.exists(xx)]:
shutil.copy('%s.sample' % f, f)
updateIndicoConfPathInsideMaKaCConfig(newConf, os.path.join(makacconfig_base_dir, 'MaKaCConfig.py'))

# Shall we create a DB?
dbInstalledBySetupPy = False
dbpath = None

if force_no_db:
print 'Skipping database detection'
else:
if os.path.exists(dbDir):
dbpath = dbDir
print 'Successfully found a database directory at %s' % dbDir
else:
opt = None
while opt not in ('Y', 'y', 'n', ''):
opt = raw_input('''\nWe cannot find a configured database at %s.
Do you want to create a new database now [Y/n]? ''' % dbDir)
if opt in ('Y', 'y', ''):
dbInstalledBySetupPy = True
dbpath_ok = False
while not dbpath_ok:
dbpath = raw_input('''\nWhere do you want to install the database [%s]? ''' % dbDir)
if dbpath.strip() == '':
dbpath = dbDir

try:
os.makedirs(dbpath)
dbpath_ok = True
except Exception, e:
print e
print 'Unable to create database at %s, please make sure that you have permissions to create that directory' % dbpath

elif opt == 'n':
pass
# copy the logging config
fpath = os.path.join(targetDirs['etc'], 'logging.conf')
if not os.path.exists(fpath):
shutil.copy(fpath + '.sample', fpath)

#we delete an existing vars.js.tpl.tmp
tmp_dir = targetDirs['tmp']
Expand All @@ -543,27 +476,14 @@ def indico_post_install(targetDirs, sourceDirs, makacconfig_base_dir, package_di
print 'Old vars.js.tpl.tmp found at: %s. Removing' % varsJsTplTmpPath
os.remove(varsJsTplTmpPath)

if dbInstalledBySetupPy:
dbParam = dbpath
else:
dbParam = None

# find the apache user/group
user, group = _findApacheUserGroup(uid, gid)

# set the directory for the egg cache
_updateMaKaCEggCache(os.path.join(package_dir, 'MaKaC', '__init__.py'), targetDirs['tmp'])

if not force_no_db and dbpath:
# change the db config files (paths + apache user/group)
_updateDbConfigFiles(targetDirs['etc'],
log=targetDirs['log'],
db=dbpath,
tmp=targetDirs['tmp'],
uid=user)

# check permissions
_checkDirPermissions(targetDirs, dbInstalledBySetupPy=dbParam, accessuser=user, accessgroup=group)
_checkDirPermissions(targetDirs, accessuser=user, accessgroup=group)
# check that mod_python is installed
_checkModPythonIsInstalled()

Expand All @@ -587,13 +507,4 @@ def indico_post_install(targetDirs, sourceDirs, makacconfig_base_dir, package_di
Please do not forget to start the Celery worker in order to use background tasks
such as event reminders and periodic cleanups. You can run it using this command:
$ indico celery worker -B
%s
""" % (targetDirs['etc'], targetDirs['bin'], targetDirs['doc'], targetDirs['etc'], targetDirs['htdocs'], _databaseText(targetDirs['etc']))


def _databaseText(cfgPrefix):
return """If you are running ZODB on this host:
- Review %s/zodb.conf and %s/zdctl.conf to make sure everything is ok.
- To start the database run: zdaemon -C %s/zdctl.conf start
""" % (cfgPrefix, cfgPrefix, cfgPrefix)
""" % (targetDirs['etc'], targetDirs['bin'], targetDirs['doc'], targetDirs['etc'], targetDirs['htdocs'])
4 changes: 0 additions & 4 deletions indico/MaKaC/webinterface/rh/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -754,10 +754,6 @@ def _deleteTempFiles(self):
class RHSimple(RH):
"""A simple RH that calls a function to build the response
The main purpose of this RH is to allow external library to
display something within the Indico layout (which requires a
RH / a ZODB connection in most cases).
The preferred way to use this class is by using the
`RHSimple.wrap_function` decorator.
Expand Down
12 changes: 0 additions & 12 deletions indico/testing/fixtures/disallow.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,3 @@ def _emit(*args, **kwargs):
monkeypatch.setattr(SMTP, 'connect', _connect)
monkeypatch.setattr('logging.handlers.SMTPHandler.emit', _emit)
return allowed


@pytest.fixture(autouse=True)
def disallow_zodb(monkeypatch):
"""Prevents any code from connecting to ZODB"""

@staticmethod
def _fail(*args, **kwargs):
__tracebackhide__ = True
pytest.fail('Code tried to connect to ZODB')

monkeypatch.setattr('indico.core.db.manager.DBMgr.getInstance', _fail)
3 changes: 0 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
Babel==2.3.4
Mako==0.9.1
MarkupSafe==0.23
ZConfig==2.9.2
ZODB3==3.10.5
indico-fonts==1.1
cssmin==0.2.0
icalendar==3.11.3
Expand Down Expand Up @@ -31,7 +29,6 @@ webassets==0.12.1
wsgiref==0.1.2
zc.lockfile==1.0.0
zc.queue==1.3
zdaemon==3.0.5
zope.event==4.0.0
zope.index==3.6.4
zope.interface==3.8.0
Expand Down
3 changes: 3 additions & 0 deletions requirements.zodb.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ZConfig==2.9.2
ZODB3==3.10.5
zdaemon==3.0.5
Loading

0 comments on commit 0d88a8c

Please sign in to comment.